From d0b62d38b052bad1785942e98068382afc5b9773 Mon Sep 17 00:00:00 2001
From: Mark van Renswoude
Date: Mon, 19 Mar 2018 07:45:54 +0100
Subject: [PATCH 1/3] Added automatic retry to frontend
Better support for iOS language detection?
---
hosted/timezone.php | 13 +++++++++
src/assets/version.h | 4 +--
src/main.cpp | 10 ++-----
src/main.triggers.h | 13 +++++++++
web/app.js | 65 +++++++++++++++++++++++++++++++++-----------
web/dist/bundle.js | 2 +-
web/index.html | 6 ++--
web/lang.js | 4 +--
8 files changed, 84 insertions(+), 33 deletions(-)
diff --git a/hosted/timezone.php b/hosted/timezone.php
index 33d184b..1e62312 100644
--- a/hosted/timezone.php
+++ b/hosted/timezone.php
@@ -1,3 +1,16 @@
\ No newline at end of file
diff --git a/src/assets/version.h b/src/assets/version.h
index 8e34c37..7591d38 100644
--- a/src/assets/version.h
+++ b/src/assets/version.h
@@ -4,10 +4,10 @@
const uint8_t VersionMajor = 2;
const uint8_t VersionMinor = 0;
const uint8_t VersionPatch = 0;
-const uint8_t VersionMetadata = ;
+const uint8_t VersionMetadata = 0;
const char VersionBranch[] = "master";
const char VersionSemVer[] = "2.0.0";
-const char VersionFullSemVer[] = "2.0.0";
+const char VersionFullSemVer[] = "2.0.0+0";
const char VersionCommitDate[] = "2018-02-17";
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 1278f67..104c1c0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -75,7 +75,7 @@ void setup()
stairs = new Stairs();
stairs->init(pwmDriver);
-
+ /*
_dln("Setup :: starting initialization sequence");
stairs->set(0, 255);
delay(300);
@@ -89,6 +89,7 @@ void setup()
}
stairs->set(stepCount - 1, 0);
+ */
_dln("Setup :: initializing WiFi");
WiFi.persistent(false);
@@ -118,13 +119,6 @@ void loop()
ESP.restart();
}
- if (motionTriggerSettingsChanged)
- {
- initMotionPins();
- motionTriggerSettingsChanged = false;
- }
-
-
currentTime = millis();
updateDebugStatus();
diff --git a/src/main.triggers.h b/src/main.triggers.h
index a76b5c7..432846e 100644
--- a/src/main.triggers.h
+++ b/src/main.triggers.h
@@ -302,6 +302,13 @@ bool lastMotion = false;
void updateMotionTrigger()
{
+ if (motionTriggerSettingsChanged)
+ {
+ initMotionPins();
+ activeMotionStart = 0;
+ }
+
+
if (!motionTriggerSettings->enabled() || !motionTriggerSettings->triggerCount())
{
activeMotionStart = 0;
@@ -355,6 +362,12 @@ void checkTriggers()
bool motionChanged = (activeMotionStart > 0) != lastMotion;
lastMotion = (activeMotionStart > 0);
+ if (motionTriggerSettingsChanged)
+ {
+ motionChanged = true;
+ motionTriggerSettingsChanged = false;
+ }
+
if (!motionChanged && !timeTriggerChanged)
return;
diff --git a/web/app.js b/web/app.js
index 66353c8..04cd2e9 100644
--- a/web/app.js
+++ b/web/app.js
@@ -1,5 +1,36 @@
function startApp()
{
+ // Source: https://github.com/axios/axios/issues/164
+ axios.interceptors.response.use(undefined, function axiosRetryInterceptor(err) {
+ var config = err.config;
+ // If config does not exist or the retry option is not set, reject
+ if(!config || !config.retry) return Promise.reject(err);
+
+ // Set the variable for keeping track of the retry count
+ config.__retryCount = config.__retryCount || 0;
+
+ // Check if we've maxed out the total number of retries
+ if(config.__retryCount >= config.retry) {
+ // Reject with the error
+ return Promise.reject(err);
+ }
+
+ // Increase the retry count
+ config.__retryCount += 1;
+
+ // Create new promise to handle exponential backoff
+ var backoff = new Promise(function(resolve) {
+ setTimeout(function() {
+ resolve();
+ }, config.retryDelay || 1);
+ });
+
+ // Return the promise in which recalls axios to retry the request
+ return backoff.then(function() {
+ return axios(config);
+ });
+ });
+
Vue.component('check', {
template: '