wifiecho example error -2 on uno r4
as in the title. it connects just fine with the wifi but i get an error code -2 whenn running the wifiecho example on an arduino uno r4. it happens both on test.mosquitto.org and a local mosquitto broker acceptiong anonymous connections. mqtt explorer works just fine on both so i don't know what's going on . thx for the help. i'm unable to test on any other boards atm but the most likely culprit is the uno r4 since it's so new and i've had trouble with other libraries Max
Hi @maxvaneck I'm not able to reproduce your issue with my UNO R4, seems everything is working fine. Would you check which wifi firmware version is running on your board?
I was running an older firmware version. i've just updated and i still run in the same problem on the example
I am also having this issue with an Uno r4 running firmware 0.4.1
i did find a fix eventually . i vaguely remember something about adding a sort of delay during connection . below is some code you could try of which i am reasonably sure it works
Serial.print("Attempting to connect to the MQTT broker: ");
Serial.println(broker);
if (!mqttClient.connect(broker, port)) {
Serial.print("MQTT connection failed! Error code = ");
Serial.println(mqttClient.connectError());
Serial.print("Attempting to connect to the MQTT broker: ");
Serial.println(broker);
while (!mqttClient.connect(broker, port))
{
Serial.print(".");
delay(100);
}
Serial.println("\nYou're connected to the MQTT broker!");
Serial.println();
Serial.println("You're connected to the MQTT broker!");
Serial.println();
Serial.print("Subscribing to topic: ");
Serial.println(topic);
Serial.println();
// subscribe to a topic
mqttClient.subscribe(topic);