Skip to content

Commit f5edcd3

Browse files
committed
Revert "Merge pull request #422 from sparkfun/Fix_#419"
This reverts commit d554418, reversing changes made to 4a74690.
1 parent d554418 commit f5edcd3

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

Firmware/RTK_Everywhere/MQTT_Client.ino

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,8 @@ void mqttClientReceiveMessage(int messageSize)
457457

458458
settings.pointPerfectNextKeyDuration = (1000LL * 60 * 60 * 24 * 28) - 1; // Assume next key duration is 28 days
459459

460-
if (online.rtc)
461-
settings.lastKeyAttempt = rtc.getEpoch(); // Mark it - but only if RTC is online
462-
460+
settings.lastKeyAttempt = rtc.getEpoch(); // Mark it
461+
463462
recordSystemSettings(); // Record these settings to unit
464463

465464
if (settings.debugCorrections == true)

Firmware/RTK_Everywhere/menuPP.ino

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,8 @@ void provisioningSetState(uint8_t newState)
12091209
}
12101210
}
12111211

1212-
unsigned long provisioningStartTime_millis;
1213-
const unsigned long provisioningTimeout_ms = 120000;
1212+
unsigned long provisioningStartTime;
1213+
const unsigned long provisioningTimeout = 120000;
12141214

12151215
void updateProvisioning()
12161216
{
@@ -1229,15 +1229,14 @@ void updateProvisioning()
12291229
default:
12301230
case PROVISIONING_OFF:
12311231
{
1232-
provisioningStartTime_millis = millis(); // Record the start time so we can timeout
1232+
provisioningStartTime = millis(); // Record the start time so we can timeout
12331233
provisioningSetState(PROVISIONING_WAIT_RTC);
12341234
}
12351235
break;
12361236
case PROVISIONING_WAIT_RTC:
12371237
{
12381238
if ((online.rtc)
1239-
// If RTC is not online after provisioningTimeout_ms, try to provision anyway
1240-
|| (millis() > (provisioningStartTime_millis + provisioningTimeout_ms))
1239+
|| (millis() > (provisioningStartTime + provisioningTimeout))
12411240
|| (settings.requestKeyUpdate))
12421241
provisioningSetState(PROVISIONING_NOT_STARTED);
12431242
}
@@ -1259,7 +1258,6 @@ void updateProvisioning()
12591258
systemPrintln("Invalid certificates or keys. Starting provisioning");
12601259
provisioningSetState(PROVISIONING_CHECK_NETWORK);
12611260
}
1262-
// If RTC is not online, we have to skip PROVISIONING_CHECK_ATTEMPT
12631261
else if (!online.rtc)
12641262
{
12651263
if (settings.debugPpCertificate)
@@ -1268,21 +1266,21 @@ void updateProvisioning()
12681266
}
12691267
else
12701268
{
1271-
// RTC is online. Determine days until next key expires
1269+
// Determine days until next key expires
12721270
int daysRemaining =
12731271
daysFromEpoch(settings.pointPerfectNextKeyStart + settings.pointPerfectNextKeyDuration + 1);
12741272

12751273
if (settings.debugPpCertificate)
12761274
systemPrintf("Days until keys expire: %d\r\n", daysRemaining);
12771275

12781276
if (daysRemaining > 28)
1279-
provisioningSetState(PROVISIONING_KEYS_REMAINING); // Don't need new keys
1277+
provisioningSetState(PROVISIONING_KEYS_REMAINING);
12801278
else
1281-
provisioningSetState(PROVISIONING_CHECK_ATTEMPT); // Do need new keys
1279+
provisioningSetState(PROVISIONING_CHECK_ATTEMPT);
12821280
}
12831281
}
12841282
break;
1285-
case PROVISIONING_CHECK_ATTEMPT: // Requires RTC to be online
1283+
case PROVISIONING_CHECK_ATTEMPT:
12861284
{
12871285
// When did we last try to get keys? Attempt every 24 hours - or always for DEVELOPER
12881286
//if (rtc.getEpoch() - settings.lastKeyAttempt > ( ENABLE_DEVELOPER ? 0 : (60 * 60 * 24)))
@@ -1319,22 +1317,22 @@ void updateProvisioning()
13191317
recordSystemSettings(); // Record these settings to unit
13201318
ztpResponse = ZTP_NOT_STARTED; // HTTP_Client will update this
13211319
httpClientModeNeeded = true; // This will start the HTTP_Client
1322-
provisioningStartTime_millis = millis(); // Record the start time so we can timeout
1320+
provisioningStartTime = millis(); // Record the start time so we can timeout
13231321
paintGettingKeys();
13241322
provisioningSetState(PROVISIONING_STARTED);
13251323
}
13261324
case PROVISIONING_STARTED:
13271325
{
1328-
if (millis() > (provisioningStartTime_millis + provisioningTimeout_ms))
1326+
if (millis() > (provisioningStartTime + provisioningTimeout))
13291327
{
13301328
httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...)
13311329
paintKeyUpdateFail(5000);
13321330
provisioningSetState(PROVISIONING_KEYS_REMAINING);
13331331
}
13341332
else if (ztpResponse == ZTP_SUCCESS)
13351333
{
1336-
httpClientModeNeeded = false; // Tell HTTP_Client to give up
1337-
recordSystemSettings(); // Make sure the new cert and keys are recorded
1334+
httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...)
1335+
recordSystemSettings();
13381336
provisioningSetState(PROVISIONING_KEYS_REMAINING);
13391337
}
13401338
else if (ztpResponse == ZTP_DEACTIVATED)
@@ -1358,7 +1356,7 @@ void updateProvisioning()
13581356
"subscription. Please reference device ID: %s\r\n",
13591357
landingPageUrl, hardwareID);
13601358

1361-
httpClientModeNeeded = false; // Tell HTTP_Client to give up
1359+
httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...)
13621360
displayAccountExpired(5000);
13631361

13641362
provisioningSetState(PROVISIONING_KEYS_REMAINING);
@@ -1384,7 +1382,7 @@ void updateProvisioning()
13841382
"activated. Please reference device ID: %s\r\n",
13851383
landingPageUrl, hardwareID);
13861384

1387-
httpClientModeNeeded = false; // Tell HTTP_Client to give up
1385+
httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...)
13881386
displayNotListed(5000);
13891387

13901388
provisioningSetState(PROVISIONING_KEYS_REMAINING);
@@ -1400,7 +1398,7 @@ void updateProvisioning()
14001398
"[email protected] for more assistance. Please reference device ID: %s\r\n",
14011399
hardwareID);
14021400

1403-
httpClientModeNeeded = false; // Tell HTTP_Client to give up
1401+
httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...)
14041402
displayAlreadyRegistered(5000);
14051403

14061404
provisioningSetState(PROVISIONING_KEYS_REMAINING);
@@ -1409,7 +1407,7 @@ void updateProvisioning()
14091407
{
14101408
systemPrintln("updateProvisioning: ZTP_UNKNOWN_ERROR");
14111409

1412-
httpClientModeNeeded = false; // Tell HTTP_Client to give up
1410+
httpClientModeNeeded = false; // Tell HTTP_Client to give up. (But it probably already has...)
14131411

14141412
provisioningSetState(PROVISIONING_KEYS_REMAINING);
14151413
}
@@ -1441,21 +1439,24 @@ void updateProvisioning()
14411439

14421440
gnssApplyPointPerfectKeys(); // Send current keys, if available, to GNSS
14431441

1444-
provisioningStartTime_millis = millis(); // Record the time so we can restart after 24 hours
14451442
provisioningSetState(PROVISIONING_WAIT_ATTEMPT);
14461443
}
14471444
break;
1448-
case PROVISIONING_WAIT_ATTEMPT: // We may still not have RTC... Or RTC may come online _during_ this state.
1445+
case PROVISIONING_WAIT_ATTEMPT:
14491446
{
14501447
if (settings.requestKeyUpdate)
1451-
provisioningSetState(PROVISIONING_CHECK_REMAINING);
1448+
provisioningSetState(PROVISIONING_STARTING);
14521449
else if (!settings.enablePointPerfectCorrections || !settings.autoKeyRenewal)
14531450
provisioningSetState(PROVISIONING_OFF);
14541451
// When did we last try to get keys? Attempt every 24 hours - or every 15 mins for DEVELOPER
1455-
//else if (millis() > (provisioningStartTime_millis + ( ENABLE_DEVELOPER ? (1000 * 60 * 15) : (1000 * 60 * 60 * 24))))
1452+
//else if (online.rtc && (rtc.getEpoch() - settings.lastKeyAttempt > ( ENABLE_DEVELOPER ? (15 * 60) : (60 * 60 * 24))))
14561453
// When did we last try to get keys? Attempt every 24 hours
1457-
else if (millis() > (provisioningStartTime_millis + (1000 * 60 * 60 * 24))) // Don't use settings.lastKeyAttempt (#419)
1458-
provisioningSetState(PROVISIONING_CHECK_REMAINING);
1454+
else if (online.rtc && (rtc.getEpoch() - settings.lastKeyAttempt > (60 * 60 * 24)))
1455+
{
1456+
settings.lastKeyAttempt = rtc.getEpoch(); // Mark it
1457+
recordSystemSettings(); // Record these settings to unit
1458+
provisioningSetState(PROVISIONING_STARTING);
1459+
}
14591460
}
14601461
break;
14611462
}

0 commit comments

Comments
 (0)