Skip to content

Commit

Permalink
Fix wrong client identifier causing some boards to reconnect to MQTT …
Browse files Browse the repository at this point in the history
…continuously
  • Loading branch information
4m1g0 committed Jan 9, 2020
1 parent c3942fa commit fb1eb69
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
15 changes: 6 additions & 9 deletions FossaGroundStation/src/Mqtt/MQTT_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
MQTT_Client::MQTT_Client(ConfigManager& x)
: PubSubClient(espClient)
, configManager(x)
{
uint64_t chipId = ESP.getEfuseMac();
clientId = String ((uint32_t)chipId, HEX);
}
{ }

void MQTT_Client::loop() {
if (!connected() && millis() - lastConnectionAtempt > reconnectionInterval) {
Expand Down Expand Up @@ -55,14 +52,14 @@ void MQTT_Client::loop() {
}

void MQTT_Client::reconnect() {
if (!connected()) {
uint64_t chipId = ESP.getEfuseMac();
String clientId = String ((uint32_t)chipId, HEX);
}
uint64_t chipId = ESP.getEfuseMac();
char clientId[13];
sprintf(clientId, "%04X%08X",(uint16_t)(chipId>>32), (uint32_t)chipId);
Serial.println(clientId);

Serial.print("Attempting MQTT connection...");
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.");
if (connect(clientId.c_str(), configManager.getMqttUser(), configManager.getMqttPass(), buildTopic(topicStatus).c_str(), 2, false, "0")) {
if (connect(clientId, configManager.getMqttUser(), configManager.getMqttPass(), buildTopic(topicStatus).c_str(), 2, false, "0")) {
Serial.println("connected");
subscribeToAll();
sendWelcome();
Expand Down
1 change: 0 additions & 1 deletion FossaGroundStation/src/Mqtt/MQTT_Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class MQTT_Client : public PubSubClient {
unsigned long lastPing = 0;
unsigned long lastConnectionAtempt = 0;
uint8_t connectionAtempts = 0;
String clientId;

const unsigned long pingInterval = 1 * 60 * 1000;
const unsigned long reconnectionInterval = 5 * 1000;
Expand Down
2 changes: 1 addition & 1 deletion FossaGroundStation/src/Status.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct PacketInfo {
};

struct Status {
const uint32_t version = 2001080; // version year month day release
const uint32_t version = 2001081; // version year month day release
bool mqtt_connected = false;
SysInfo sysInfo;
PacketInfo lastPacketInfo;
Expand Down

0 comments on commit fb1eb69

Please sign in to comment.