Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a ArduinoIoTCloudClass::end() function for a regulated shutdown #73

Open
generationmake opened this issue May 27, 2019 · 9 comments
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@generationmake
Copy link

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:

void ArduinoIoTCloudClass::end() {
  _connection->end();  // power down network interface - reduces power consumption from serveral mAs to a few uAs
  ECCX08.end();     // power down ECC508 - reduces power consumption from 800 uA to 6 uA
}

and add to the ConnectionManager a public end function. For the MKR WIFI 1010 for example WiFi.end();

Thank you

@ubidefeo
Copy link
Collaborator

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 :)

@aentinger
Copy link
Collaborator

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.

@generationmake
Copy link
Author

Hi @ubidefeo and @lxrobotics.
Thank you for your answers.
I will stay patient and see what comes up next.

@podhrmic
Copy link

podhrmic commented Dec 2, 2019

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?

@ubidefeo
Copy link
Collaborator

ubidefeo commented Dec 2, 2019

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

@podhrmic
Copy link

podhrmic commented Dec 2, 2019

Thanks for the quick reply!

@ubidefeo
Copy link
Collaborator

ubidefeo commented Dec 2, 2019

my pleasure, @podhrmic
just make sure you give the board enough time to reconnect before it goes back to sleep ;)

@andreacosti
Copy link

andreacosti commented Mar 9, 2020

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

@podhrmic
Copy link

podhrmic commented Mar 9, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

6 participants