Skip to content

wifiecho example error -2 on uno r4  #108

Open
@maxvaneck

Description

@maxvaneck

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

Activity

pennam

pennam commented on Jul 17, 2024

@pennam
Contributor

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?

maxvaneck

maxvaneck commented on Jul 19, 2024

@maxvaneck
Author

I was running an older firmware version. i've just updated and i still run in the same problem on the example

willham93

willham93 commented on Nov 19, 2024

@willham93

I am also having this issue with an Uno r4 running firmware 0.4.1

maxvaneck

maxvaneck commented on Nov 19, 2024

@maxvaneck
Author

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      wifiecho example error -2 on uno r4 · Issue #108 · arduino-libraries/ArduinoMqttClient