From d8ac05b153a2480ea0dc2d0b933f7c0f7db18cc9 Mon Sep 17 00:00:00 2001 From: Tobias Blum Date: Sat, 4 Jan 2020 22:54:27 +0100 Subject: [PATCH] Fix SMODEPRESENCEREQUESTERROR mode --- src/main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index aa696ed..38994e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -461,6 +461,7 @@ void pollPresence() { if (!res) { state = SMODEPRESENCEREQUESTERROR; + retries++; } else if (responseDoc.containsKey("error")) { const char* _error_code = responseDoc["error"]["code"]; if (strcmp(_error_code, "InvalidAuthenticationToken")) { @@ -470,11 +471,13 @@ void pollPresence() { } else { Serial.printf("pollPresence() - Error: %s\n", _error_code); state = SMODEPRESENCEREQUESTERROR; + retries++; } } else { // Store presence info availability = responseDoc["availability"].as(); activity = responseDoc["activity"].as(); + retries = 0; setPresenceAnimation(); } @@ -560,7 +563,7 @@ void statemachine() { } // Statemachine: Poll for presence information, even if there was a error before (handled below) - if (state == SMODEPOLLPRESENCE || state == SMODEPRESENCEREQUESTERROR) { + if (state == SMODEPOLLPRESENCE) { if (millis() >= tsPolling) { Serial.println("Polling presence info ..."); pollPresence(); @@ -592,12 +595,13 @@ void statemachine() { if (laststate != SMODEPRESENCEREQUESTERROR) { retries = 0; } - retries++; + Serial.printf("Polling presence failed, retry #%d.\n", retries); if (retries >= 5) { // Try token refresh state = SMODEREFRESHTOKEN; } + state = SMODEPOLLPRESENCE; } // Update laststate