arduino-libraries / ArduinoIoTCloud

Home Page:https://app.arduino.cc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ArduinoCloud does not reconnect

jcham opened this issue · comments

The simple example projects to light up an LED work fine, but the whole thing stops working when WiFi connection gets momentarily lost, and it doesn't reconnect, requiring a reset.
If this is normal, then what is the recommended way to detect a disconnect and reconnect?
Thanks

I've tried several things, but none of them cause the connection to come back up:

void loop() {
  
  ArduinoCloud.update();

  // ---- Maintaining connection led
  bool connected = ArduinoCloud.connected();
  if (connected_prev != connected) {
    Serial.print("ArduinoCloud connection ");
    Serial.println(connected);
  }
  connected_prev = connected;
  digitalWrite(CONNECTION_LED_PIN, connected);

  // ---- Reconnect
  ArduinoIoTPreferredConnection.check();
  // if (!connected) {
  //   Serial.println("ArduinoCloud reconnecting...");
  //   ArduinoIoTPreferredConnection.connect();
  //   ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  //   delay(10000);
  // }
}

Hi @jcham 👋
The reconnection is handled within the ArduinoCloud logic. Under no circumstances should you try to manually interfere with this logic (e.g. directly calling ArduinoIoTPreferredConnection.check()). When you say "WiFi connection gets momentarily lost" what kind of WiFi connection loss are you describing?

Also: What board are you using?

Using an Arduino Nano 33. That's what I tried in the first place, but it never reconnects. I don't know in production why the connection fails, but I can replicate my problem by turning off the wifi at home.
So not calling anything it should reconnect automatically?

When I disconnect the WiFi, I get this on the Serial:

ArduinoIoTCloudTCP::handle_Connected MQTT client connection lost

But it never reconnects, what do I have to do to restart it.

Ah I used the IDE to update the WiFi module firmware and now it's ok!

Actually, there is still a problem: when the WiFi comes in and out it reconnects fine, but some other condition (after some random amount of time) causes it to drop and then it doesn't recover. How to debug this?

Hi 👋 We've got new releases of the firmware running on the WiFi module (NINA-W102). Would you mind trying to upgrade to the latest release (1.4.3) and see if that solves your issue? Best way to do is is probably: https://github.com/arduino/FirmwareUpdater.

@jcham Lot's of stuff happened 👋 ArduinoIoTCloud:v1.0.1 in combination with nina-fw:v1.4.4 should solve a lot of issues with regards to reconnection. I'll be closing this issue since you already failed to answer to my last comment. If you should still be around and give a spin to the latest releases AND still experience issues, please reopen this issue.