@@ -64,25 +64,27 @@ String MqttClient::getError() {
6464void MqttClient::loop () {
6565 if (!client.connected ()) {
6666 bool connectstatus;
67+ char client_id[20 ];
68+ // NOTE: the connect client-ID MUST be unique on the MQTT server
69+ // Here we use the ESP Chip ID to make it unique
70+ sprintf_P (client_id, PSTR (" marquee-%08X" ), ESP.getChipId ());
6771 Serial.println (F (" MQTT (Re-)connect" ));
6872 if (strlen (authUser) > 0 ) {
69- connectstatus = client.connect (" marquee " , authUser, authPass);
73+ connectstatus = client.connect (client_id , authUser, authPass);
7074 } else {
71- connectstatus = client.connect (" marquee " );
75+ connectstatus = client.connect (client_id );
7276 }
7377 if (connectstatus) {
7478 failMessage[0 ] = 0 ;
7579 if (!client.subscribe (topic)) {
7680 sprintf_P (failMessage, PSTR (" MQTT Failed to connect to topic: %s" ), topic);
81+ Serial.println (failMessage);
7782 } else {
78- // publish on topic + "/ready" the time to signal MQTT we are there
79- // String pubtopic = topic;
80- // pubtopic += "/ready";
81- // client.publish(pubtopic.c_str(), "ready");
8283 Serial.printf_P (PSTR (" MQTT connected and subscribed to: %s\n " ), topic);
8384 }
8485 } else {
8586 sprintf_P (failMessage, PSTR (" MQTT Failed to connect to: %s:%d, reason: %d" ), server, port, client.state ());
87+ Serial.println (failMessage);
8688 }
8789 }
8890 if (client.connected ()) {
0 commit comments