From 264c1944035f8d7533951abbeb87fe3eef330f99 Mon Sep 17 00:00:00 2001 From: Nathan Seidle Date: Thu, 29 Aug 2024 13:09:28 -0600 Subject: [PATCH 1/4] Whitespace change --- Firmware/RTK_Everywhere/MQTT_Client.ino | 132 +++++++++++++----------- 1 file changed, 71 insertions(+), 61 deletions(-) diff --git a/Firmware/RTK_Everywhere/MQTT_Client.ino b/Firmware/RTK_Everywhere/MQTT_Client.ino index ff4a8b063..0ec299764 100644 --- a/Firmware/RTK_Everywhere/MQTT_Client.ino +++ b/Firmware/RTK_Everywhere/MQTT_Client.ino @@ -75,8 +75,7 @@ MQTT_Client.ino // When the dict is received, we subscribe to the nearest localized topic and unsubscribe from the continental topic // When the AssistNow MGA data arrives, we unsubscribe and subscribe to AssistNow updates - -String localizedDistributionDictTopic = ""; //Used in menuPP +String localizedDistributionDictTopic = ""; // Used in menuPP String localizedDistributionTileTopic = ""; #ifdef COMPILE_MQTT_CLIENT @@ -116,7 +115,7 @@ const int mqttClientStateNameEntries = sizeof(mqttClientStateName) / sizeof(mqtt const RtkMode_t mqttClientMode = RTK_MODE_ROVER | RTK_MODE_BASE_SURVEY_IN; -const String MQTT_TOPIC_ASSISTNOW = "/pp/ubx/mga"; // AssistNow (MGA) topic +const String MQTT_TOPIC_ASSISTNOW = "/pp/ubx/mga"; // AssistNow (MGA) topic const String MQTT_TOPIC_ASSISTNOW_UPDATES = "/pp/ubx/mga/updates"; // AssistNow (MGA) topic - updates only // Note: the key and correction topics are now stored in settings - extracted from ZTP const char localizedPrefix[] = "pp/ip/L"; // The localized distribution topic prefix. Note: starts with "pp", not "/pp" @@ -125,13 +124,13 @@ const char localizedPrefix[] = "pp/ip/L"; // The localized distribution topic pr // Locals //---------------------------------------- -std::vector mqttSubscribeTopics; // List of MQTT topics to be subscribed to +std::vector mqttSubscribeTopics; // List of MQTT topics to be subscribed to std::vector mqttClientSubscribedTopics; // List of topics currently subscribed to static MqttClient *mqttClient; static char *mqttClientCertificateBuffer = nullptr; // Buffer for client certificate -static char *mqttClientPrivateKeyBuffer = nullptr; // Buffer for client private key +static char *mqttClientPrivateKeyBuffer = nullptr; // Buffer for client private key // Throttle the time between connection attempts static int mqttClientConnectionAttempts; // Count the number of connection attempts between restarts @@ -329,8 +328,8 @@ void mqttClientReceiveMessage(int messageSize) if (mqttCount > 0) { // Check for localizedDistributionDictTopic - if ((localizedDistributionDictTopic.length() > 0) - && (strcmp(topic, localizedDistributionDictTopic.c_str()) == 0)) + if ((localizedDistributionDictTopic.length() > 0) && + (strcmp(topic, localizedDistributionDictTopic.c_str()) == 0)) { // We should be using a JSON library to read the nodes. But JSON is // heavy on RAM and the dict could be 25KB for Level 3. @@ -363,7 +362,7 @@ void mqttClientReceiveMessage(int messageSize) float minDist = 99999.0; // Minimum distance to tile center in centidegrees char *preservedTile; char *tile = strtok_r(nodes, ",", &preservedTile); - int latitude = int(gnssGetLatitude() * 100.0); // Centidegrees + int latitude = int(gnssGetLatitude() * 100.0); // Centidegrees int longitude = int(gnssGetLongitude() * 100.0); // Centidegrees while (tile != nullptr) { @@ -375,15 +374,18 @@ void mqttClientReceiveMessage(int messageSize) lat = 0 - lat; if (ew == 'W') lon = 0 - lon; - float factorLon = cos(radians(latitude / 100.0)); // Scale lon by the lat - float distScaled = pow(pow(lat - latitude, 2) + pow((lon - longitude) * factorLon, 2), 0.5); // Calculate distance to tile center in centidegrees + float factorLon = cos(radians(latitude / 100.0)); // Scale lon by the lat + float distScaled = pow(pow(lat - latitude, 2) + pow((lon - longitude) * factorLon, 2), + 0.5); // Calculate distance to tile center in centidegrees if (distScaled < minDist) { minDist = distScaled; tile[12] = 0; // Convert the second quote to NULL for snprintf char tileTopic[50]; snprintf(tileTopic, sizeof(tileTopic), "%s", localizedDistributionDictTopic.c_str()); - snprintf(&tileTopic[strlen(localizedPrefix) + 13], sizeof(tileTopic) - (strlen(localizedPrefix) + 13), "%s", tile + 1); // Start after the first quote + snprintf(&tileTopic[strlen(localizedPrefix) + 13], + sizeof(tileTopic) - (strlen(localizedPrefix) + 13), "%s", + tile + 1); // Start after the first quote localizedDistributionTileTopic = tileTopic; } } @@ -398,16 +400,17 @@ void mqttClientReceiveMessage(int messageSize) // Is this the full AssistNow MGA data? If so, unsubscribe and subscribe to updates if (strcmp(topic, MQTT_TOPIC_ASSISTNOW.c_str()) == 0) { - std::vector::iterator pos = std::find(mqttSubscribeTopics.begin(), mqttSubscribeTopics.end(), MQTT_TOPIC_ASSISTNOW); + std::vector::iterator pos = + std::find(mqttSubscribeTopics.begin(), mqttSubscribeTopics.end(), MQTT_TOPIC_ASSISTNOW); if (pos != mqttSubscribeTopics.end()) mqttSubscribeTopics.erase(pos); - + mqttSubscribeTopics.push_back(MQTT_TOPIC_ASSISTNOW_UPDATES); } // Are these keys? If so, update our local copy - if ((strlen(settings.pointPerfectKeyDistributionTopic) > 0 ) - && (strcmp(topic, settings.pointPerfectKeyDistributionTopic) == 0)) + if ((strlen(settings.pointPerfectKeyDistributionTopic) > 0) && + (strcmp(topic, settings.pointPerfectKeyDistributionTopic) == 0)) { // Separate the UBX message into its constituent Key/ToW/Week parts uint8_t *payLoad = &mqttData[6]; @@ -444,7 +447,8 @@ void mqttClientReceiveMessage(int messageSize) WeekToWToUnixEpoch(&settings.pointPerfectCurrentKeyStart, currentWeek, currentToW); WeekToWToUnixEpoch(&settings.pointPerfectNextKeyStart, nextWeek, nextToW); - settings.pointPerfectCurrentKeyStart -= gnssGetLeapSeconds(); // Remove GPS leap seconds to align with u-blox + settings.pointPerfectCurrentKeyStart -= + gnssGetLeapSeconds(); // Remove GPS leap seconds to align with u-blox settings.pointPerfectNextKeyStart -= gnssGetLeapSeconds(); settings.pointPerfectCurrentKeyStart *= 1000; // Convert to ms @@ -453,10 +457,11 @@ void mqttClientReceiveMessage(int messageSize) settings.pointPerfectCurrentKeyDuration = settings.pointPerfectNextKeyStart - settings.pointPerfectCurrentKeyStart - 1; // settings.pointPerfectNextKeyDuration = - // settings.pointPerfectCurrentKeyDuration; // We assume next key duration is the same as current key - // duration because we have to + // settings.pointPerfectCurrentKeyDuration; // We assume next key duration is the same as current + // key duration because we have to - settings.pointPerfectNextKeyDuration = (1000LL * 60 * 60 * 24 * 28) - 1; // Assume next key duration is 28 days + settings.pointPerfectNextKeyDuration = + (1000LL * 60 * 60 * 24 * 28) - 1; // Assume next key duration is 28 days settings.lastKeyAttempt = rtc.getEpoch(); // Mark it @@ -472,13 +477,11 @@ void mqttClientReceiveMessage(int messageSize) // Only push SPARTN if the priority says we can if ( // We can get correction data from the continental topic - ((strlen(settings.regionalCorrectionTopics[settings.geographicRegion]) > 0) - && (strcmp(topic, settings.regionalCorrectionTopics[settings.geographicRegion]) == 0)) - || + ((strlen(settings.regionalCorrectionTopics[settings.geographicRegion]) > 0) && + (strcmp(topic, settings.regionalCorrectionTopics[settings.geographicRegion]) == 0)) || // Or from the localized distribution tile topic - ((localizedDistributionTileTopic.length() > 0) - && (strcmp(topic, localizedDistributionTileTopic.c_str()) == 0)) - ) + ((localizedDistributionTileTopic.length() > 0) && + (strcmp(topic, localizedDistributionTileTopic.c_str()) == 0))) { // Determine if MQTT (SPARTN data) is the correction source if (correctionLastSeen(CORR_IP)) @@ -504,8 +507,7 @@ void mqttClientReceiveMessage(int messageSize) else { // KEYS or MGA - if (((settings.debugMqttClientData == true) || (settings.debugCorrections == true)) && - !inMainMenu) + if (((settings.debugMqttClientData == true) || (settings.debugCorrections == true)) && !inMainMenu) systemPrintf("Pushing %d bytes from %s topic to GNSS\r\n", mqttCount, topic); gnssPushRawData(mqttData, mqttCount); @@ -615,7 +617,7 @@ void mqttClientStop(bool shutdown) { if (settings.debugMqttClientState) systemPrintln("Freeing mqttSecureClient"); - //delete mqttSecureClient; // Don't. This causes issue #335 + // delete mqttSecureClient; // Don't. This causes issue #335 mqttSecureClient = nullptr; reportHeapNow(settings.debugMqttClientState); } @@ -652,9 +654,9 @@ void mqttClientStop(bool shutdown) if (shutdown) { mqttClientSetState(MQTT_CLIENT_OFF); - //settings.enablePointPerfectCorrections = false; + // settings.enablePointPerfectCorrections = false; //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Why? This means PointPerfect Corrections - //cannot be restarted without opening the menu or web configuration page... + // cannot be restarted without opening the menu or web configuration page... mqttClientConnectionAttempts = 0; mqttClientConnectionAttemptTimeout = 0; } @@ -785,7 +787,8 @@ void mqttClientUpdate() { if (settings.debugMqttClientState) systemPrintln("MQTT_CLIENT_CONNECTING_2_SERVER no certificate available"); - mqttClientRestart(); // This does need a restart. Was mqttClientShutdown, but that causes an immediate retry with no timeout + mqttClientRestart(); // This does need a restart. Was mqttClientShutdown, but that causes an immediate retry + // with no timeout break; } mqttSecureClient->setCertificate(mqttClientCertificateBuffer); @@ -796,7 +799,8 @@ void mqttClientUpdate() { if (settings.debugMqttClientState) systemPrintln("MQTT_CLIENT_CONNECTING_2_SERVER no private key available"); - mqttClientRestart(); // This does need a restart. Was mqttClientShutdown, but that causes an immediate retry with no timeout + mqttClientRestart(); // This does need a restart. Was mqttClientShutdown, but that causes an immediate retry + // with no timeout break; } mqttSecureClient->setPrivateKey(mqttClientPrivateKeyBuffer); @@ -828,7 +832,7 @@ void mqttClientUpdate() // The MQTT server is now connected mqttClient->onMessage(mqttClientReceiveMessage); - mqttSubscribeTopics.clear(); // Clear the list of MQTT topics to be subscribed to + mqttSubscribeTopics.clear(); // Clear the list of MQTT topics to be subscribed to mqttClientSubscribedTopics.clear(); // Clear the list of topics currently subscribed to localizedDistributionDictTopic = ""; localizedDistributionTileTopic = ""; @@ -850,11 +854,12 @@ void mqttClientUpdate() if (settings.debugMqttClientState) systemPrintln("MQTT client - no corrections topic. Continuing..."); } - // Subscribing to the localized distribution dictionary and local tile is handled by MQTT_CLIENT_SERVICES_CONNECTED - // since we need a 3D fix for those + // Subscribing to the localized distribution dictionary and local tile is handled by + // MQTT_CLIENT_SERVICES_CONNECTED since we need a 3D fix for those + + mqttClientLastDataReceived = + millis(); // Prevent MQTT_CLIENT_SERVICES_CONNECTED from going immediately into timeout - mqttClientLastDataReceived = millis(); // Prevent MQTT_CLIENT_SERVICES_CONNECTED from going immediately into timeout - reportHeapNow(settings.debugMqttClientState); mqttClientSetState(MQTT_CLIENT_SERVICES_CONNECTED); @@ -886,8 +891,10 @@ void mqttClientUpdate() for (auto it = mqttSubscribeTopics.begin(); it != mqttSubscribeTopics.end(); it = std::next(it)) { String topic = *it; - std::vector::iterator pos = std::find(mqttClientSubscribedTopics.begin(), mqttClientSubscribedTopics.end(), topic); - if (pos == mqttClientSubscribedTopics.end()) // The mqttSubscribeTopics is not in mqttClientSubscribedTopics, so subscribe + std::vector::iterator pos = + std::find(mqttClientSubscribedTopics.begin(), mqttClientSubscribedTopics.end(), topic); + if (pos == mqttClientSubscribedTopics + .end()) // The mqttSubscribeTopics is not in mqttClientSubscribedTopics, so subscribe { if (settings.debugMqttClientState) systemPrintf("MQTT_Client subscribing to topic %s\r\n", topic.c_str()); @@ -914,8 +921,10 @@ void mqttClientUpdate() for (auto it = mqttClientSubscribedTopics.begin(); it != mqttClientSubscribedTopics.end(); it = std::next(it)) { String topic = *it; - std::vector::iterator pos = std::find(mqttSubscribeTopics.begin(), mqttSubscribeTopics.end(), topic); - if (pos == mqttSubscribeTopics.end()) // The mqttClientSubscribedTopics is not in mqttSubscribeTopics, so unsubscribe + std::vector::iterator pos = + std::find(mqttSubscribeTopics.begin(), mqttSubscribeTopics.end(), topic); + if (pos == mqttSubscribeTopics + .end()) // The mqttClientSubscribedTopics is not in mqttSubscribeTopics, so unsubscribe { if (settings.debugMqttClientState) systemPrintf("MQTT_Client unsubscribing from topic %s\r\n", topic.c_str()); @@ -939,38 +948,39 @@ void mqttClientUpdate() break; // Break out of this state // Check if localized distribution is enabled - if ((strlen(settings.regionalCorrectionTopics[settings.geographicRegion]) > 0) && (settings.useLocalizedDistribution)) + if ((strlen(settings.regionalCorrectionTopics[settings.geographicRegion]) > 0) && + (settings.useLocalizedDistribution)) { uint8_t fixType = gnssGetFixType(); - double latitude = gnssGetLatitude(); // degrees + double latitude = gnssGetLatitude(); // degrees double longitude = gnssGetLongitude(); // degrees - if (fixType >= 3) // If we have a 3D fix + if (fixType >= 3) // If we have a 3D fix { // If both the dict and tile topics are empty, prepare to subscribe to the dict topic if ((localizedDistributionDictTopic.length() == 0) && (localizedDistributionTileTopic.length() == 0)) { float tileDelta = 2.5; // 2.5 degrees (10 degrees and 5 degrees are also possible) - if ((settings.localizedDistributionTileLevel == 0) || (settings.localizedDistributionTileLevel == 3)) + if ((settings.localizedDistributionTileLevel == 0) || + (settings.localizedDistributionTileLevel == 3)) tileDelta = 10.0; - if ((settings.localizedDistributionTileLevel == 1) || (settings.localizedDistributionTileLevel == 4)) + if ((settings.localizedDistributionTileLevel == 1) || + (settings.localizedDistributionTileLevel == 4)) tileDelta = 5.0; - float lat = latitude; // Degrees + float lat = latitude; // Degrees lat = floor(lat / tileDelta) * tileDelta; // Calculate the tile center in degrees lat += tileDelta / 2.0; int lat_i = round(lat * 100.0); // integer centidegrees - float lon = longitude; // Degrees + float lon = longitude; // Degrees lon = floor(lon / tileDelta) * tileDelta; // Calculate the tile center in degrees lon += tileDelta / 2.0; int lon_i = round(lon * 100.0); // integer centidegrees char dictTopic[50]; - snprintf(dictTopic, sizeof(dictTopic), "%s%c%c%04d%c%05d/dict", - localizedPrefix, char(0x30 + settings.localizedDistributionTileLevel), - (lat_i < 0) ? 'S' : 'N', abs(lat_i), - (lon_i < 0) ? 'W' : 'E', abs(lon_i)); - + snprintf(dictTopic, sizeof(dictTopic), "%s%c%c%04d%c%05d/dict", localizedPrefix, + char(0x30 + settings.localizedDistributionTileLevel), (lat_i < 0) ? 'S' : 'N', abs(lat_i), + (lon_i < 0) ? 'W' : 'E', abs(lon_i)); localizedDistributionDictTopic = dictTopic; mqttSubscribeTopics.push_back(localizedDistributionDictTopic); @@ -986,25 +996,25 @@ void mqttClientUpdate() // Subscribe to the localizedDistributionTileTopic mqttSubscribeTopics.push_back(localizedDistributionTileTopic); // Unsubscribe from the localizedDistributionDictTopic - std::vector::iterator pos = std::find(mqttSubscribeTopics.begin(), mqttSubscribeTopics.end(), localizedDistributionDictTopic); + std::vector::iterator pos = std::find( + mqttSubscribeTopics.begin(), mqttSubscribeTopics.end(), localizedDistributionDictTopic); if (pos != mqttSubscribeTopics.end()) - mqttSubscribeTopics.erase(pos); + mqttSubscribeTopics.erase(pos); // Unsubscribe from the continental corrections - pos = std::find(mqttSubscribeTopics.begin(), mqttSubscribeTopics.end(), String(settings.regionalCorrectionTopics[settings.geographicRegion])); + pos = std::find(mqttSubscribeTopics.begin(), mqttSubscribeTopics.end(), + String(settings.regionalCorrectionTopics[settings.geographicRegion])); if (pos != mqttSubscribeTopics.end()) - mqttSubscribeTopics.erase(pos); + mqttSubscribeTopics.erase(pos); - localizedDistributionDictTopic = ""; // Empty localizedDistributionDictTopic to prevent this state being repeated + localizedDistributionDictTopic = + ""; // Empty localizedDistributionDictTopic to prevent this state being repeated breakOut = true; } - - } } if (breakOut) break; // Break out of this state - // Add any new state checking above this line break; } // /case MQTT_CLIENT_SERVICES_CONNECTED From 53631dc25ffa9a73fbb045b6253d4e5661cf988e Mon Sep 17 00:00:00 2001 From: Nathan Seidle Date: Thu, 29 Aug 2024 13:10:10 -0600 Subject: [PATCH 2/4] Update last attempt only if RTC is online Re-implementing main #422 - https://github.com/sparkfun/SparkFun_RTK_Everywhere_Firmware/commit/09a4b45e505c6ac9d62ffa463419e57630712169 --- Firmware/RTK_Everywhere/MQTT_Client.ino | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Firmware/RTK_Everywhere/MQTT_Client.ino b/Firmware/RTK_Everywhere/MQTT_Client.ino index 0ec299764..3ac6353a8 100644 --- a/Firmware/RTK_Everywhere/MQTT_Client.ino +++ b/Firmware/RTK_Everywhere/MQTT_Client.ino @@ -463,9 +463,10 @@ void mqttClientReceiveMessage(int messageSize) settings.pointPerfectNextKeyDuration = (1000LL * 60 * 60 * 24 * 28) - 1; // Assume next key duration is 28 days - settings.lastKeyAttempt = rtc.getEpoch(); // Mark it - - recordSystemSettings(); // Record these settings to unit + if (online.rtc) + settings.lastKeyAttempt = rtc.getEpoch(); // Mark it - but only if RTC is online + + recordSystemSettings(); // Record these settings to unit if (settings.debugCorrections == true) pointperfectPrintKeyInformation(); From d43babaecc93a1481365037bca457b4c2a758f5c Mon Sep 17 00:00:00 2001 From: Nathan Seidle Date: Thu, 29 Aug 2024 13:10:35 -0600 Subject: [PATCH 3/4] Whitespace changes --- Firmware/RTK_Everywhere/menuPP.ino | 438 ++++++++++++++--------------- 1 file changed, 215 insertions(+), 223 deletions(-) diff --git a/Firmware/RTK_Everywhere/menuPP.ino b/Firmware/RTK_Everywhere/menuPP.ino index 62a1944da..8de30859e 100644 --- a/Firmware/RTK_Everywhere/menuPP.ino +++ b/Firmware/RTK_Everywhere/menuPP.ino @@ -1,5 +1,5 @@ -#include "mbedtls/ssl.h" //Needed for certificate validation #include "mbedtls/ctr_drbg.h" +#include "mbedtls/ssl.h" //Needed for certificate validation //---------------------------------------- // Locals - compiled out @@ -221,8 +221,7 @@ void createZtpRequest(String &str) // Get the hardware ID char hardwareID[15]; snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X%02X%02X%02X%02X", btMACAddress[0], btMACAddress[1], - btMACAddress[2], btMACAddress[3], btMACAddress[4], btMACAddress[5], - productVariant); + btMACAddress[2], btMACAddress[3], btMACAddress[4], btMACAddress[5], productVariant); // Get the firmware version string char versionString[9]; @@ -463,7 +462,8 @@ bool checkPrivateKeyValidity(char *privateKey, int privateKeySize) mbedtls_ctr_drbg_context ctr_drbg; mbedtls_ctr_drbg_init(&ctr_drbg); - int result_code = mbedtls_pk_parse_key(&pk, (unsigned char *)privateKey, privateKeySize + 1, nullptr, 0, mbedtls_ctr_drbg_random, &ctr_drbg); + int result_code = mbedtls_pk_parse_key(&pk, (unsigned char *)privateKey, privateKeySize + 1, nullptr, 0, + mbedtls_ctr_drbg_random, &ctr_drbg); mbedtls_pk_free(&pk); mbedtls_ctr_drbg_free(&ctr_drbg); @@ -811,14 +811,15 @@ void beginLBand() int r = 0; // Step through each geographic region for (; r < numRegionalAreas; r++) { - if ((longitude >= Regional_Information_Table[r].area.lonWest) - && (longitude <= Regional_Information_Table[r].area.lonEast) - && (latitude >= Regional_Information_Table[r].area.latSouth) - && (latitude <= Regional_Information_Table[r].area.latNorth)) + if ((longitude >= Regional_Information_Table[r].area.lonWest) && + (longitude <= Regional_Information_Table[r].area.lonEast) && + (latitude >= Regional_Information_Table[r].area.latSouth) && + (latitude <= Regional_Information_Table[r].area.latNorth)) { LBandFreq = Regional_Information_Table[r].frequency; if (settings.debugCorrections == true) - systemPrintf("Setting L-Band frequency to %s (%dHz)\r\n", Regional_Information_Table[r].name, LBandFreq); + systemPrintf("Setting L-Band frequency to %s (%dHz)\r\n", Regional_Information_Table[r].name, + LBandFreq); break; } } @@ -826,15 +827,16 @@ void beginLBand() { LBandFreq = Regional_Information_Table[settings.geographicRegion].frequency; if (settings.debugCorrections == true) - systemPrintf("Error: Unknown L-Band geographic region. Using %s (%dHz)\r\n", Regional_Information_Table[settings.geographicRegion].name, LBandFreq); + systemPrintf("Error: Unknown L-Band geographic region. Using %s (%dHz)\r\n", + Regional_Information_Table[settings.geographicRegion].name, LBandFreq); } - } else { LBandFreq = Regional_Information_Table[settings.geographicRegion].frequency; if (settings.debugCorrections == true) - systemPrintf("No fix available for L-Band geographic region determination. Using %s (%dHz)\r\n", Regional_Information_Table[settings.geographicRegion].name, LBandFreq); + systemPrintf("No fix available for L-Band geographic region determination. Using %s (%dHz)\r\n", + Regional_Information_Table[settings.geographicRegion].name, LBandFreq); } bool response = true; @@ -948,7 +950,7 @@ void menuPointPerfect() if (pointPerfectIsEnabled()) { -#ifdef COMPILE_NETWORK +#ifdef COMPILE_NETWORK systemPrint("2) Toggle Auto Key Renewal: "); if (settings.autoKeyRenewal == true) systemPrintln("Enabled"); @@ -980,7 +982,7 @@ void menuPointPerfect() else systemPrintln("Disabled"); } -#endif // COMPILE_NETWORK +#endif // COMPILE_NETWORK systemPrintln("c) Clear the Keys"); @@ -1003,7 +1005,7 @@ void menuPointPerfect() settings.requestKeyUpdate = settings.enablePointPerfectCorrections; // Force a key update - or don't } -#ifdef COMPILE_NETWORK +#ifdef COMPILE_NETWORK else if (incoming == 2 && pointPerfectIsEnabled()) { settings.autoKeyRenewal ^= 1; @@ -1027,7 +1029,7 @@ void menuPointPerfect() { settings.useAssistNow ^= 1; } -#endif // COMPILE_NETWORK +#endif // COMPILE_NETWORK else if (incoming == 'c' && pointPerfectIsEnabled()) { settings.pointPerfectCurrentKey[0] = 0; @@ -1224,250 +1226,240 @@ void updateProvisioning() switch (provisioningState) { - default: - case PROVISIONING_OFF: + default: + case PROVISIONING_OFF: { + provisioningStartTime = millis(); // Record the start time so we can timeout + provisioningSetState(PROVISIONING_WAIT_RTC); + } + break; + case PROVISIONING_WAIT_RTC: { + if ((online.rtc) || (millis() > (provisioningStartTime + provisioningTimeout)) || (settings.requestKeyUpdate)) + provisioningSetState(PROVISIONING_NOT_STARTED); + } + break; + case PROVISIONING_NOT_STARTED: { + if (settings.enablePointPerfectCorrections && (settings.autoKeyRenewal || settings.requestKeyUpdate)) { - provisioningStartTime = millis(); // Record the start time so we can timeout - provisioningSetState(PROVISIONING_WAIT_RTC); + provisioningSetState(PROVISIONING_CHECK_REMAINING); } - break; - case PROVISIONING_WAIT_RTC: + } + break; + case PROVISIONING_CHECK_REMAINING: { + // If we don't have certs or keys, begin zero touch provisioning + if (!checkCertificates() || strlen(settings.pointPerfectCurrentKey) == 0 || + strlen(settings.pointPerfectNextKey) == 0) { - if ((online.rtc) - || (millis() > (provisioningStartTime + provisioningTimeout)) - || (settings.requestKeyUpdate)) - provisioningSetState(PROVISIONING_NOT_STARTED); + if (settings.debugPpCertificate) + systemPrintln("Invalid certificates or keys. Starting provisioning"); + provisioningSetState(PROVISIONING_CHECK_NETWORK); } - break; - case PROVISIONING_NOT_STARTED: + // If requestKeyUpdate is true, begin provisioning + else if (settings.requestKeyUpdate) { - if (settings.enablePointPerfectCorrections && (settings.autoKeyRenewal || settings.requestKeyUpdate)) - { - provisioningSetState(PROVISIONING_CHECK_REMAINING); - } + if (settings.debugPpCertificate) + systemPrintln("requestKeyUpdate is true. Starting provisioning"); + provisioningSetState(PROVISIONING_CHECK_NETWORK); } - break; - case PROVISIONING_CHECK_REMAINING: + // If RTC is not online, we have to skip PROVISIONING_CHECK_ATTEMPT + else if (!online.rtc) { - // If we don't have certs or keys, begin zero touch provisioning - if (!checkCertificates() || strlen(settings.pointPerfectCurrentKey) == 0 || strlen(settings.pointPerfectNextKey) == 0) - { - if (settings.debugPpCertificate) - systemPrintln("Invalid certificates or keys. Starting provisioning"); - provisioningSetState(PROVISIONING_CHECK_NETWORK); - } - // If requestKeyUpdate is true, begin provisioning - else if (settings.requestKeyUpdate) - { - if (settings.debugPpCertificate) - systemPrintln("requestKeyUpdate is true. 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) - systemPrintln("No RTC. Starting provisioning"); - provisioningSetState(PROVISIONING_CHECK_NETWORK); - } - else - { - // Determine days until next key expires - int daysRemaining = - daysFromEpoch(settings.pointPerfectNextKeyStart + settings.pointPerfectNextKeyDuration + 1); + if (settings.debugPpCertificate) + systemPrintln("No RTC. Starting provisioning"); + provisioningSetState(PROVISIONING_CHECK_NETWORK); + } + else + { + // 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 (settings.debugPpCertificate) + systemPrintf("Days until keys expire: %d\r\n", daysRemaining); - if (daysRemaining > 28) - provisioningSetState(PROVISIONING_KEYS_REMAINING); - else - provisioningSetState(PROVISIONING_CHECK_ATTEMPT); - } + if (daysRemaining > 28) + provisioningSetState(PROVISIONING_KEYS_REMAINING); + else + provisioningSetState(PROVISIONING_CHECK_ATTEMPT); } - break; - case PROVISIONING_CHECK_ATTEMPT: + } + break; + 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))) + // When did we last try to get keys? Attempt every 24 hours + if (rtc.getEpoch() - settings.lastKeyAttempt > (60 * 60 * 24)) { - // 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))) - // When did we last try to get keys? Attempt every 24 hours - if (rtc.getEpoch() - settings.lastKeyAttempt > (60 * 60 * 24)) - { - settings.lastKeyAttempt = rtc.getEpoch(); // Mark it - recordSystemSettings(); // Record these settings to unit - provisioningSetState(PROVISIONING_CHECK_NETWORK); - } - else - { - if (settings.debugPpCertificate) - systemPrintln("Already tried to obtain keys for today"); - provisioningSetState(PROVISIONING_KEYS_REMAINING); - } + settings.lastKeyAttempt = rtc.getEpoch(); // Mark it + recordSystemSettings(); // Record these settings to unit + provisioningSetState(PROVISIONING_CHECK_NETWORK); } - break; - case PROVISIONING_CHECK_NETWORK: + else { - uint8_t networkType = networkGetActiveType(); - if ((networkType == NETWORK_TYPE_WIFI) && (wifiNetworkCount() == 0)) - { - displayNoSSIDs(2000); - provisioningSetState(PROVISIONING_KEYS_REMAINING); - } - else - provisioningSetState(PROVISIONING_STARTING); + if (settings.debugPpCertificate) + systemPrintln("Already tried to obtain keys for today"); + provisioningSetState(PROVISIONING_KEYS_REMAINING); } - break; - case PROVISIONING_STARTING: + } + break; + case PROVISIONING_CHECK_NETWORK: { + uint8_t networkType = networkGetActiveType(); + if ((networkType == NETWORK_TYPE_WIFI) && (wifiNetworkCount() == 0)) { - ztpResponse = ZTP_NOT_STARTED; // HTTP_Client will update this - httpClientModeNeeded = true; // This will start the HTTP_Client - provisioningStartTime = millis(); // Record the start time so we can timeout - paintGettingKeys(); - provisioningSetState(PROVISIONING_STARTED); + displayNoSSIDs(2000); + provisioningSetState(PROVISIONING_KEYS_REMAINING); } - case PROVISIONING_STARTED: + else + provisioningSetState(PROVISIONING_STARTING); + } + break; + case PROVISIONING_STARTING: { + ztpResponse = ZTP_NOT_STARTED; // HTTP_Client will update this + httpClientModeNeeded = true; // This will start the HTTP_Client + provisioningStartTime = millis(); // Record the start time so we can timeout + paintGettingKeys(); + provisioningSetState(PROVISIONING_STARTED); + } + case PROVISIONING_STARTED: { + // Only leave this state if we timeout or ZTP is complete + if (millis() > (provisioningStartTime_millis + provisioningTimeout_ms)) { - // Only leave this state if we timeout or ZTP is complete - if (millis() > (provisioningStartTime_millis + provisioningTimeout_ms)) - { - 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. (But it probably already has...) - recordSystemSettings(); - provisioningSetState(PROVISIONING_KEYS_REMAINING); - } - else if (ztpResponse == ZTP_DEACTIVATED) - { - char hardwareID[15]; - snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X%02X%02X%02X%02X", btMACAddress[0], btMACAddress[1], - btMACAddress[2], btMACAddress[3], btMACAddress[4], btMACAddress[5], productVariant); - - char landingPageUrl[200] = ""; - if (productVariant == RTK_TORCH) - snprintf(landingPageUrl, sizeof(landingPageUrl), - "or goto https://www.sparkfun.com/rtk_torch_registration "); - else if (productVariant == RTK_EVK) - snprintf(landingPageUrl, sizeof(landingPageUrl), - "or goto https://www.sparkfun.com/rtk_evk_registration "); - else - systemPrintln("pointperfectProvisionDevice() Platform missing landing page"); + 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. (But it probably already has...) + recordSystemSettings(); + provisioningSetState(PROVISIONING_KEYS_REMAINING); + } + else if (ztpResponse == ZTP_DEACTIVATED) + { + char hardwareID[15]; + snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X%02X%02X%02X%02X", btMACAddress[0], btMACAddress[1], + btMACAddress[2], btMACAddress[3], btMACAddress[4], btMACAddress[5], productVariant); - systemPrintf("This device has been deactivated. Please contact " - "support@sparkfun.com %sto renew the PointPerfect " - "subscription. Please reference device ID: %s\r\n", - landingPageUrl, hardwareID); + char landingPageUrl[200] = ""; + if (productVariant == RTK_TORCH) + snprintf(landingPageUrl, sizeof(landingPageUrl), + "or goto https://www.sparkfun.com/rtk_torch_registration "); + else if (productVariant == RTK_EVK) + snprintf(landingPageUrl, sizeof(landingPageUrl), + "or goto https://www.sparkfun.com/rtk_evk_registration "); + else + systemPrintln("pointperfectProvisionDevice() Platform missing landing page"); - httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) - displayAccountExpired(5000); + systemPrintf("This device has been deactivated. Please contact " + "support@sparkfun.com %sto renew the PointPerfect " + "subscription. Please reference device ID: %s\r\n", + landingPageUrl, hardwareID); - provisioningSetState(PROVISIONING_KEYS_REMAINING); - } - else if (ztpResponse == ZTP_NOT_WHITELISTED) - { - char hardwareID[15]; - snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X%02X%02X%02X%02X", btMACAddress[0], btMACAddress[1], - btMACAddress[2], btMACAddress[3], btMACAddress[4], btMACAddress[5], productVariant); - - char landingPageUrl[200] = ""; - if (productVariant == RTK_TORCH) - snprintf(landingPageUrl, sizeof(landingPageUrl), - "or goto https://www.sparkfun.com/rtk_torch_registration "); - else if (productVariant == RTK_EVK) - snprintf(landingPageUrl, sizeof(landingPageUrl), - "or goto https://www.sparkfun.com/rtk_evk_registration "); - else - systemPrintln("pointperfectProvisionDevice() Platform missing landing page"); + httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) + displayAccountExpired(5000); - systemPrintf("This device is not whitelisted. Please contact " - "support@sparkfun.com %sto get the subscription " - "activated. Please reference device ID: %s\r\n", - landingPageUrl, hardwareID); + provisioningSetState(PROVISIONING_KEYS_REMAINING); + } + else if (ztpResponse == ZTP_NOT_WHITELISTED) + { + char hardwareID[15]; + snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X%02X%02X%02X%02X", btMACAddress[0], btMACAddress[1], + btMACAddress[2], btMACAddress[3], btMACAddress[4], btMACAddress[5], productVariant); - httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) - displayNotListed(5000); + char landingPageUrl[200] = ""; + if (productVariant == RTK_TORCH) + snprintf(landingPageUrl, sizeof(landingPageUrl), + "or goto https://www.sparkfun.com/rtk_torch_registration "); + else if (productVariant == RTK_EVK) + snprintf(landingPageUrl, sizeof(landingPageUrl), + "or goto https://www.sparkfun.com/rtk_evk_registration "); + else + systemPrintln("pointperfectProvisionDevice() Platform missing landing page"); - provisioningSetState(PROVISIONING_KEYS_REMAINING); - } - else if (ztpResponse == ZTP_ALREADY_REGISTERED) - { - // Device is already registered to a different ZTP profile. - char hardwareID[15]; - snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X%02X%02X%02X%02X", btMACAddress[0], btMACAddress[1], - btMACAddress[2], btMACAddress[3], btMACAddress[4], btMACAddress[5], productVariant); - - systemPrintf("This device is registered on a different profile. Please contact " - "support@sparkfun.com for more assistance. Please reference device ID: %s\r\n", - hardwareID); - - httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) - displayAlreadyRegistered(5000); + systemPrintf("This device is not whitelisted. Please contact " + "support@sparkfun.com %sto get the subscription " + "activated. Please reference device ID: %s\r\n", + landingPageUrl, hardwareID); - provisioningSetState(PROVISIONING_KEYS_REMAINING); - } - else if (ztpResponse == ZTP_UNKNOWN_ERROR) - { - systemPrintln("updateProvisioning: ZTP_UNKNOWN_ERROR"); + httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) + displayNotListed(5000); - httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) - - provisioningSetState(PROVISIONING_KEYS_REMAINING); - } + provisioningSetState(PROVISIONING_KEYS_REMAINING); } - break; - case PROVISIONING_KEYS_REMAINING: + else if (ztpResponse == ZTP_ALREADY_REGISTERED) { - if (online.rtc == true) + // Device is already registered to a different ZTP profile. + char hardwareID[15]; + snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X%02X%02X%02X%02X", btMACAddress[0], btMACAddress[1], + btMACAddress[2], btMACAddress[3], btMACAddress[4], btMACAddress[5], productVariant); + + systemPrintf("This device is registered on a different profile. Please contact " + "support@sparkfun.com for more assistance. Please reference device ID: %s\r\n", + hardwareID); + + httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) + displayAlreadyRegistered(5000); + + provisioningSetState(PROVISIONING_KEYS_REMAINING); + } + else if (ztpResponse == ZTP_UNKNOWN_ERROR) + { + systemPrintln("updateProvisioning: ZTP_UNKNOWN_ERROR"); + + httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) + + provisioningSetState(PROVISIONING_KEYS_REMAINING); + } + } + break; + case PROVISIONING_KEYS_REMAINING: { + if (online.rtc == true) + { + if (settings.pointPerfectNextKeyStart > 0) { - if (settings.pointPerfectNextKeyStart > 0) + int daysRemaining = + daysFromEpoch(settings.pointPerfectNextKeyStart + settings.pointPerfectNextKeyDuration + 1); + systemPrintf("Days until PointPerfect keys expire: %d\r\n", daysRemaining); + if (daysRemaining >= 0) + { + paintKeyDaysRemaining(daysRemaining, 2000); + } + else { - int daysRemaining = - daysFromEpoch(settings.pointPerfectNextKeyStart + settings.pointPerfectNextKeyDuration + 1); - systemPrintf("Days until PointPerfect keys expire: %d\r\n", daysRemaining); - if (daysRemaining >= 0) - { - paintKeyDaysRemaining(daysRemaining, 2000); - } - else - { - paintKeysExpired(); - } + paintKeysExpired(); } } - paintLBandConfigure(); + } + paintLBandConfigure(); - // Be sure we ignore any external RTCM sources - gnssDisableRtcmOnGnss(); + // Be sure we ignore any external RTCM sources + gnssDisableRtcmOnGnss(); - gnssApplyPointPerfectKeys(); // Send current keys, if available, to GNSS + gnssApplyPointPerfectKeys(); // Send current keys, if available, to GNSS - settings.requestKeyUpdate = false; // However we got here, clear requestKeyUpdate - recordSystemSettings(); // Record these settings to unit + settings.requestKeyUpdate = false; // However we got here, clear requestKeyUpdate + recordSystemSettings(); // Record these settings to unit - provisioningStartTime_millis = millis(); // Record the time so we can restart after 24 hours - provisioningSetState(PROVISIONING_WAIT_ATTEMPT); - } - break; - case PROVISIONING_WAIT_ATTEMPT: + provisioningStartTime_millis = millis(); // Record the time so we can restart after 24 hours + provisioningSetState(PROVISIONING_WAIT_ATTEMPT); + } + break; + case PROVISIONING_WAIT_ATTEMPT: { + if (settings.requestKeyUpdate) // requestKeyUpdate can be set via the menu, mode button or web config + provisioningSetState(PROVISIONING_CHECK_REMAINING); + 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 (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 (online.rtc && (rtc.getEpoch() - settings.lastKeyAttempt > (60 * 60 * 24))) { - if (settings.requestKeyUpdate) // requestKeyUpdate can be set via the menu, mode button or web config - provisioningSetState(PROVISIONING_CHECK_REMAINING); - 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 (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 (online.rtc && (rtc.getEpoch() - settings.lastKeyAttempt > (60 * 60 * 24))) - { - settings.lastKeyAttempt = rtc.getEpoch(); // Mark it - recordSystemSettings(); // Record these settings to unit - provisioningSetState(PROVISIONING_STARTING); - } + settings.lastKeyAttempt = rtc.getEpoch(); // Mark it + recordSystemSettings(); // Record these settings to unit + provisioningSetState(PROVISIONING_STARTING); } - break; + } + break; } // Periodically display the provisioning state From 6619428285dccfa69bc3609d4d009ae16cec3477 Mon Sep 17 00:00:00 2001 From: Nathan Seidle Date: Thu, 29 Aug 2024 13:22:07 -0600 Subject: [PATCH 4/4] Fix merge bugs - provisioningStartTime_millis Re-implementing main #422 - https://github.com/sparkfun/SparkFun_RTK_Everywhere_Firmware/commit/09a4b45e505c6ac9d62ffa463419e57630712169 --- Firmware/RTK_Everywhere/menuPP.ino | 47 +++++++++++++++--------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/Firmware/RTK_Everywhere/menuPP.ino b/Firmware/RTK_Everywhere/menuPP.ino index 8de30859e..bb0b0b347 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; -const unsigned long provisioningTimeout = 120000; +unsigned long provisioningStartTime_millis; +const unsigned long provisioningTimeout_ms = 120000; void updateProvisioning() { @@ -1228,12 +1228,14 @@ void updateProvisioning() { default: case PROVISIONING_OFF: { - provisioningStartTime = millis(); // Record the start time so we can timeout + provisioningStartTime_millis = millis(); // Record the start time so we can timeout provisioningSetState(PROVISIONING_WAIT_RTC); } break; case PROVISIONING_WAIT_RTC: { - if ((online.rtc) || (millis() > (provisioningStartTime + provisioningTimeout)) || (settings.requestKeyUpdate)) + if ((online.rtc) + // If RTC is not online after provisioningTimeout_ms, try to provision anyway + || (millis() > (provisioningStartTime_millis + provisioningTimeout_ms)) || (settings.requestKeyUpdate)) provisioningSetState(PROVISIONING_NOT_STARTED); } break; @@ -1269,7 +1271,7 @@ void updateProvisioning() } else { - // Determine days until next key expires + // RTC is online. Determine days until next key expires int daysRemaining = daysFromEpoch(settings.pointPerfectNextKeyStart + settings.pointPerfectNextKeyDuration + 1); @@ -1277,9 +1279,9 @@ void updateProvisioning() systemPrintf("Days until keys expire: %d\r\n", daysRemaining); if (daysRemaining > 28) - provisioningSetState(PROVISIONING_KEYS_REMAINING); + provisioningSetState(PROVISIONING_KEYS_REMAINING); // Don't need new keys else - provisioningSetState(PROVISIONING_CHECK_ATTEMPT); + provisioningSetState(PROVISIONING_CHECK_ATTEMPT); // Do need new keys } } break; @@ -1313,9 +1315,9 @@ void updateProvisioning() } break; case PROVISIONING_STARTING: { - ztpResponse = ZTP_NOT_STARTED; // HTTP_Client will update this - httpClientModeNeeded = true; // This will start the HTTP_Client - provisioningStartTime = millis(); // Record the start time so we can timeout + 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 paintGettingKeys(); provisioningSetState(PROVISIONING_STARTED); } @@ -1329,8 +1331,8 @@ void updateProvisioning() } else if (ztpResponse == ZTP_SUCCESS) { - httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) - recordSystemSettings(); + httpClientModeNeeded = false; // Tell HTTP_Client to give up + recordSystemSettings(); // Make sure the new cert and keys are recorded provisioningSetState(PROVISIONING_KEYS_REMAINING); } else if (ztpResponse == ZTP_DEACTIVATED) @@ -1354,7 +1356,7 @@ void updateProvisioning() "subscription. Please reference device ID: %s\r\n", landingPageUrl, hardwareID); - httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) + httpClientModeNeeded = false; // Tell HTTP_Client to give up. displayAccountExpired(5000); provisioningSetState(PROVISIONING_KEYS_REMAINING); @@ -1380,7 +1382,7 @@ void updateProvisioning() "activated. Please reference device ID: %s\r\n", landingPageUrl, hardwareID); - httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) + httpClientModeNeeded = false; // Tell HTTP_Client to give up. displayNotListed(5000); provisioningSetState(PROVISIONING_KEYS_REMAINING); @@ -1396,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. (But it probably already has...) + httpClientModeNeeded = false; // Tell HTTP_Client to give up. displayAlreadyRegistered(5000); provisioningSetState(PROVISIONING_KEYS_REMAINING); @@ -1405,7 +1407,7 @@ void updateProvisioning() { systemPrintln("updateProvisioning: ZTP_UNKNOWN_ERROR"); - httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...) + httpClientModeNeeded = false; // Tell HTTP_Client to give up. provisioningSetState(PROVISIONING_KEYS_REMAINING); } @@ -1449,15 +1451,12 @@ void updateProvisioning() 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 (online.rtc && (rtc.getEpoch() - settings.lastKeyAttempt > ( ENABLE_DEVELOPER ? (15 * 60) : (60 * 60 - // * 24)))) + // else if (millis() > (provisioningStartTime_millis + ( ENABLE_DEVELOPER ? (1000 * 60 * 15) : (1000 * 60 * 60 * + // 24)))) // When did we last try to get keys? Attempt every 24 hours - 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); - } + else if (millis() > + (provisioningStartTime_millis + (1000 * 60 * 60 * 24))) // Don't use settings.lastKeyAttempt (#419) + provisioningSetState(PROVISIONING_CHECK_REMAINING); } break; }