-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Merge pull request #422 from sparkfun/Fix_#419"
- Loading branch information
Showing
2 changed files
with
27 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1209,8 +1209,8 @@ void provisioningSetState(uint8_t newState) | |
} | ||
} | ||
|
||
unsigned long provisioningStartTime_millis; | ||
const unsigned long provisioningTimeout_ms = 120000; | ||
unsigned long provisioningStartTime; | ||
const unsigned long provisioningTimeout = 120000; | ||
|
||
void updateProvisioning() | ||
{ | ||
|
@@ -1229,15 +1229,14 @@ void updateProvisioning() | |
default: | ||
case PROVISIONING_OFF: | ||
{ | ||
provisioningStartTime_millis = millis(); // Record the start time so we can timeout | ||
provisioningStartTime = millis(); // Record the start time so we can timeout | ||
provisioningSetState(PROVISIONING_WAIT_RTC); | ||
} | ||
break; | ||
case PROVISIONING_WAIT_RTC: | ||
{ | ||
if ((online.rtc) | ||
// If RTC is not online after provisioningTimeout_ms, try to provision anyway | ||
|| (millis() > (provisioningStartTime_millis + provisioningTimeout_ms)) | ||
|| (millis() > (provisioningStartTime + provisioningTimeout)) | ||
|| (settings.requestKeyUpdate)) | ||
provisioningSetState(PROVISIONING_NOT_STARTED); | ||
} | ||
|
@@ -1259,7 +1258,6 @@ void updateProvisioning() | |
systemPrintln("Invalid certificates or keys. Starting provisioning"); | ||
provisioningSetState(PROVISIONING_CHECK_NETWORK); | ||
} | ||
// If RTC is not online, we have to skip PROVISIONING_CHECK_ATTEMPT | ||
else if (!online.rtc) | ||
{ | ||
if (settings.debugPpCertificate) | ||
|
@@ -1268,21 +1266,21 @@ void updateProvisioning() | |
} | ||
else | ||
{ | ||
// RTC is online. Determine days until next key expires | ||
// Determine days until next key expires | ||
int daysRemaining = | ||
daysFromEpoch(settings.pointPerfectNextKeyStart + settings.pointPerfectNextKeyDuration + 1); | ||
|
||
if (settings.debugPpCertificate) | ||
systemPrintf("Days until keys expire: %d\r\n", daysRemaining); | ||
|
||
if (daysRemaining > 28) | ||
provisioningSetState(PROVISIONING_KEYS_REMAINING); // Don't need new keys | ||
provisioningSetState(PROVISIONING_KEYS_REMAINING); | ||
else | ||
provisioningSetState(PROVISIONING_CHECK_ATTEMPT); // Do need new keys | ||
provisioningSetState(PROVISIONING_CHECK_ATTEMPT); | ||
} | ||
} | ||
break; | ||
case PROVISIONING_CHECK_ATTEMPT: // Requires RTC to be online | ||
case PROVISIONING_CHECK_ATTEMPT: | ||
{ | ||
// When did we last try to get keys? Attempt every 24 hours - or always for DEVELOPER | ||
//if (rtc.getEpoch() - settings.lastKeyAttempt > ( ENABLE_DEVELOPER ? 0 : (60 * 60 * 24))) | ||
|
@@ -1319,22 +1317,22 @@ void updateProvisioning() | |
recordSystemSettings(); // Record these settings to unit | ||
ztpResponse = ZTP_NOT_STARTED; // HTTP_Client will update this | ||
httpClientModeNeeded = true; // This will start the HTTP_Client | ||
provisioningStartTime_millis = millis(); // Record the start time so we can timeout | ||
provisioningStartTime = millis(); // Record the start time so we can timeout | ||
paintGettingKeys(); | ||
provisioningSetState(PROVISIONING_STARTED); | ||
} | ||
case PROVISIONING_STARTED: | ||
{ | ||
if (millis() > (provisioningStartTime_millis + provisioningTimeout_ms)) | ||
if (millis() > (provisioningStartTime + provisioningTimeout)) | ||
{ | ||
httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) | ||
paintKeyUpdateFail(5000); | ||
provisioningSetState(PROVISIONING_KEYS_REMAINING); | ||
} | ||
else if (ztpResponse == ZTP_SUCCESS) | ||
{ | ||
httpClientModeNeeded = false; // Tell HTTP_Client to give up | ||
recordSystemSettings(); // Make sure the new cert and keys are recorded | ||
httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) | ||
recordSystemSettings(); | ||
provisioningSetState(PROVISIONING_KEYS_REMAINING); | ||
} | ||
else if (ztpResponse == ZTP_DEACTIVATED) | ||
|
@@ -1358,7 +1356,7 @@ void updateProvisioning() | |
"subscription. Please reference device ID: %s\r\n", | ||
landingPageUrl, hardwareID); | ||
|
||
httpClientModeNeeded = false; // Tell HTTP_Client to give up | ||
httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) | ||
displayAccountExpired(5000); | ||
|
||
provisioningSetState(PROVISIONING_KEYS_REMAINING); | ||
|
@@ -1384,7 +1382,7 @@ void updateProvisioning() | |
"activated. Please reference device ID: %s\r\n", | ||
landingPageUrl, hardwareID); | ||
|
||
httpClientModeNeeded = false; // Tell HTTP_Client to give up | ||
httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) | ||
displayNotListed(5000); | ||
|
||
provisioningSetState(PROVISIONING_KEYS_REMAINING); | ||
|
@@ -1400,7 +1398,7 @@ void updateProvisioning() | |
"[email protected] for more assistance. Please reference device ID: %s\r\n", | ||
hardwareID); | ||
|
||
httpClientModeNeeded = false; // Tell HTTP_Client to give up | ||
httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) | ||
displayAlreadyRegistered(5000); | ||
|
||
provisioningSetState(PROVISIONING_KEYS_REMAINING); | ||
|
@@ -1409,7 +1407,7 @@ void updateProvisioning() | |
{ | ||
systemPrintln("updateProvisioning: ZTP_UNKNOWN_ERROR"); | ||
|
||
httpClientModeNeeded = false; // Tell HTTP_Client to give up | ||
httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) | ||
|
||
provisioningSetState(PROVISIONING_KEYS_REMAINING); | ||
} | ||
|
@@ -1441,21 +1439,24 @@ void updateProvisioning() | |
|
||
gnssApplyPointPerfectKeys(); // Send current keys, if available, to GNSS | ||
|
||
provisioningStartTime_millis = millis(); // Record the time so we can restart after 24 hours | ||
provisioningSetState(PROVISIONING_WAIT_ATTEMPT); | ||
} | ||
break; | ||
case PROVISIONING_WAIT_ATTEMPT: // We may still not have RTC... Or RTC may come online _during_ this state. | ||
case PROVISIONING_WAIT_ATTEMPT: | ||
{ | ||
if (settings.requestKeyUpdate) | ||
provisioningSetState(PROVISIONING_CHECK_REMAINING); | ||
provisioningSetState(PROVISIONING_STARTING); | ||
else if (!settings.enablePointPerfectCorrections || !settings.autoKeyRenewal) | ||
provisioningSetState(PROVISIONING_OFF); | ||
// When did we last try to get keys? Attempt every 24 hours - or every 15 mins for DEVELOPER | ||
//else if (millis() > (provisioningStartTime_millis + ( ENABLE_DEVELOPER ? (1000 * 60 * 15) : (1000 * 60 * 60 * 24)))) | ||
//else if (online.rtc && (rtc.getEpoch() - settings.lastKeyAttempt > ( ENABLE_DEVELOPER ? (15 * 60) : (60 * 60 * 24)))) | ||
// When did we last try to get keys? Attempt every 24 hours | ||
else if (millis() > (provisioningStartTime_millis + (1000 * 60 * 60 * 24))) // Don't use settings.lastKeyAttempt (#419) | ||
provisioningSetState(PROVISIONING_CHECK_REMAINING); | ||
else if (online.rtc && (rtc.getEpoch() - settings.lastKeyAttempt > (60 * 60 * 24))) | ||
{ | ||
settings.lastKeyAttempt = rtc.getEpoch(); // Mark it | ||
recordSystemSettings(); // Record these settings to unit | ||
provisioningSetState(PROVISIONING_STARTING); | ||
} | ||
} | ||
break; | ||
} | ||
|