knolleary / pubsubclient

A client library for the Arduino Ethernet Shield that provides support for MQTT.
http://pubsubclient.knolleary.net/
MIT License
3.82k stars 1.47k forks source link

Cannot connect after Mosquitto broker was updated from 1.6 to 2.x #918

Open BorisBrock opened 2 years ago

BorisBrock commented 2 years ago

I recently updated my broker (Mosquitto) from version 1.6 to 2.14. All my devices continued to work fine, except for my ESP8266 with the pubsubclient library. With the serial monitor I can see that the connect() function returns with error -4. Here's my code:

Serial.println("Attempting MQTT connection...");
if (mqttClient.connect("test"))
{
    Serial.println("MQTT Connected");
    break;
}
else
{
    Serial.print("Failed with state ");
    Serial.print(mqttClient.state());

    retries++;
    if (retries > 20)
        ESP.restart();

    // Wait some time before retrying
    delay(200);
}

In the Mosquitto log everything looks fine though:

New connection from 172.17.0.1:42484 on port 1883. New client connected from 172.17.0.1:42484 as test (p2, c1, k15).

So from the broker's point of view the connection seems to be established just fine. Only the ESP gives me a -4 (timeout?) error. Is there anything I need to change on client or server side to get this working again?

christophehurpeau commented 2 years ago

I had the same problem when I was using UIPEthernet.h, changing to https://www.arduino.cc/reference/en/libraries/ethernetenc/ fixed this issue for me.

fmarzocca commented 5 months ago

I recently updated my broker (Mosquitto) from version 1.6 to 2.14. All my devices continued to work fine, except for my ESP8266 with the pubsubclient library. With the serial monitor I can see that the connect() function returns with error -4.

I have this same problem. How did you fix it?