Okay, I have been racking my brain these past hours and tested various things, but I so far no real progress.
Looking at the LoRaWAN example code and taking your hints into account, it is obvious that the sleep mode happens in case DEVICE_STATE_SLEEP: { }
, so naturally any code for sleeping should be there. I mean, the function LoRaWAN.sleep(loraWanClass);
is already there and contains a call to sleep. That function seemingly only turns off the LoRaWAN, nothing else (I say seemingly because looking up LoRaWAN.sleep()
online only returns threads of other people having issues with that function [so far none that I could apply to my issue] but no documentation that explains what this does).
But to reduce the power usage, I want my device to enter an actual “deep sleep”, where the radio is off, the board LED is off, the sensors are not powered, etc. – from Quency-D’s code there is more code that should be added to turn off things. Now here is where things stopped making sense to me.
If I leave everything as it is in my code, the data is transmitted, I get it printed out to the serial monitor and it appears on TTN. Good.
When I remove the LoRaWAN.sleep() function in the sleep state, it displays “forward join-accept message” in TTN but never gets values. The same thing happens when I replace that sleep function with the esp deep sleep function, when I put the deep sleep function before or after the LoRaWAN.sleep() function. Which makes sense, because after that function there is a break statement which takes us back to initialization, and when that break is not executed, nothing else in the switch function is executed.
The sleep state is set in the cycle part with deviceState = DEVICE_STATE_SLEEP;
and when I print out “going to sleep” before that line, I can observe a downlink message afterwards, a short pause, and then some booting etc. until the next data is sent (see “output” below).
output
02:36:10.131 -> enter sleep state. zzz
02:36:15.237 -> received unconfirmed downlink: rssi = -61, snr = 14, datarate = 5
02:36:25.189 -> ESP-ROM:esp32s3-20210327
02:36:25.230 -> Build:Mar 27 2021
02:36:25.230 -> rst:0x5 (DSLEEP),boot:0x9 (SPI_FAST_FLASH_BOOT)
02:36:25.230 -> pro cpu reset by JTAG
02:36:25.230 -> SPIWP:0xee
02:36:25.230 -> mode:DIO, clock div:1
02:36:25.230 -> load:0x3fce3808,len:0x43c
02:36:25.230 -> load:0x403c9700,len:0xbec
02:36:25.230 -> load:0x403cc700,len:0x2a3c
02:36:25.230 -> SHA-256 comparison failed:
02:36:25.230 -> Calculated: dcde8d8a4817d9bf5d5d69a7247667264e4e10ac7493514868b61f5aa6146539
02:36:25.230 -> Expected: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
02:36:25.254 -> Attempting to boot anyway…
02:36:25.254 -> entry 0x403c98d8
02:36:25.685 -> temperature: 22.55 | humidity: 72.50
02:36:25.685 -> confirmed uplink sending …
02:36:25.685 -> sent data
02:36:25.685 -> enter sleep state. zzz
So I know that my sleep resources have to be activated after the cycle state, to be active in the sleep state, and then the wakeup resource has to be defined there as well. Because none of the logic placements of the additional deep sleep resources worked, I then tried everything else that came to my mind, with the following findings:
- Putting the resources instead of lorawan.sleep -> no data sent to TTN
- Putting the resources after lorawan.sleep -> see above
- Putting the resources before lorawan.sleep -> see above
- Putting the resources in the cycle state -> no data sent to TTN
- Putting the resources in the send state -> no data sent to TTN
- Putting the resources in the join state -> doesn’t even communicate with the gateway but prints out devUI etc.
- Putting the resources in the init state -> see above
- Sandwiching the switch statement between the wakeup and the sleep resource -> see above
In the Heltec TimerWakeUp.ino file, everything that is supposed to be executed is place between the wakeup and the sleep resource, just in the setup rather than the loop part. However, that would just cause the same issue as the last point in the bullet list above.
TL;DR: I know the deep sleep resources have to be in the sleep cycle, when my device (or parts of it) are supposed to sleep. But somewhere, there is an issue, and my brain does not comprehend where it comes from and how to fix it.