@@ -22,6 +22,7 @@ static const uint8_t ppLbandIpToken[16] = {POINTPERFECT_LBAND_IP_TOKEN}; // Toke
2222
2323#ifdef COMPILE_NETWORK
2424MqttClient *menuppMqttClient;
25+ static NetPriority_t pointperfectPriority = NETWORK_OFFLINE;
2526#endif // COMPILE_NETWORK
2627
2728// ----------------------------------------
@@ -891,7 +892,6 @@ void beginLBand()
891892#endif // /COMPILE_MOSAICX5
892893}
893894
894- // Set 'home' WiFi credentials
895895// Provision device on ThingStream
896896// Download keys
897897void menuPointPerfect ()
@@ -1177,7 +1177,7 @@ enum ProvisioningStates
11771177 PROVISIONING_NOT_STARTED,
11781178 PROVISIONING_CHECK_REMAINING,
11791179 PROVISIONING_CHECK_ATTEMPT,
1180- PROVISIONING_CHECK_NETWORK ,
1180+ PROVISIONING_WAIT_FOR_NETWORK ,
11811181 PROVISIONING_STARTING,
11821182 PROVISIONING_STARTED,
11831183 PROVISIONING_KEYS_REMAINING,
@@ -1191,7 +1191,7 @@ const char *const provisioningStateName[] = {"PROVISIONING_OFF",
11911191 " PROVISIONING_NOT_STARTED" ,
11921192 " PROVISIONING_CHECK_REMAINING" ,
11931193 " PROVISIONING_CHECK_ATTEMPT" ,
1194- " PROVISIONING_CHECK_NETWORK " ,
1194+ " PROVISIONING_WAIT_FOR_NETWORK " ,
11951195 " PROVISIONING_STARTING" ,
11961196 " PROVISIONING_STARTED" ,
11971197 " PROVISIONING_KEYS_REMAINING" ,
@@ -1273,21 +1273,21 @@ void updateProvisioning()
12731273 {
12741274 if (settings.debugPpCertificate )
12751275 systemPrintln (" Invalid certificates or keys. Starting provisioning" );
1276- provisioningSetState (PROVISIONING_CHECK_NETWORK );
1276+ provisioningSetState (PROVISIONING_WAIT_FOR_NETWORK );
12771277 }
12781278 // If requestKeyUpdate is true, begin provisioning
12791279 else if (settings.requestKeyUpdate )
12801280 {
12811281 if (settings.debugPpCertificate )
12821282 systemPrintln (" requestKeyUpdate is true. Starting provisioning" );
1283- provisioningSetState (PROVISIONING_CHECK_NETWORK );
1283+ provisioningSetState (PROVISIONING_WAIT_FOR_NETWORK );
12841284 }
12851285 // If RTC is not online, we have to skip PROVISIONING_CHECK_ATTEMPT
12861286 else if (!online.rtc )
12871287 {
12881288 if (settings.debugPpCertificate )
12891289 systemPrintln (" No RTC. Starting provisioning" );
1290- provisioningSetState (PROVISIONING_CHECK_NETWORK );
1290+ provisioningSetState (PROVISIONING_WAIT_FOR_NETWORK );
12911291 }
12921292 else
12931293 {
@@ -1313,7 +1313,7 @@ void updateProvisioning()
13131313 {
13141314 settings.lastKeyAttempt = rtc.getEpoch (); // Mark it
13151315 recordSystemSettings (); // Record these settings to unit
1316- provisioningSetState (PROVISIONING_CHECK_NETWORK );
1316+ provisioningSetState (PROVISIONING_WAIT_FOR_NETWORK );
13171317 }
13181318 else
13191319 {
@@ -1323,19 +1323,29 @@ void updateProvisioning()
13231323 }
13241324 }
13251325 break ;
1326- case PROVISIONING_CHECK_NETWORK: {
1327- if (!networkIsOnline ())
1326+
1327+ // Wait for connection to the network
1328+ case PROVISIONING_WAIT_FOR_NETWORK: {
1329+ // Determine if the key update request has been canceled while waiting
1330+ if (settings.requestKeyUpdate == false )
13281331 {
1329- if (wifiNetworkCount () == 0 )
1330- displayNoSSIDs (2000 );
1331- else
1332- displayNoNetwork (2000 );
1333- provisioningSetState (PROVISIONING_KEYS_REMAINING);
1332+ provisioningSetState (PROVISIONING_NOT_STARTED);
13341333 }
1335- else
1334+ // Wait until the network is available
1335+ else if (networkIsConnected (&pointperfectPriority))
1336+ {
1337+ if (settings.debugPpCertificate )
1338+ systemPrintln (" PointPerfect key update connected to network" );
1339+
1340+ // Go get latest keys
13361341 provisioningSetState (PROVISIONING_STARTING);
1342+ }
1343+ // TODO If we just booted, show keys remaining regardless of provisioning state machine
1344+ // provisioningSetState(PROVISIONING_KEYS_REMAINING);
13371345 }
1346+
13381347 break ;
1348+
13391349 case PROVISIONING_STARTING: {
13401350 ztpResponse = ZTP_NOT_STARTED; // HTTP_Client will update this
13411351 httpClientModeNeeded = true ; // This will start the HTTP_Client
0 commit comments