Skip to content

Commit

Permalink
Fix expiration time calc
Browse files Browse the repository at this point in the history
  • Loading branch information
nmtoblum committed Jan 5, 2020
1 parent bcff061 commit fb65022
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ uint8_t interval = 5;
String access_token = "";
String refresh_token = "";
String id_token = "";
uint8_t expires = 0;
unsigned int expires = 0;

String availability = "";
String activity = "";
Expand All @@ -102,10 +102,10 @@ String activity = "";
#define SMODEPOLLPRESENCE 21 // Poll for presence
#define SMODEREFRESHTOKEN 22 // Access token needs refresh
#define SMODEPRESENCEREQUESTERROR 23 // Access token needs refresh
int state = SMODEINITIAL;
int laststate = SMODEINITIAL;
uint8_t state = SMODEINITIAL;
uint8_t laststate = SMODEINITIAL;
static unsigned long tsPolling = 0;
unsigned int retries = 0;
uint8_t retries = 0;


/**
Expand Down Expand Up @@ -253,8 +253,7 @@ boolean requestJsonApi(JsonDocument& doc, String url, String payload = "", size_
// Send auth header?
if (sendAuth) {
https.addHeader("Authorization", "Bearer " + access_token);
DBG_PRINT(F("[HTTPS] Auth token valid for %d s."));
DBG_PRINTLN(getTokenLifetime());
Serial.printf("[HTTPS] Auth token valid for %d s.\n", getTokenLifetime());
}

// Start connection and send HTTP header
Expand Down Expand Up @@ -447,7 +446,7 @@ void pollForToken() {
access_token = responseDoc["access_token"].as<String>();
refresh_token = responseDoc["refresh_token"].as<String>();
id_token = responseDoc["id_token"].as<String>();
int _expires_in = responseDoc["expires_in"].as<unsigned int>();
unsigned int _expires_in = responseDoc["expires_in"].as<unsigned int>();
expires = millis() + (_expires_in * 1000); // Calculate timestamp when token expires

// Set state
Expand Down

0 comments on commit fb65022

Please sign in to comment.