I am struggling to modify existing LoRaWAN example code to my needs. I want to synchronize the state of a magnetic reed-switch with my home automation using a CubeCell board.
Normally the CubeCell does deepsleep with a battery-life message every 24h.
Only when the switch changes, an interrupt occurs and a Lora message is sent. All of this already works by slightly modifying the examle scetch “LoRaWAN_Interrupt.ino”. So what is my issue:
When the switch changes state back in just a second, another interrupt is generated. But this seems to be “forgotten”. What I think is happening: The prepareTxFrame() is called again, the LoRaWAN.send() is called again, but because this is too early after the last message, it is just omitted.
I can (and do) remember the last state sent and the current state in variables, but my issue is the control flow. When one message is omitted, the device sleeps and is not retriggered (only after 24h…).
And the LoRaWAN.send() method does not indicate, if the message was simply dropped.
Is there some example code which is nearer to my use case, or do you have another proposal where I should be looking?
Frankly speaking: I do not fully understand the interrrupt-propagation in combination with the state machine in the example code. What I imagine would work: Once an interupt occurs, the duty-cycle is shortened to like 10s, and only after the I/O state is identical to the last message sent, it falls back to 24h sleep.