Datalogger MKR GSM 1400 with Arduino IoT Cloud in sleep mode (LowPower library)

Hi guys, it's been few days that I try to work out a solution for my project but I'm still stuck.

Basically my project consists on using an Arduino MKR GSM 1400 (coupled with an MKR SD shield) to log and store some values that I will get from a sensor. This datalogger will then be connected to the Arduino IoT Cloud platform and will show the measured values live (or with a small delay). Since I am using a MKR GSM which will be powered by a Lipo 2Ah, I need to keep the power consumption as low as possible. To do so, I found the library LowPower (which is based on the RTC library) for arduino models with a SAMD21 which allows to save some power by putting the arduino asleep for a certain amount of time. And here I started to get some problems...

[See "Test_sleep_cloud" attached code] Firstly I tried to write my code in the web editor (since it was faster and the code is half autofilled when you create your IoT thing) to test the cloud and without sleeping mode it worked. As soon as I used the sleep mode, the "setup" section worked fine, but once the SAMD21 wakes up after sleeping, it can't send data to the cloud and therefore I cannot see the measured values. I thought it could be the fact the I should wait until the Arduino get reconnected with the cloud, but I didn't know how to do it yet and I decided to make sure that without the Cloud the board could work with the LowPower library.

[See "Test_sleep_serial" attached code]To make sure that the LowPower library could work I tried to debug the code with the classic Arduino IDE and keeping the code as simple as possible (no Arduino IoT Cloud and no GSM connection). For this test I proceeded by sending messages to the Serial for each important piece of code, to better keep track of what the heck is going on in my Arduino. ...And here comes other problems. As done in the previous test, the "setup" section and the first loop worked fine, then after waking up it can't send data to the Serial. I then tried by:

  • using Serial.flush() before going to sleep;
  • using Serial.end() before going to sleep + using Serial.begin(9600) at the beginning of each loop;

None of these improvements worked. So at this stage I must miss something in the library and on how it works.
So, how does really works the RTC in SAMD21 arduino models?
How does it works the LowPower library?
What can I do to restore everything back to the normal (like connections with Serial + GSM network + Cloud IoT) once the SAMD21 is woken up?

It's a pretty complicated history/problem I know, but I tried to be as clear as possible.

Thanks in advance for the help!

Ludovico

PS: Since it was a test, the circuit is the same as the one you can find in this nice tutorial/project!

Test_sleep_cloud.ino (4.4 KB)

Test_sleep_serial.ino (3.43 KB)