So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By gdsports
#76235 Each ESP must use a unique MQTT client name. mosquitto disconnects clients with duplicate names. In the current code, "ESP8266Client" is used for all clients.

Code: Select allif (client.connect("ESP8266Client", mqtt_username, mqtt_password)) {


See the latest pubsubclient ESP example which generates a random client name for every connection.

Code: Select all    Serial.print("Attempting MQTT connection...");
    // Create a random client ID
    String clientId = "ESP8266Client-";
    clientId += String(random(0xffff), HEX);
    // Attempt to connect
if (client.connect(clientId.c_str())) {


If the problem persists, turn on verbose debug on the MQTT server to see if and why it is disconnecting clients. Wireshark captures might be helpful.
User avatar
By fritserasmus
#76338
gdsports wrote:Each ESP must use a unique MQTT client name. mosquitto disconnects clients with duplicate names. In the current code, "ESP8266Client" is used for all clients.

Code: Select allif (client.connect("ESP8266Client", mqtt_username, mqtt_password)) {


See the latest pubsubclient ESP example which generates a random client name for every connection.

Code: Select all    Serial.print("Attempting MQTT connection...");
    // Create a random client ID
    String clientId = "ESP8266Client-";
    clientId += String(random(0xffff), HEX);
    // Attempt to connect
if (client.connect(clientId.c_str())) {


If the problem persists, turn on verbose debug on the MQTT server to see if and why it is disconnecting clients. Wireshark captures might be helpful.



Thank you gdsports.
That was exactly what I needed.