Skip to content

Commit

Permalink
Updated/fixed unique MQTT Client ID generation
Browse files Browse the repository at this point in the history
  • Loading branch information
epiller committed Dec 3, 2019
1 parent d6f2a76 commit 1557fa4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/ATT_ESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,9 @@ void Device::debugPort(Stream &debugSerial, bool verbose) {

// Generate Unique MQTT ID
void Device::generateRandomID() {
String chipId = "arduino-";
chipId += ESP.getChipId();
sprintf(mqttId, "%s%i", "arduino-", ESP.getChipId());
debugVerbose("Unique MQTT ID of Device:", ' ');
debugVerbose(randValue);
debugVerbose(mqttId);
}

// Initialization of everything. Run in setup(), only after defining everything else.
Expand Down
13 changes: 6 additions & 7 deletions src/ATT_MKR1010.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ void Device::debugPort(Stream &debugSerial, bool verbose) {

}

// Generate Random MQTT ID - If two same IDs are on one broker, the connection drops
// Generate Unique MQTT ID
void Device::generateRandomID() {
randomSeed(analogRead(0));
long randValue = random(2147483647);
snprintf(mqttId, sizeof mqttId, "%s%dl", "arduino-", randValue);
debugVerbose("Generated Unique ID for this Device:", ' ');
debugVerbose("arduino", '-');
debugVerbose(randValue);
byte mac[6];
WiFi.macAddress(mac);
sprintf(mqttId, "arduino-%2X%2X%2X%2X", mac[3], mac[2], mac[1], mac[0]);
debugVerbose("Unique MQTT ID of Device:", ' ');
debugVerbose(mqttId);
}

// Initialization of everything. Run in setup(), only after defining everything else.
Expand Down

0 comments on commit 1557fa4

Please sign in to comment.