Permanent offline status / dropping connection

Hello,

I keep having a strange issue with one of the Nano RP2040 Connects. I uploaded a simple sketch without issues (see below), however, most of the time the device shows as offline in the cloud, with error messages appearing in the editors: no associated device found, then switching back to the COM port where the device is actually located - periodically. Same thing when you go to the full editor and check the monitor - the serial port is busy, and top right corner periodically comes up with ... connected ... disconnected ... connected ... and so on.

Thing is, yesterday I got it to work, and it ran stably until today, but today, after updating the sketch (including resetting a couple of times), it simply wont do. Firmware is latest, the local Arduino IDE is not running, I restarted the browser, so nothing else should be accessing the port - at the same time the fact that the error messages are periodic and timed, makes me think I am missing something trivial.

Any help would be appreciated!

Thank you -
Liliya.

#include "thingProperties.h"

#include <EduIntro.h>
DHT11 dht11(4);

void setup() {
  initProperties();
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  dht11.update();
  temperature = dht11.readCelsius();
  humidity = dht11.readHumidity();
  delay(10000);
}

void onTemperatureChange()  {
}

void onHumidityChange()  {
}

...seems the delay() at the end of the loop() is causing problems. This always disconnects the Nano, but only when you run it from the Cloud.

Cheers -
L.

Congratulations on finding the cause of the problem @licicka! Thank you for taking the time to post an update.

Just in case you (or anyone else who has a similar problem and finds this forum thread during their research) are curious about why long delays can cause problems for Arduino Cloud Thing sketches, I'll provide some information on the subject:

It is essential to design your Thing sketch code so that ArduinoCloud.update() is called frequently. The reason is that this function is what handles the syncing of your Arduino Cloud Variables between the device and the Arduino Cloud servers and your dashboards.

If the sketch code causes in long intervals to occur during which ArduinoCloud.update() is not called, this will result in problems such as lags in response of the board to actions taken in the Arduino Cloud dashboard and of response of the dashboard to changes made to the Cloud Variable values by the Thing sketch program.

If a problem in the sketch code caused the program to go into a state where ArduinoCloud.update() is not called at all, all Cloud Variables would cease to be synced altogether. For this reason, Thing sketches have a "watchdog timer":

https://docs.arduino.cc/arduino-cloud/cloud-interface/sketches/#watchdog-timer-wdt

This feature will automatically reset the Arduino board if a long interval passes since the last time ArduinoCloud.update() was called.

You can learn a useful technique for writing sketches that perform actions at defined intervals, while allowing the loop function to run freely and continue calling ArduinoCloud.update() frequently, from this tutorial:

https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay

1 Like

Thank you very much for this in-depth explanation!
All the best -
Liliya.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.