Difference between api.system.scheduler.task.destroy();
and api.system.sleep.all();
and this seemly the same
When using this code
Serial.print("The timestamp before sleeping: ");
Serial.print(millis());
Serial.println(" ms");
Serial.println("(Wait 10 seconds or Press any key to wakeup)");
api.system.scheduler.task.destroy();
api.system.sleep.all(); // change function
Serial.print("The timestamp after sleeping: ");
Serial.print(millis());
Serial.println(" ms");
there is no difference. In the examples sometimes the one and sometimes the other is used
api.system.scheduler.task.destroy(); stops loop() from being called ever. api.system.sleep.all(); puts the loop into sleep until an event happens.
Difficult to explain. Maybe this simple example helps.
Loop calls 16 times api.system.sleep.all();
The device wakes up from sleep on events, that can be LoRa or LoRaWAN events or a timer event or an external interrupt.
After 16 times loop calls api.system.scheduler.task.destroy(); and after that loop() is never called again.
For demonstration purposes I use a timer that “ticks” every one second.
In the beginning, every timer event triggers a wakeup from sleep ==> loop is executed (if you look into the log, you can see there is as well another event happening that wakes the loop between tick #1 and tick #2
After 16 times you can still see the “Tick”, but loop is not executed anymore, because the loop task is destroyed.
After 20 ticks, the timer is stopping itself and you see no more output.