Skip to content

Commit fb1eb69

Browse files
committed
Fix wrong client identifier causing some boards to reconnect to MQTT continuously
1 parent c3942fa commit fb1eb69

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

FossaGroundStation/src/Mqtt/MQTT_Client.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
MQTT_Client::MQTT_Client(ConfigManager& x)
2424
: PubSubClient(espClient)
2525
, configManager(x)
26-
{
27-
uint64_t chipId = ESP.getEfuseMac();
28-
clientId = String ((uint32_t)chipId, HEX);
29-
}
26+
{ }
3027

3128
void MQTT_Client::loop() {
3229
if (!connected() && millis() - lastConnectionAtempt > reconnectionInterval) {
@@ -55,14 +52,14 @@ void MQTT_Client::loop() {
5552
}
5653

5754
void MQTT_Client::reconnect() {
58-
if (!connected()) {
59-
uint64_t chipId = ESP.getEfuseMac();
60-
String clientId = String ((uint32_t)chipId, HEX);
61-
}
55+
uint64_t chipId = ESP.getEfuseMac();
56+
char clientId[13];
57+
sprintf(clientId, "%04X%08X",(uint16_t)(chipId>>32), (uint32_t)chipId);
58+
Serial.println(clientId);
6259

6360
Serial.print("Attempting MQTT connection...");
6461
Serial.println ("If this is taking more than expected, connect to the config panel on the ip: " + WiFi.localIP().toString() + " to review the MQTT connection credentials.");
65-
if (connect(clientId.c_str(), configManager.getMqttUser(), configManager.getMqttPass(), buildTopic(topicStatus).c_str(), 2, false, "0")) {
62+
if (connect(clientId, configManager.getMqttUser(), configManager.getMqttPass(), buildTopic(topicStatus).c_str(), 2, false, "0")) {
6663
Serial.println("connected");
6764
subscribeToAll();
6865
sendWelcome();

FossaGroundStation/src/Mqtt/MQTT_Client.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class MQTT_Client : public PubSubClient {
8383
unsigned long lastPing = 0;
8484
unsigned long lastConnectionAtempt = 0;
8585
uint8_t connectionAtempts = 0;
86-
String clientId;
8786

8887
const unsigned long pingInterval = 1 * 60 * 1000;
8988
const unsigned long reconnectionInterval = 5 * 1000;

FossaGroundStation/src/Status.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct PacketInfo {
4242
};
4343

4444
struct Status {
45-
const uint32_t version = 2001080; // version year month day release
45+
const uint32_t version = 2001081; // version year month day release
4646
bool mqtt_connected = false;
4747
SysInfo sysInfo;
4848
PacketInfo lastPacketInfo;

0 commit comments

Comments
 (0)