Skip to content

Commit

Permalink
change mqtt client id to partial mac
Browse files Browse the repository at this point in the history
  • Loading branch information
softwarecrash committed May 25, 2023
1 parent 00f0dae commit 8223fb5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ unsigned long getDataTimer = 0;
unsigned long RestartTimer = 0;
byte wsReqInvNum = 1;
char mqtt_server[80];
char mqttClientId[80];
int errorcode;

WiFiClient client;
Expand Down Expand Up @@ -188,6 +189,8 @@ void setup()

wm.setSaveConfigCallback(saveConfigCallback);

sprintf(mqttClientId, "%s-%06X", _settings._deviceName.c_str(), ESP.getChipId());

AsyncWiFiManagerParameter custom_mqtt_server("mqtt_server", "MQTT server", NULL, 32);
AsyncWiFiManagerParameter custom_mqtt_user("mqtt_user", "MQTT User", NULL, 32);
AsyncWiFiManagerParameter custom_mqtt_pass("mqtt_pass", "MQTT Password", NULL, 32);
Expand Down Expand Up @@ -659,7 +662,7 @@ bool connectMQTT()
{
if (!mqttclient.connected())
{
if (mqttclient.connect((String(_settings._deviceName)).c_str(), _settings._mqttUser.c_str(), _settings._mqttPassword.c_str(), (topic + "/Alive").c_str(), 0, true, "false", true))
if (mqttclient.connect(mqttClientId, _settings._mqttUser.c_str(), _settings._mqttPassword.c_str(), (topic + "/Alive").c_str(), 0, true, "false", true))
{
mqttclient.publish((topic + String("/IP")).c_str(), String(WiFi.localIP().toString()).c_str());
mqttclient.publish((topic + String("/Alive")).c_str(), "true", true); // LWT online message must be retained!
Expand Down

0 comments on commit 8223fb5

Please sign in to comment.