Skip to content

Commit

Permalink
Fix SMODEPRESENCEREQUESTERROR mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nmtoblum committed Jan 4, 2020
1 parent 4ec60af commit d8ac05b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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<String>();
activity = responseDoc["activity"].as<String>();
retries = 0;

setPresenceAnimation();
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d8ac05b

Please sign in to comment.