mcci-catena / arduino-lorawan

User-friendly library for using arduino-lmic with The Things Network and other LoRaWAN® networks
MIT License
274 stars 54 forks source link

How to implement low power LoRaWAN device using OTAA? #144

Open wzab opened 3 years ago

wzab commented 3 years ago

I need to implement a LoRaWAN device that sends a message every 10 minutes. To limit the power consumption I need to put the device to sleep between sending the messages. If I use ABP, the problem can be solved easily with simple putting the CPU to sleep in the loop() function. However such solution is not possible when using OTAA, as it breaks the timing, I have checked the sources, and I can see that Arduino_LoRaWAN::loop() https://github.com/mcci-catena/arduino-lorawan/blob/4bc0d48b9956d5bed8e26dda01ead05d8ac269b3/src/lib/arduino_lorawan_loop.cpp#L40 calls the os_runloop_once routine from the underlying Arduino-LMIC library, and this routine calls hal_sleep() . Unfortunately, the hal_sleep() function is currently not implemented . Does it mean that if I need to implement a low-power LoRaWAN device I have to use ABP or I need to use another, not-MCCI LoraWAN library?

wzab commented 3 years ago

I have found that website. It requires me to use the low-level library, but seems to support the deep sleep mode. The solution works nice, consuming ca. 100µA in the sleep state (probably mainly by the voltage regulator). There is however one serious disadvantage. If the device can't join the network (e.g., because there is no active gateway in the vicinity) , it remains all the time in the active mode and may drain the battery very quickly. Probably it is necessary to limit the number of the attempts to join the network, and in case of failure the device should go to sleep, and retry after e.g. half an hour.

jdeus commented 3 years ago

Yes these LMIC libraries are far from being usable. They lack key features such as saving the state to be restored when exiting a deep sleep.

Much work has to be done for this to be used in any serious application.

postfalk commented 3 years ago

It says "It provides a simple framework for doing low-power programming." in the documentation and never gets back to the topic. Documentation needs to be improved. This library is not user-friendly due to a lack of concise documentation. See also #143