Arduino Nano 33 IoT stuck in ArduinoCloud.update()?

Hi everyone,

first of all: What I'm trying to build is an IoT-device with low power-consumption. The arduino is supposed to read a sensor-value, send it to the cloud and going back to sleep-mode. During the sleepmode the wifi-nina-module and the ECC508-IC are disabled. The accelerometer is disabled all the time.
Now getting to the problem: To test this scenario, I wrote some code, that does exactly, what I described before, but instead of reading the sensor-value, it counts up a variable.
In theory this works fine so far :nerd_face: In practice it works for five cycles. Getting to the sixth cycle, the arduino connects to the cloud, starts the "ArduinoCloud.update"-function and doesn't do a anything anymore :bomb: :boom: I even have to press the hardware-button on the arduino, to re-upload code.

I already tried to remove some things from the code to find the source of the bug, but I did not get any further:
--> It shows no effect, not powering down the ECC508
--> It shows no effect, not closing the wifi-connection (removing "Wifi.end()")
--> It shows effect, not disabling the wifi-nina-module :see_no_evil: The effect is, that the arduino gets stuck on the ninth cycle, not before the update-function, but after it (serial monitor tells me "update done").

I did a lot of research, but can't find related issues (which I don't understand, because I thought reading a sensors-value, send it to the cloud and going to low-power is a common usage of arduino-IoT). And I really don't get it, because it works five times, why not the sixth???... :thinking:

Anyways, I hope you're able to help me. Below you can find my code and the output of the serial monitor.

If this thread should not be in the correct category, feel free to move it there :slight_smile:

Regards Joseph

Used hardware: Arduino Nano 33 IoT
Wifi-firmware: 1.4.3

Here is the code:


#include "arduino_secrets.h"
#include "thingProperties.h"
#include <SPI.h>
#include <WiFiNINA.h>
#include <Arduino_LSM6DS3.h>
#include <ArduinoECCX08.h>
#include <ArduinoLowPower.h>

//define variables:
int seqStep = 0;

void setup() {

  //init serial monitor
  Serial.begin(9600);
  while (! Serial);   //wait till serial connection is ready

  //disable accelerometer:
  IMU.begin();
  IMU.end();

  initProperties();   //Defined in thingProperties.h
  dhtTemperatureCloud = 0;

  //start sequence
  seqStep = 10;
  
}


void loop() {

  switch (seqStep) {

    case 10:  //activate NINA-wifi-module:
      digitalWrite(NINA_RESETN, LOW);  // activate nina
      delay(3000);
      seqStep = 20;
      break;

    case 20:  //initialize wifi and iot:
      ArduinoCloud.begin(ArduinoIoTPreferredConnection);
      ArduinoCloud.printDebugInfo();
      setDebugMessageLevel(4);
      delay(500);
      seqStep = 21;
      break;

    case 21:  //conncet to wifi and iot-cloud:
      ArduinoCloud.update();
      seqStep = 25;
      break;

    case 25:  //check, if connected:
      if (WiFi.status() == 0 or ArduinoCloud.connected() == 0) {
        delay(2500);
        seqStep = 21;
      }
      else if (seqStep == 25 and WiFi.status() == 3 and ArduinoCloud.connected() == 1) {
        seqStep = 30;
      }
      break;

    case 30:  //take measurements:
      dhtTemperatureCloud = dhtTemperatureCloud + 1;
      Serial.print("dhtTemperatureCloud:"); Serial.println(dhtTemperatureCloud);
      seqStep = 31;
      break;

    case 31:  //update values in cloud:
      Serial.println("Start update");
      ArduinoCloud.update();
      delay(3000);
      ArduinoCloud.update();
      delay(3000);
      ArduinoCloud.update();
      delay(500);
      Serial.println("update done");
      seqStep = 40;
      break;

    case 40:  //close connection, disable wifi-module and ECC508:
      WiFi.end();
      delay(100);
      digitalWrite(NINA_RESETN, HIGH);  // reset nina
      //delay(100);
      ECCX08.begin();
      ECCX08.end();     // power down ECC508
      seqStep = 50;
      break;

    case 50:  //send arduino to sleepmode
      //LowPower.deepSleep(10000);
      delay (10000);
      //restart measuring-cylce:
      seqStep = 10;
      break;

  }

}

And here is the output of the serial monitor:

10:56:36.731 -> ***** Arduino IoT Cloud - configuration info *****
10:56:36.731 -> Device ID: ################################
10:56:36.731 -> Thing ID: ################################
10:56:36.731 -> MQTT Broker: mqtts-sa.iot.arduino.cc:8883
10:56:37.231 -> WiFi.status(): 0
10:56:37.231 -> Current WiFi Firmware: 1.4.3
10:56:45.569 -> Connected to "Wifi-Network123"
10:56:53.535 -> dhtTemperatureCloud:1.00
10:56:53.535 -> Start update
10:56:54.180 -> Connected to Arduino IoT Cloud
10:57:00.725 -> update done
10:57:15.306 -> ***** Arduino IoT Cloud - configuration info *****
10:57:15.306 -> Device ID: ################################
10:57:15.306 -> Thing ID: ################################
10:57:15.306 -> MQTT Broker: mqtts-sa.iot.arduino.cc:8883
10:57:15.828 -> ArduinoIoTCloudTCP::handle_Connected MQTT client connection lost
10:57:18.326 -> WiFi.status(): 0
10:57:18.326 -> Connection to "Wifi-Network123" lost.
10:57:18.326 -> Attempting reconnection
10:57:24.111 -> WiFi.status(): 0
10:57:24.111 -> Current WiFi Firmware: 1.4.3
10:57:32.615 -> Connected to "Wifi-Network123"
10:57:40.237 -> dhtTemperatureCloud:2.00
10:57:40.237 -> Start update
10:57:40.857 -> Connected to Arduino IoT Cloud
10:57:47.388 -> update done
10:58:02.022 -> ***** Arduino IoT Cloud - configuration info *****
10:58:02.022 -> Device ID: ################################
10:58:02.022 -> Thing ID: ################################
10:58:02.022 -> MQTT Broker: mqtts-sa.iot.arduino.cc:8883
10:58:02.513 -> ArduinoIoTCloudTCP::handle_Connected MQTT client connection lost
10:58:05.029 -> WiFi.status(): 0
10:58:05.029 -> Connection to "Wifi-Network123" lost.
10:58:05.029 -> Attempting reconnection
10:58:10.773 -> WiFi.status(): 0
10:58:10.773 -> Current WiFi Firmware: 1.4.3
10:58:21.442 -> Connected to "Wifi-Network123"
10:58:29.089 -> dhtTemperatureCloud:3.00
10:58:29.089 -> Start update
10:58:29.704 -> Connected to Arduino IoT Cloud
10:58:36.216 -> update done
10:58:50.835 -> ***** Arduino IoT Cloud - configuration info *****
10:58:50.835 -> Device ID: ################################
10:58:50.835 -> Thing ID: ################################
10:58:50.835 -> MQTT Broker: mqtts-sa.iot.arduino.cc:8883
10:58:51.361 -> ArduinoIoTCloudTCP::handle_Connected MQTT client connection lost
10:58:53.855 -> WiFi.status(): 0
10:58:53.855 -> Connection to "Wifi-Network123" lost.
10:58:53.855 -> Attempting reconnection
10:58:59.605 -> WiFi.status(): 0
10:58:59.605 -> Current WiFi Firmware: 1.4.3
10:59:09.961 -> Connected to "Wifi-Network123"
10:59:17.673 -> dhtTemperatureCloud:4.00
10:59:17.673 -> Start update
10:59:18.575 -> Connected to Arduino IoT Cloud
10:59:25.083 -> update done
10:59:39.681 -> ***** Arduino IoT Cloud - configuration info *****
10:59:39.681 -> Device ID: ################################
10:59:39.728 -> Thing ID: ################################
10:59:39.728 -> MQTT Broker: mqtts-sa.iot.arduino.cc:8883
10:59:40.218 -> ArduinoIoTCloudTCP::handle_Connected MQTT client connection lost
10:59:42.699 -> WiFi.status(): 0
10:59:42.699 -> Connection to "Wifi-Network123" lost.
10:59:42.699 -> Attempting reconnection
10:59:48.445 -> WiFi.status(): 0
10:59:48.445 -> Current WiFi Firmware: 1.4.3
10:59:58.722 -> Connected to "Wifi-Network123"
11:00:06.484 -> dhtTemperatureCloud:5.00
11:00:06.484 -> Start update
11:00:07.402 -> Connected to Arduino IoT Cloud
11:00:13.907 -> update done
11:00:28.547 -> ***** Arduino IoT Cloud - configuration info *****
11:00:28.547 -> Device ID: ################################
11:00:28.547 -> Thing ID: ################################
11:00:28.547 -> MQTT Broker: mqtts-sa.iot.arduino.cc:8883
11:00:29.031 -> ArduinoIoTCloudTCP::handle_Connected MQTT client connection lost
11:00:31.537 -> WiFi.status(): 0
11:00:31.537 -> Connection to "Wifi-Network123" lost.
11:00:31.537 -> Attempting reconnection
11:00:37.286 -> WiFi.status(): 0
11:00:37.333 -> Current WiFi Firmware: 1.4.3
11:00:47.651 -> Connected to "Wifi-Network123"
11:00:55.346 -> dhtTemperatureCloud:6.00
11:00:55.346 -> Start update
11:00:56.249 -> Connected to Arduino IoT Cloud