MKR1400 + arduino iot cloud - time out connection send data only one time

Good morning, I'm writing here to ask for help with a possible code error that I can't solve.

Briefly my project aims to measure the temperature of an environment in a remote location and provides a MKR1400 board + arduino sim + DHT22 that sends data to the cloud every 30 or 60 minutes (this is to save data traffic sim).

The connection code taken from the examples provided with the libraries seems to work well if the code runs with very short delays. The problem comes when I want to make pass a longer time between a measurement and the other and then do the send and update cloud.
Starting the code at the first reading the data are sent to the cloud, the second sending is lost and the card is disconnected from the cloud (on the serial monitor instead the measurement is always correct).
Can someone give me some tips to understand what I'm doing wrong?

Here is the code of the .ino file

Thanks for help

#include "arduino_secrets.h"
#include "thingProperties.h"

// Costanti di tempo per la gestione dell'intervallo di misurazione 
const long oneSecond = 1000;
const long halfMinute = oneSecond*30;
const long oneMinute = oneSecond*60;
const long fiveMinute = oneMinute*5;
const long quarterHour = oneMinute*15;
const long halfHour = oneMinute*30;
const long oneHour = oneMinute*60;
const long oneDay =  oneHour*24;

// DHT22 inizializzazione
#include <SimpleDHT.h>
int pinDHT22 = 2;
SimpleDHT22 dht22(pinDHT22);


void setup() {
  /* Initialize serial and wait up to 5 seconds for port to open */
  Serial.begin(9600);
  for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
  
  /* inizializzo il BMP280 
  if(!bmp280.init()){
    Serial.println("Device error!");
  }
*/
  /* Configure LED pin as an output */
  pinMode(LED_BUILTIN, OUTPUT);

  /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
  initProperties();

  /* Initialize Arduino IoT Cloud library */
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  setDebugMessageLevel(DBG_INFO);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  
  ArduinoCloud.update();
  
  DHT22_function();
 // BMP280_function ();
  
  Serial.println("attendo prima di aggiornare");
  delay(halfHour);  // -->> verifca il corretto delay 30 minuti
  // Domanda, se metto un delay lungo qui perde la connessioe al cloud

}


void DHT22_function() {
  // start working...
  Serial.println("=================================");
  Serial.println("Lettura dati sensore DHT22...");
  
// these are present in the thingProperties file as global variabiles

//  float ext_temp ;     // non richiamo le variabili già dichiarate in thingProperties.h
//  float ext_humidity ; // non richiamo le variabili già dichiarate in thingProperties.h

//
  int err = SimpleDHTErrSuccess;
  if ((err = dht22.read2(&ext_temp, &ext_humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000);
    return;
  }
  Serial.print("Sample OK: ");
  Serial.print((float)ext_temp); Serial.print(" *C, ");
  Serial.print((float)ext_humidity); Serial.println(" RH%");
  Serial.println("=================================");
  delay(2000);
}

Hi,
I've noticed that you have to call the ArduinoCloud.update(); very frequently, at least once every 2 seconds.
If you put a delay of 30 minutes between one update and the next the connection is dropped and this library
is not able to recover.

I'm facing a lot of troubles also with LowPower mode [Different POST].

Try to remove the delay.
Toshiro

Hello,
thanks for your reply, at the end I've moved to thingspeaks cloud with a different iot sim.
With this metod you can turn on and off the gprs connection and save data consuption.
I'm still working on the project but I suggest this way tha is more flexible and easy to personalize.
Keep in touch.

PS: once my project will be ready I'll try to take time and share more infos on it.

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