@matthijs, did you ever try to understand the DO_DEVDB macro?
I wondered if frame counters survive Arduino restarts, but they don't. This might soon become troublesome, as per Security in LoRaWAN and TTN in the staging wiki:
[...] you should realize that these frame counters reset to
0every time the device restarts (when you flash the firmware or when you unplug it). As a result, The Things Network will block all messages from the device until theFCntUpbecomes higher than the previousFCntUp. Therefore, you should re-register your device in the backend every time you reset it.
When a counter increments, it seems LMiC allows for storing it in some "device database" (beware: my own terminology). Like for LoRaWAN's FCntUp:
LMIC.seqnoUp += 1;
DO_DEVDB(LMIC.seqnoUp,seqnoUp);
The same macro is used after Over-the-Air Activation, or for adaptive date rate. However, DO_DEVDB is a no-operation in oslmic.h:
#define DO_DEVDB(field1,field2) /**/
(Which, I think, is also why this code even compiles, as the bare seqnoUp is not even defined?)
But maybe my guess about the meaning of the DO_DEVDB macro is wrong. First, for a database, I'd have expected LMiC to define that in the HAL, not in oslmic.h. Also, I don't see how the values are ever read back from such database, in the IBM code. And the LMiC documentation states:
2.5.4
void LMIC_setSession (u4_t netid, devaddr_t devaddr, u1_t* nwkKey, u1_t* artKey)Set static session parameters. Instead of dynamically establishing a session by joining the network, precomputed session parameters can be provided. To resume a session with precomputed parameters, the frame sequence counters (
LMIC.seqnoUpandLMIC.seqnoDn) must be restored to their latest values.
I guess that implies one should store the counters in the EV_TXCOMPLETE event. And when doing so, the following might be relevant too:
EV_RESETSession reset due to rollover of sequence counters. Network will be rejoined automatically to acquire new session.
Reading the LMiC documentation makes me think this is only a problem for Activation by Personalization (as used in the example code). But I've not checked if Over-the-Air Activation automatically resets the counters in the TTN backend.