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

Issues connecting to MQTT broker using W5500 chip #374

Open ApoelAlex opened 6 years ago

ApoelAlex commented 6 years ago

Hi there,

I am facing connection issues with the MQTT broker, while trying to connect using an Ethernet Shield2 (W5500).

I am not sure if the library has full support for the W5500 chip, exact code seems to work fine for the w5100 one. Do you guys have any suggestions?

I am using the following Ethernet library: Ethernet2

// AA: Program Entry point
void setup() {
    Serial.begin(9600);
    while (!Serial) { ; }

    // AA: Init Pins
    pinMode(RELAY_PIN, OUTPUT);
    pinMode(SD_PIN, OUTPUT);
    controlSD(false);

    // AA: Init Web Server
    delay(1000);
    Ethernet.begin(_Mac);
    _Server.begin();
    delay(1000);
    Serial.print("server is at ");
    Serial.println(Ethernet.localIP());
    delay(2000);

    // AA: Init Mqtt
    //if (_IsMqEnabled == 1) {
        _SrvClient = _Server.available();
        _MqClient.setServer("test.mosquitto.org", 1833);
        _MqClient.setCallback(callback);

        if (_MqClient.connect("ApoelAlex001")) {
            Serial.println("connection succeeded");
            _MqClient.subscribe(_MqTopic, 2);
        }
        else {
            Serial.println("connection failed");
            Serial.print("failed, rc=");
            Serial.print(_MqClient.state());
        }
    //}
}
eveready1010 commented 5 years ago

I have the exact same issue. Is the W5500 chip not supported by MQTT or something? I tried other libraries and also could not get them working...

chris-kuhr commented 4 years ago

same here, arduino mega/nano with w5500. sometimes the connectiin fails with rc=-2. any idea?