Skip to content

Commit 3704b8a

Browse files
committed
MQTT_Client changes:
Call mqttClientRestart if the certificate or private key are not available (i.e. ZTP has not yet taken place). mqttClientShutdown causes an immediate retry with no timeout. Replace mqttClientStop with MQTT_CLIENT_STOP to allow the source of the stop to be traced.
1 parent 29605c2 commit 3704b8a

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

Firmware/RTK_Everywhere/MQTT_Client.ino

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ bool mqttClientConnectLimitReached()
169169
networkRestart(NETWORK_USER_MQTT_CLIENT);
170170

171171
// Restart the MQTT client
172-
mqttClientStop(limitReached || (!enableMqttClient));
172+
MQTT_CLIENT_STOP(limitReached || (!enableMqttClient));
173173

174174
mqttClientConnectionAttempts++;
175175
mqttClientConnectionAttemptsTotal++;
@@ -475,7 +475,7 @@ void mqttClientSetState(uint8_t newState)
475475
// Shutdown the MQTT client
476476
void mqttClientShutdown()
477477
{
478-
mqttClientStop(true);
478+
MQTT_CLIENT_STOP(true);
479479
}
480480

481481
// Start the MQTT client
@@ -489,7 +489,7 @@ void mqttClientStart()
489489
// Start the MQTT client
490490
systemPrintln("MQTT Client start");
491491
}
492-
mqttClientStop(false);
492+
MQTT_CLIENT_STOP(false);
493493
}
494494

495495
// Shutdown or restart the MQTT client
@@ -582,7 +582,7 @@ void mqttClientUpdate()
582582
if (mqttClientState > MQTT_CLIENT_OFF)
583583
{
584584
systemPrintln("MQTT Client stopping");
585-
mqttClientStop(true); // Was false - #StopVsRestart
585+
MQTT_CLIENT_STOP(true); // Was false - #StopVsRestart
586586
mqttClientConnectionAttempts = 0;
587587
mqttClientConnectionAttemptTimeout = 0;
588588
mqttClientSetState(MQTT_CLIENT_OFF);
@@ -686,7 +686,9 @@ void mqttClientUpdate()
686686
memset(mqttClientCertificateBuffer, 0, MQTT_CERT_SIZE);
687687
if (!loadFile("certificate", mqttClientCertificateBuffer, settings.debugMqttClientState))
688688
{
689-
mqttClientShutdown();
689+
if (settings.debugMqttClientState)
690+
systemPrintln("MQTT_CLIENT_CONNECTING_2_SERVER no certificate available");
691+
mqttClientRestart(); // This does need a restart. Was mqttClientShutdown, but that causes an immediate retry with no timeout
690692
break;
691693
}
692694
mqttSecureClient->setCertificate(mqttClientCertificateBuffer);
@@ -695,7 +697,9 @@ void mqttClientUpdate()
695697
memset(mqttClientPrivateKeyBuffer, 0, MQTT_CERT_SIZE);
696698
if (!loadFile("privateKey", mqttClientPrivateKeyBuffer, settings.debugMqttClientState))
697699
{
698-
mqttClientShutdown();
700+
if (settings.debugMqttClientState)
701+
systemPrintln("MQTT_CLIENT_CONNECTING_2_SERVER no private key available");
702+
mqttClientRestart(); // This does need a restart. Was mqttClientShutdown, but that causes an immediate retry with no timeout
699703
break;
700704
}
701705
mqttSecureClient->setPrivateKey(mqttClientPrivateKeyBuffer);
@@ -747,7 +751,7 @@ void mqttClientUpdate()
747751
{
748752
mqttClientRestart();
749753
systemPrintln("ERROR: Subscription to key distribution topic failed!!");
750-
mqttClientRestart(); // Why twice? TODO
754+
//mqttClientRestart(); // Why twice? TODO
751755
break;
752756
}
753757

@@ -775,7 +779,7 @@ void mqttClientUpdate()
775779
{
776780
mqttClientRestart();
777781
systemPrintln("ERROR: Subscription to corrections topic failed!!");
778-
mqttClientRestart(); // Why twice? TODO
782+
//mqttClientRestart(); // Why twice? TODO
779783
break;
780784
}
781785

Firmware/RTK_Everywhere/Network.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ void networkStop(uint8_t networkType)
933933
case NETWORK_USER_MQTT_CLIENT:
934934
if (settings.debugNetworkLayer)
935935
systemPrintln("Network layer stopping MQTT client");
936-
mqttClientStop(true); // Was mqttClientRestart(); - #StopVsRestart
936+
MQTT_CLIENT_STOP(true); // Was mqttClientRestart(); - #StopVsRestart
937937
break;
938938

939939
case NETWORK_USER_NTP_SERVER:

Firmware/RTK_Everywhere/RTK_Everywhere.ino

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,13 @@ char logFileName[sizeof("SFE_Reference_Station_230101_120101.ubx_plusExtraSpace"
286286
}
287287
#endif // COMPILE_WIFI
288288

289+
#define MQTT_CLIENT_STOP(shutdown) \
290+
{ \
291+
if (settings.debugNetworkLayer || settings.debugMqttClientState) \
292+
systemPrintf("mqttClientStop(%s) called by %s %d\r\n", shutdown ? "true" : "false", __FILE__, __LINE__); \
293+
mqttClientStop(shutdown); \
294+
}
295+
289296
#define OTA_FIRMWARE_JSON_URL_LENGTH 128
290297
// 1 1 1
291298
// 1 2 3 4 5 6 7 8 9 0 1 2

0 commit comments

Comments
 (0)