Open generationmake opened 5 years ago
hi @generationmake You have a really good point there. We have been working on an update which will allow better control of connection/disconnection. Of course our goal is to work on something which won't introduce breaking changes, but we're getting there. Stay tuned :)
Hi @generationmake Thank you very much for raising this issue. If you have already a complete implementation feel free to create a pull request. I'll have to advise you though that currently refactoring efforts are under way which might render your PR obsolete, so I suggest the best course of action is to wait it out a bit and then create a PR with your suggested changes.
Hi @ubidefeo and @lxrobotics. Thank you for your answers. I will stay patient and see what comes up next.
Hi! What is the status of this feature? I have an application that needs to sleep for extended periods of time between updates (~10min), and I am not sure if the Arduino can reconnect with the cloud after the deep sleep (using Arduino Low Power library on MKR GSM board). Is that currently possible?
hi @podhrmic I have successfully used the automatic reconnect on IoT Cloud using MKR GSM waking up from deep sleep. I have occasionally had reconnection issues when coverage wasn't available but it worked once signal was fine again
Thanks for the quick reply!
my pleasure, @podhrmic just make sure you give the board enough time to reconnect before it goes back to sleep ;)
hi @ubidefeo I have the same problem. I have a MKRGSM1400 with a MKRENV shield and I want to send dato to cloud. I use Arduino low power library to put the MKRGSM in deep sleep but after some times it stop working. For example with deep sleep time of 15 minutes it works for a while then it stop working. In my last test it worked for 4 hours then it stop working. With a sleep time of 30 minutes or 1 hour it stop working immediately.
This is my simple sketch:
#include <Arduino_MKRENV.h>
#include <ArduinoLowPower.h>
#include "thingProperties.h"
GSM_SMS sms;
unsigned long tempo;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1000*30);
// Defined in thingProperties.h
initProperties();
// Imposto Callback per invio SMS informativo alla prima connessione
ArduinoIoTPreferredConnection.addConnectCallback(onNetworkConnect);
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(4);
ArduinoCloud.printDebugInfo();
// Inizializzo MKRENV
if (!ENV.begin()) {
Serial.println("Failed to initialize MKR ENV shield!");
while (1);
}
// Imposto funzione da richiamare al risveglio
LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, onWakeUp, CHANGE);
tempo = millis();
}
void loop() {
ArduinoCloud.update();
// Your code here
// read sensor values
temperatura = ENV.readTemperature();
umidita = ENV.readHumidity();
pressione = ENV.readPressure();
if (millis() - tempo > 90000) {
// Triggers a 300 seconds sleep (the device will be woken up only by the registered wakeup sources and by internal RTC)
// The power consumption of the chip will drop consistently
LowPower.deepSleep(900000);
delay(10000);
tempo = millis();
}
}
void onNetworkConnect(void *_arg) {
static int SMSConnessione = 0;
if (SMSConnessione == 0) {
// Invio SMS di conferma inizializzazione scheda
sendSMS("xxxxxxxxxx", "Scheda Inizializzata");
SMSConnessione = 1;
}
}
void sendSMS(char numero[], char testoSMS[]){
sms.beginSMS(numero);
sms.print(testoSMS);
sms.endSMS();
}
void onWakeUp() {
// This function will be called once on device wakeup
// You can do some little operations here (like changing variables which will be used in the loop)
// Remember to avoid calling delay() and long running functions since this functions executes in interrupt context
//ArduinoIoTPreferredConnection.connect();
//tempo = millis();
}
Thanks
Just FYI I had a similar problem - I have Arduino MKR GSM shield with a number of I2C sensors, and it all works nicely until Arduino goes to sleep. After spending some time trying to debug what is going on, I used Arduino Uno to turn Arduino MKR GSM on and off (and Uno sleeps in between) and that works as expected.
I suggest to add a ArduinoIoTCloudClass::end() function for a regulated shutdown and restart of the whole cloud function. This would allow arduinos to shut down the cloud functions for power reasons (for example sleep mode) and enable them later again.
For example:
and add to the ConnectionManager a public end function. For the MKR WIFI 1010 for example WiFi.end();
Thank you