Skip to content

Commit 1557fa4

Browse files
committed
Updated/fixed unique MQTT Client ID generation
1 parent d6f2a76 commit 1557fa4

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/ATT_ESP8266.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,9 @@ void Device::debugPort(Stream &debugSerial, bool verbose) {
150150

151151
// Generate Unique MQTT ID
152152
void Device::generateRandomID() {
153-
String chipId = "arduino-";
154-
chipId += ESP.getChipId();
153+
sprintf(mqttId, "%s%i", "arduino-", ESP.getChipId());
155154
debugVerbose("Unique MQTT ID of Device:", ' ');
156-
debugVerbose(randValue);
155+
debugVerbose(mqttId);
157156
}
158157

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

src/ATT_MKR1010.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,13 @@ void Device::debugPort(Stream &debugSerial, bool verbose) {
201201

202202
}
203203

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

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

0 commit comments

Comments
 (0)