From f5edcd32e2072aad8c5099565800b3d3ecd7070c Mon Sep 17 00:00:00 2001 From: Nathan Seidle Date: Tue, 9 Jul 2024 08:54:05 -0600 Subject: [PATCH] Revert "Merge pull request #422 from sparkfun/Fix_#419" This reverts commit d554418fa76e3ee419cae8f85f4085a0e1f32f98, reversing changes made to 4a746900df60f40902884cbd885ec046d72fa44c. --- Firmware/RTK_Everywhere/MQTT_Client.ino | 5 +-- Firmware/RTK_Everywhere/menuPP.ino | 49 +++++++++++++------------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Firmware/RTK_Everywhere/MQTT_Client.ino b/Firmware/RTK_Everywhere/MQTT_Client.ino index 579b89458..434f193fb 100644 --- a/Firmware/RTK_Everywhere/MQTT_Client.ino +++ b/Firmware/RTK_Everywhere/MQTT_Client.ino @@ -457,9 +457,8 @@ void mqttClientReceiveMessage(int messageSize) settings.pointPerfectNextKeyDuration = (1000LL * 60 * 60 * 24 * 28) - 1; // Assume next key duration is 28 days - if (online.rtc) - settings.lastKeyAttempt = rtc.getEpoch(); // Mark it - but only if RTC is online - + settings.lastKeyAttempt = rtc.getEpoch(); // Mark it + recordSystemSettings(); // Record these settings to unit if (settings.debugCorrections == true) diff --git a/Firmware/RTK_Everywhere/menuPP.ino b/Firmware/RTK_Everywhere/menuPP.ino index 88122e334..29b84a82d 100644 --- a/Firmware/RTK_Everywhere/menuPP.ino +++ b/Firmware/RTK_Everywhere/menuPP.ino @@ -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,7 +1266,7 @@ 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); @@ -1276,13 +1274,13 @@ void updateProvisioning() 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,13 +1317,13 @@ 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); @@ -1333,8 +1331,8 @@ void updateProvisioning() } 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() "support@sparkfun.com 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; }