@@ -1209,8 +1209,8 @@ void provisioningSetState(uint8_t newState)
1209
1209
}
1210
1210
}
1211
1211
1212
- unsigned long provisioningStartTime_millis ;
1213
- const unsigned long provisioningTimeout_ms = 120000 ;
1212
+ unsigned long provisioningStartTime ;
1213
+ const unsigned long provisioningTimeout = 120000 ;
1214
1214
1215
1215
void updateProvisioning ()
1216
1216
{
@@ -1229,15 +1229,14 @@ void updateProvisioning()
1229
1229
default :
1230
1230
case PROVISIONING_OFF:
1231
1231
{
1232
- provisioningStartTime_millis = millis (); // Record the start time so we can timeout
1232
+ provisioningStartTime = millis (); // Record the start time so we can timeout
1233
1233
provisioningSetState (PROVISIONING_WAIT_RTC);
1234
1234
}
1235
1235
break ;
1236
1236
case PROVISIONING_WAIT_RTC:
1237
1237
{
1238
1238
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))
1241
1240
|| (settings.requestKeyUpdate ))
1242
1241
provisioningSetState (PROVISIONING_NOT_STARTED);
1243
1242
}
@@ -1259,7 +1258,6 @@ void updateProvisioning()
1259
1258
systemPrintln (" Invalid certificates or keys. Starting provisioning" );
1260
1259
provisioningSetState (PROVISIONING_CHECK_NETWORK);
1261
1260
}
1262
- // If RTC is not online, we have to skip PROVISIONING_CHECK_ATTEMPT
1263
1261
else if (!online.rtc )
1264
1262
{
1265
1263
if (settings.debugPpCertificate )
@@ -1268,21 +1266,21 @@ void updateProvisioning()
1268
1266
}
1269
1267
else
1270
1268
{
1271
- // RTC is online. Determine days until next key expires
1269
+ // Determine days until next key expires
1272
1270
int daysRemaining =
1273
1271
daysFromEpoch (settings.pointPerfectNextKeyStart + settings.pointPerfectNextKeyDuration + 1 );
1274
1272
1275
1273
if (settings.debugPpCertificate )
1276
1274
systemPrintf (" Days until keys expire: %d\r\n " , daysRemaining);
1277
1275
1278
1276
if (daysRemaining > 28 )
1279
- provisioningSetState (PROVISIONING_KEYS_REMAINING); // Don't need new keys
1277
+ provisioningSetState (PROVISIONING_KEYS_REMAINING);
1280
1278
else
1281
- provisioningSetState (PROVISIONING_CHECK_ATTEMPT); // Do need new keys
1279
+ provisioningSetState (PROVISIONING_CHECK_ATTEMPT);
1282
1280
}
1283
1281
}
1284
1282
break ;
1285
- case PROVISIONING_CHECK_ATTEMPT: // Requires RTC to be online
1283
+ case PROVISIONING_CHECK_ATTEMPT:
1286
1284
{
1287
1285
// When did we last try to get keys? Attempt every 24 hours - or always for DEVELOPER
1288
1286
// if (rtc.getEpoch() - settings.lastKeyAttempt > ( ENABLE_DEVELOPER ? 0 : (60 * 60 * 24)))
@@ -1319,22 +1317,22 @@ void updateProvisioning()
1319
1317
recordSystemSettings (); // Record these settings to unit
1320
1318
ztpResponse = ZTP_NOT_STARTED; // HTTP_Client will update this
1321
1319
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
1323
1321
paintGettingKeys ();
1324
1322
provisioningSetState (PROVISIONING_STARTED);
1325
1323
}
1326
1324
case PROVISIONING_STARTED:
1327
1325
{
1328
- if (millis () > (provisioningStartTime_millis + provisioningTimeout_ms ))
1326
+ if (millis () > (provisioningStartTime + provisioningTimeout ))
1329
1327
{
1330
1328
httpClientModeNeeded = false ; // Tell HTTP_Client to give up. (But it probably already has...)
1331
1329
paintKeyUpdateFail (5000 );
1332
1330
provisioningSetState (PROVISIONING_KEYS_REMAINING);
1333
1331
}
1334
1332
else if (ztpResponse == ZTP_SUCCESS)
1335
1333
{
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 ();
1338
1336
provisioningSetState (PROVISIONING_KEYS_REMAINING);
1339
1337
}
1340
1338
else if (ztpResponse == ZTP_DEACTIVATED)
@@ -1358,7 +1356,7 @@ void updateProvisioning()
1358
1356
" subscription. Please reference device ID: %s\r\n " ,
1359
1357
landingPageUrl, hardwareID);
1360
1358
1361
- httpClientModeNeeded = false ; // Tell HTTP_Client to give up
1359
+ httpClientModeNeeded = false ; // Tell HTTP_Client to give up. (But it probably already has...)
1362
1360
displayAccountExpired (5000 );
1363
1361
1364
1362
provisioningSetState (PROVISIONING_KEYS_REMAINING);
@@ -1384,7 +1382,7 @@ void updateProvisioning()
1384
1382
" activated. Please reference device ID: %s\r\n " ,
1385
1383
landingPageUrl, hardwareID);
1386
1384
1387
- httpClientModeNeeded = false ; // Tell HTTP_Client to give up
1385
+ httpClientModeNeeded = false ; // Tell HTTP_Client to give up. (But it probably already has...)
1388
1386
displayNotListed (5000 );
1389
1387
1390
1388
provisioningSetState (PROVISIONING_KEYS_REMAINING);
@@ -1400,7 +1398,7 @@ void updateProvisioning()
1400
1398
" [email protected] for more assistance. Please reference device ID: %s\r\n " ,
1401
1399
hardwareID);
1402
1400
1403
- httpClientModeNeeded = false ; // Tell HTTP_Client to give up
1401
+ httpClientModeNeeded = false ; // Tell HTTP_Client to give up. (But it probably already has...)
1404
1402
displayAlreadyRegistered (5000 );
1405
1403
1406
1404
provisioningSetState (PROVISIONING_KEYS_REMAINING);
@@ -1409,7 +1407,7 @@ void updateProvisioning()
1409
1407
{
1410
1408
systemPrintln (" updateProvisioning: ZTP_UNKNOWN_ERROR" );
1411
1409
1412
- httpClientModeNeeded = false ; // Tell HTTP_Client to give up
1410
+ httpClientModeNeeded = false ; // Tell HTTP_Client to give up. (But it probably already has...)
1413
1411
1414
1412
provisioningSetState (PROVISIONING_KEYS_REMAINING);
1415
1413
}
@@ -1441,21 +1439,24 @@ void updateProvisioning()
1441
1439
1442
1440
gnssApplyPointPerfectKeys (); // Send current keys, if available, to GNSS
1443
1441
1444
- provisioningStartTime_millis = millis (); // Record the time so we can restart after 24 hours
1445
1442
provisioningSetState (PROVISIONING_WAIT_ATTEMPT);
1446
1443
}
1447
1444
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:
1449
1446
{
1450
1447
if (settings.requestKeyUpdate )
1451
- provisioningSetState (PROVISIONING_CHECK_REMAINING );
1448
+ provisioningSetState (PROVISIONING_STARTING );
1452
1449
else if (!settings.enablePointPerfectCorrections || !settings.autoKeyRenewal )
1453
1450
provisioningSetState (PROVISIONING_OFF);
1454
1451
// 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))))
1456
1453
// 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
+ }
1459
1460
}
1460
1461
break ;
1461
1462
}
0 commit comments