Skip to content

Commit

Permalink
Revert "Merge pull request #422 from sparkfun/Fix_#419"
Browse files Browse the repository at this point in the history
This reverts commit d554418, reversing
changes made to 4a74690.
  • Loading branch information
nseidle committed Jul 9, 2024
1 parent d554418 commit f5edcd3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
5 changes: 2 additions & 3 deletions Firmware/RTK_Everywhere/MQTT_Client.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
49 changes: 25 additions & 24 deletions Firmware/RTK_Everywhere/menuPP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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);
}
Expand All @@ -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)
Expand All @@ -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)))
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f5edcd3

Please sign in to comment.