Skip to content

Commit f096db1

Browse files
committed
Work in progress - needs the ability to wait on Ethernet before attempting provisioning
1 parent 1084f98 commit f096db1

File tree

8 files changed

+2007
-2044
lines changed

8 files changed

+2007
-2044
lines changed

Firmware/RTK_Everywhere/Display.ino

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,6 @@ void displayUpdate()
404404
case (STATE_KEYS_NEEDED):
405405
// Do nothing. Quick, fall through state.
406406
break;
407-
case (STATE_KEYS_WIFI_STARTED):
408-
setWiFiIcon(&iconPropertyList); // Blink WiFi in center
409-
paintGettingKeys();
410-
break;
411-
case (STATE_KEYS_WIFI_CONNECTED):
412-
setWiFiIcon(&iconPropertyList); // Blink WiFi in center
413-
paintGettingKeys();
414-
break;
415-
case (STATE_KEYS_WIFI_TIMEOUT):
416-
// Do nothing. Quick, fall through state.
417-
break;
418407
case (STATE_KEYS_EXPIRED):
419408
// Do nothing. Quick, fall through state.
420409
break;
@@ -431,9 +420,11 @@ void displayUpdate()
431420
setWiFiIcon(&iconPropertyList); // Blink WiFi in center
432421
paintGettingKeys();
433422
break;
434-
case (STATE_KEYS_PROVISION_CONNECTED):
423+
case (STATE_KEYS_PROVISION_SUCCESS):
424+
setWiFiIcon(&iconPropertyList); // Blink WiFi in center
425+
break;
426+
case (STATE_KEYS_PROVISION_FAIL):
435427
setWiFiIcon(&iconPropertyList); // Blink WiFi in center
436-
paintGettingKeys();
437428
break;
438429

439430
case (STATE_ESPNOW_PAIRING_NOT_STARTED):
@@ -2724,12 +2715,12 @@ void paintKeyDaysRemaining(int daysRemaining, uint16_t displayTime)
27242715
}
27252716
}
27262717

2727-
void paintKeyWiFiFail(uint16_t displayTime)
2718+
void paintKeyUpdateFail(uint16_t displayTime)
27282719
{
27292720
// PP
27302721
// Update
27312722
// Failed
2732-
// No WiFi
2723+
// No Network
27332724

27342725
if (online.display == true)
27352726
{
@@ -2749,7 +2740,7 @@ void paintKeyWiFiFail(uint16_t displayTime)
27492740
printTextCenter("Failed", y, QW_FONT_8X16, 1, false); // text, y, font type, kerning, inverted
27502741

27512742
y += fontHeight + 1;
2752-
printTextCenter("No WiFi", y, QW_FONT_5X7, 1, false); // text, y, font type, kerning, inverted
2743+
printTextCenter("No Network", y, QW_FONT_5X7, 1, false); // text, y, font type, kerning, inverted
27532744

27542745
oled->display();
27552746

Firmware/RTK_Everywhere/MQTT_Client.ino

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ enum MQTTClientState
7878
{
7979
MQTT_CLIENT_OFF = 0, // Using Bluetooth or NTRIP server
8080
MQTT_CLIENT_ON, // WIFI_STATE_START state
81+
MQTT_CLIENT_CHECK_CERTS, // Check certs are available - with timeout
8182
MQTT_CLIENT_NETWORK_STARTED, // Connecting to WiFi access point or Ethernet
8283
MQTT_CLIENT_CONNECTING_2_SERVER, // Connecting to the MQTT server
8384
MQTT_CLIENT_SUBSCRIBE_KEY, // Subscribe to the MQTT_TOPIC_KEY
@@ -91,6 +92,7 @@ enum MQTTClientState
9192
const char *const mqttClientStateName[] = {
9293
"MQTT_CLIENT_OFF",
9394
"MQTT_CLIENT_ON",
95+
"MQTT_CLIENT_CHECK_CERTS",
9496
"MQTT_CLIENT_NETWORK_STARTED",
9597
"MQTT_CLIENT_CONNECTING_2_SERVER",
9698
"MQTT_CLIENT_SUBSCRIBE_KEY",
@@ -206,6 +208,7 @@ void mqttClientPrintStateSummary()
206208
break;
207209

208210
case MQTT_CLIENT_ON:
211+
case MQTT_CLIENT_CHECK_CERTS:
209212
case MQTT_CLIENT_NETWORK_STARTED:
210213
systemPrint("Disconnected");
211214
break;
@@ -529,6 +532,20 @@ void mqttClientUpdate()
529532
break;
530533
}
531534

535+
// Check for certs, wait for them to be available
536+
case MQTT_CLIENT_CHECK_CERTS: {
537+
// Determine if the network has failed
538+
if (networkIsShuttingDown(NETWORK_USER_MQTT_CLIENT))
539+
// Failed to connect to the network, attempt to restart the network
540+
mqttClientStop(true); // Was mqttClientRestart(); - #StopVsRestart
541+
542+
// Determine if certs are available
543+
else if (checkCertificates())
544+
// The network is available for the MQTT client
545+
mqttClientSetState(MQTT_CLIENT_NETWORK_STARTED);
546+
break;
547+
}
548+
532549
// Wait for a network media connection
533550
case MQTT_CLIENT_NETWORK_STARTED: {
534551
// Determine if the network has failed

Firmware/RTK_Everywhere/States.ino

Lines changed: 49 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -509,31 +509,29 @@ void stateUpdate()
509509
// We want an immediate change from this state
510510
forceSystemStateUpdate = true; // Immediately go to this new state
511511

512+
uint8_t networkType = networkGetActiveType();
513+
512514
// If user has turned off PointPerfect, skip everything
513515
if (!settings.enablePointPerfectCorrections)
514516
{
515517
changeState(settings.lastState); // Go to either rover or base
516518
}
517519

518-
// If there is no WiFi setup, and no keys, skip everything
519-
else if (wifiNetworkCount() == 0 && strlen(settings.pointPerfectCurrentKey) == 0)
520+
// If on WiFi and there are no WiFi SSIDs available, skip everything
521+
// (Some duplication in pointPerfectProvisionOrUpdate)
522+
else if ((networkType == NETWORK_TYPE_WIFI) && (wifiNetworkCount() == 0))
520523
{
521524
displayNoSSIDs(2000);
522525
changeState(settings.lastState); // Go to either rover or base
523526
}
524527

525-
// If we don't have keys, begin zero touch provisioning
526-
else if (strlen(settings.pointPerfectCurrentKey) == 0 || strlen(settings.pointPerfectNextKey) == 0)
528+
// If we don't have certs or keys, begin zero touch provisioning
529+
else if (!checkCertificates() || strlen(settings.pointPerfectCurrentKey) == 0 || strlen(settings.pointPerfectNextKey) == 0)
527530
{
528531
if (settings.debugPpCertificate)
529-
systemPrintln("PointPerfect Keys starting WiFi");
530-
531-
// Temporarily limit WiFi connection attempts
532-
wifiOriginalMaxConnectionAttempts = wifiMaxConnectionAttempts;
533-
wifiMaxConnectionAttempts = 0; // Override setting during key retrieval. Give up after single failure.
532+
systemPrintln("PointPerfect starting provisioning");
534533

535-
wifiStart();
536-
changeState(STATE_KEYS_PROVISION_STARTED);
534+
changeState(STATE_KEYS_NEEDED);
537535
}
538536

539537
// Determine if we have valid date/time RTC from last boot
@@ -566,17 +564,14 @@ void stateUpdate()
566564
case (STATE_KEYS_NEEDED): {
567565
forceSystemStateUpdate = true; // Immediately go to this new state
568566

567+
uint8_t networkType = networkGetActiveType();
568+
569569
if (online.rtc == false)
570570
{
571571
if (settings.debugPpCertificate)
572-
systemPrintln("Keys Needed. RTC offline. Starting WiFi");
573-
574-
// Temporarily limit WiFi connection attempts
575-
wifiOriginalMaxConnectionAttempts = wifiMaxConnectionAttempts;
576-
wifiMaxConnectionAttempts = 0; // Override setting during key retrieval. Give up after single failure.
572+
systemPrintln("Keys Needed. RTC offline. Starting provisioning or update");
577573

578-
wifiStart();
579-
changeState(STATE_KEYS_WIFI_STARTED); // If we can't check the RTC, continue
574+
changeState(STATE_KEYS_PROVISION_STARTED); // If we can't check the RTC, continue
580575
}
581576

582577
// When did we last try to get keys? Attempt every 24 hours
@@ -586,19 +581,14 @@ void stateUpdate()
586581
recordSystemSettings(); // Record these settings to unit
587582

588583
if (settings.debugPpCertificate)
589-
systemPrintln("Keys Needed. Starting WiFi");
584+
systemPrintln("Keys Needed. Starting provisioning or update");
590585

591-
// Temporarily limit WiFi connection attempts
592-
wifiOriginalMaxConnectionAttempts = wifiMaxConnectionAttempts;
593-
wifiMaxConnectionAttempts = 0; // Override setting during key retrieval. Give up after single failure.
594-
595-
wifiStart(); // Starts WiFi state machine
596-
changeState(STATE_KEYS_WIFI_STARTED);
586+
changeState(STATE_KEYS_PROVISION_STARTED);
597587
}
598588

599589
// Added to display error if user selects GetKeys from the display
600590
// Normally, this would be caught during STATE_KEYS_STARTED
601-
else if (wifiNetworkCount() == 0)
591+
else if ((networkType == NETWORK_TYPE_WIFI) && (wifiNetworkCount() == 0))
602592
{
603593
displayNoSSIDs(1000);
604594
changeState(
@@ -614,13 +604,7 @@ void stateUpdate()
614604
if (settings.debugPpCertificate)
615605
systemPrintln("Force key update. Starting WiFi");
616606

617-
// Temporarily limit WiFi connection attempts
618-
wifiOriginalMaxConnectionAttempts = wifiMaxConnectionAttempts;
619-
wifiMaxConnectionAttempts = 0; // Override setting during key retrieval. Give up after single failure.
620-
621-
wifiStart(); // Starts WiFi state machine
622-
623-
changeState(STATE_KEYS_WIFI_STARTED);
607+
changeState(STATE_KEYS_PROVISION_STARTED);
624608
}
625609

626610
else
@@ -634,75 +618,6 @@ void stateUpdate()
634618
}
635619
break;
636620

637-
case (STATE_KEYS_WIFI_STARTED): {
638-
wifiMaxConnectionAttempts = wifiOriginalMaxConnectionAttempts; // Revert setting
639-
640-
if (wifiIsConnected())
641-
changeState(STATE_KEYS_WIFI_CONNECTED);
642-
else
643-
{
644-
wifiShutdown(); // Turn off WiFi
645-
646-
changeState(STATE_KEYS_WIFI_TIMEOUT);
647-
}
648-
}
649-
break;
650-
651-
case (STATE_KEYS_WIFI_CONNECTED): {
652-
653-
// Check that the certs are valid
654-
if (checkCertificates() == true)
655-
{
656-
// Update the keys
657-
if (pointperfectUpdateKeys() == true) // Connect to ThingStream MQTT and get PointPerfect key UBX packet
658-
displayKeysUpdated();
659-
}
660-
else
661-
{
662-
// Erase keys
663-
erasePointperfectCredentials();
664-
665-
// Provision device
666-
if (pointperfectProvisionDevice() == true) // Connect to ThingStream API and get keys
667-
displayKeysUpdated();
668-
}
669-
670-
wifiShutdown(); // Turn off WiFi
671-
forceSystemStateUpdate = true; // Imediately go to this new state
672-
changeState(STATE_KEYS_DAYS_REMAINING);
673-
}
674-
break;
675-
676-
case (STATE_KEYS_WIFI_TIMEOUT): {
677-
paintKeyWiFiFail(2000);
678-
679-
forceSystemStateUpdate = true; // Imediately go to this new state
680-
681-
if (online.rtc == true)
682-
{
683-
int daysRemaining =
684-
daysFromEpoch(settings.pointPerfectNextKeyStart + settings.pointPerfectNextKeyDuration + 1);
685-
686-
if (daysRemaining >= 0)
687-
{
688-
changeState(STATE_KEYS_DAYS_REMAINING);
689-
}
690-
else
691-
{
692-
paintKeysExpired();
693-
changeState(STATE_KEYS_LBAND_ENCRYPTED);
694-
}
695-
}
696-
else
697-
{
698-
// No WiFi. No RTC. We don't know if the keys we have are expired. Attempt to use them.
699-
changeState(STATE_KEYS_LBAND_CONFIGURE);
700-
}
701-
}
702-
break;
703-
704-
// Note: STATE_KEYS_EXPIRED should be here, but isn't. TODO: check this
705-
706621
case (STATE_KEYS_DAYS_REMAINING): {
707622
if (online.rtc == true)
708623
{
@@ -749,30 +664,44 @@ void stateUpdate()
749664
break;
750665

751666
case (STATE_KEYS_PROVISION_STARTED): {
752-
if (wifiIsConnected())
753-
changeState(STATE_KEYS_PROVISION_CONNECTED);
667+
if (pointPerfectProvisionOrUpdate(false))
668+
changeState(STATE_KEYS_PROVISION_SUCCESS);
754669
else
755-
{
756-
wifiShutdown(); // Turn off WiFi
757-
changeState(STATE_KEYS_WIFI_TIMEOUT);
758-
}
670+
changeState(STATE_KEYS_PROVISION_FAIL);
759671
}
760672
break;
761673

762-
case (STATE_KEYS_PROVISION_CONNECTED): {
674+
case (STATE_KEYS_PROVISION_SUCCESS): {
763675
forceSystemStateUpdate = true; // Imediately go to this new state
764676

765-
if (pointperfectProvisionDevice() == true)
677+
//displayKeysUpdated();
678+
changeState(STATE_KEYS_DAYS_REMAINING);
679+
}
680+
break;
681+
682+
case (STATE_KEYS_PROVISION_FAIL): {
683+
forceSystemStateUpdate = true; // Imediately go to this new state
684+
685+
if (online.rtc == true)
766686
{
767-
displayKeysUpdated();
768-
changeState(STATE_KEYS_DAYS_REMAINING);
687+
int daysRemaining =
688+
daysFromEpoch(settings.pointPerfectNextKeyStart + settings.pointPerfectNextKeyDuration + 1);
689+
690+
if (daysRemaining >= 0)
691+
{
692+
changeState(STATE_KEYS_DAYS_REMAINING);
693+
}
694+
else
695+
{
696+
paintKeysExpired();
697+
changeState(STATE_KEYS_LBAND_ENCRYPTED);
698+
}
769699
}
770700
else
771701
{
772-
paintKeyProvisionFail(10000); // Device not whitelisted. Show device ID.
773-
changeState(STATE_KEYS_LBAND_ENCRYPTED);
702+
// No RTC. We don't know if the keys we have are expired. Attempt to use them.
703+
changeState(STATE_KEYS_LBAND_CONFIGURE);
774704
}
775-
wifiShutdown(); // Turn off WiFi
776705
}
777706
break;
778707

@@ -1038,12 +967,6 @@ const char *getState(SystemState state, char *buffer)
1038967
return "STATE_KEYS_STARTED";
1039968
case (STATE_KEYS_NEEDED):
1040969
return "STATE_KEYS_NEEDED";
1041-
case (STATE_KEYS_WIFI_STARTED):
1042-
return "STATE_KEYS_WIFI_STARTED";
1043-
case (STATE_KEYS_WIFI_CONNECTED):
1044-
return "STATE_KEYS_WIFI_CONNECTED";
1045-
case (STATE_KEYS_WIFI_TIMEOUT):
1046-
return "STATE_KEYS_WIFI_TIMEOUT";
1047970
case (STATE_KEYS_EXPIRED):
1048971
return "STATE_KEYS_EXPIRED";
1049972
case (STATE_KEYS_DAYS_REMAINING):
@@ -1054,8 +977,10 @@ const char *getState(SystemState state, char *buffer)
1054977
return "STATE_KEYS_LBAND_ENCRYPTED";
1055978
case (STATE_KEYS_PROVISION_STARTED):
1056979
return "STATE_KEYS_PROVISION_STARTED";
1057-
case (STATE_KEYS_PROVISION_CONNECTED):
1058-
return "STATE_KEYS_PROVISION_CONNECTED";
980+
case (STATE_KEYS_PROVISION_SUCCESS):
981+
return "STATE_KEYS_PROVISION_SUCCESS";
982+
case (STATE_KEYS_PROVISION_FAIL):
983+
return "STATE_KEYS_PROVISION_FAIL";
1059984
#endif // COMPILE_L_BAND
1060985

1061986
case (STATE_ESPNOW_PAIRING_NOT_STARTED):
@@ -1155,7 +1080,7 @@ const RTK_MODE_ENTRY stateModeTable[] = {
11551080
{"Rover", STATE_ROVER_NOT_STARTED, STATE_ROVER_RTK_FIX},
11561081
{"Base", STATE_BASE_NOT_STARTED, STATE_BASE_FIXED_TRANSMITTING},
11571082
{"Setup", STATE_DISPLAY_SETUP, STATE_PROFILE},
1158-
{"Key Provisioning", STATE_KEYS_STARTED, STATE_KEYS_PROVISION_CONNECTED},
1083+
{"Key Provisioning", STATE_KEYS_STARTED, STATE_KEYS_PROVISION_FAIL},
11591084
{"ESPNOW Pairing", STATE_ESPNOW_PAIRING_NOT_STARTED, STATE_ESPNOW_PAIRING},
11601085
{"NTP", STATE_NTPSERVER_NOT_STARTED, STATE_NTPSERVER_SYNC},
11611086
{"Ethernet Config", STATE_CONFIG_VIA_ETH_NOT_STARTED, STATE_CONFIG_VIA_ETH_RESTART_BASE},

Firmware/RTK_Everywhere/Tasks.ino

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,15 +1568,13 @@ void buttonCheckTask(void *e)
15681568
/* These lines are commented to allow default to print the diagnostic.
15691569
case STATE_KEYS_STARTED:
15701570
case STATE_KEYS_NEEDED:
1571-
case STATE_KEYS_WIFI_STARTED:
1572-
case STATE_KEYS_WIFI_CONNECTED:
1573-
case STATE_KEYS_WIFI_TIMEOUT:
15741571
case STATE_KEYS_EXPIRED:
15751572
case STATE_KEYS_DAYS_REMAINING:
15761573
case STATE_KEYS_LBAND_CONFIGURE:
15771574
case STATE_KEYS_LBAND_ENCRYPTED:
15781575
case STATE_KEYS_PROVISION_STARTED:
1579-
case STATE_KEYS_PROVISION_CONNECTED:
1576+
case STATE_KEYS_PROVISION_SUCCESS:
1577+
case STATE_KEYS_PROVISION_FAIL:
15801578
// Abort key download?
15811579
// TODO: check this! I think we want to be able to terminate STATE_KEYS via the button?
15821580
break;

Firmware/RTK_Everywhere/WiFi.ino

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,7 @@ bool wifiIsNeeded()
631631
return true;
632632
}
633633

634-
if (systemState == STATE_KEYS_WIFI_STARTED || systemState == STATE_KEYS_WIFI_CONNECTED)
635-
return true;
636-
if (systemState == STATE_KEYS_PROVISION_STARTED || systemState == STATE_KEYS_PROVISION_CONNECTED)
634+
if (systemState == STATE_KEYS_PROVISION_STARTED)
637635
return true;
638636

639637
return false;

0 commit comments

Comments
 (0)