@@ -317,8 +317,27 @@ bool pointperfectProvisionDevice()
317317
318318 if (httpResponseCode != 200 )
319319 {
320- systemPrintf (" HTTP response error %d: " , httpResponseCode);
321- systemPrintln (response);
320+ // If a device has been deactivated, response will be: "HTTP response error 403: No plan for device
321+ // device:9f49e97f-e6a7-4a08-8d58-ac7ecdc90e23"
322+ if (response.indexOf (" No plan for device" ) >= 0 )
323+ {
324+ char hardwareID[13 ];
325+ snprintf (hardwareID, sizeof (hardwareID), " %02X%02X%02X%02X%02X%02X" , lbandMACAddress[0 ],
326+ lbandMACAddress[1 ], lbandMACAddress[2 ], lbandMACAddress[3 ], lbandMACAddress[4 ],
327+ lbandMACAddress[5 ]);
328+
329+ systemPrintf (" This device's L-Band subscription has lapsed or is not white-listed. Please contact "
330+ " support@sparkfun.com to renew the L-Band "
331+ " subscription. Please reference device ID: %s\r\n " ,
332+ hardwareID);
333+
334+ displayAccountExpired (5000 );
335+ }
336+ else
337+ {
338+ systemPrintf (" HTTP response error %d: " , httpResponseCode);
339+ systemPrintln (response);
340+ }
322341 break ;
323342 }
324343 else
@@ -466,7 +485,8 @@ bool checkCertificates()
466485 if (keyContents)
467486 free (keyContents);
468487
469- systemPrintln (" Stored certificates are valid!" );
488+ if (settings.debugPpCertificate )
489+ systemPrintln (" Stored certificates are valid!" );
470490 return (validCertificates);
471491}
472492
@@ -576,47 +596,34 @@ bool pointperfectUpdateKeys()
576596 mqttClient.setCallback (mqttCallback);
577597 mqttClient.setServer (settings.pointPerfectBrokerHost , 8883 );
578598
579- if (settings.debugLBand == true )
580- systemPrintf (" Connecting to MQTT broker: %s\r\n " , settings.pointPerfectBrokerHost );
599+ systemPrintf (" Attempting to connect to MQTT broker: %s\r\n " , settings.pointPerfectBrokerHost );
581600
582- // Loop until we're connected or until the maximum retries are exceeded
583- mqttMessageReceived = false ;
584- int maxTries = 3 ;
585- do
601+ if (mqttClient.connect (settings.pointPerfectClientID ))
586602 {
587- systemPrint (" MQTT connecting..." );
588-
589- // Attempt to the key broker
590- if (mqttClient.connect (settings.pointPerfectClientID ))
591- {
592- // Successful connection
593- systemPrintln (" connected" );
603+ // Successful connection
604+ systemPrintln (" MQTT connected" );
594605
595- // Originally the provisioning process reported the '/pp/key/Lb' channel which fails to respond with
596- // keys. Looks like they fixed it to /pp/ubx/0236/Lb.
597- mqttClient.subscribe (settings.pointPerfectLBandTopic );
598- break ;
599- }
600-
601- // Retry the connection attempt
602- if (--maxTries)
603- {
604- systemPrint (" ." );
605- if (settings.debugLBand == true )
606- systemPrintf (" failed, status code: %d try again in 1 second\r\n " , mqttClient.state ());
607- delay (1000 );
608- }
609- } while (maxTries);
606+ // Originally the provisioning process reported the '/pp/key/Lb' channel which fails to respond with
607+ // keys. Looks like they fixed it to /pp/ubx/0236/Lb.
608+ mqttClient.subscribe (settings.pointPerfectLBandTopic );
609+ break ;
610+ }
610611
611612 // Check for connection failure
612613 if (mqttClient.connected () == false )
613614 {
614- systemPrintln (" failed!" );
615+ systemPrintln (" Failed to connect to MQTT Broker" );
616+
617+ // MQTT does not provide good error reporting.
618+ // Throw out everything and attempt to provision the device to get better error checking.
619+ pointperfectProvisionDevice ();
615620 break ;
616621 }
617622
618623 systemPrint (" Waiting for keys" );
619624
625+ mqttMessageReceived = false ;
626+
620627 // Wait for callback
621628 startTime = millis ();
622629 while (1 )
0 commit comments