Uplink rejected after end device wakes up and sends data

Hi All,

I am running some experiments with low power end device. The device is a Heltec Wireless Stick Lite (Arduino) and it’s using LMIC library found here: https://github.com/mcci-catena/arduino-lmic

Basically following the pattern below:

  1. Join Network
  2. Send sensor data payload
  3. Save session data (network id, devaddr, session keys and up/dn counters)
  4. Go to sleep for some time (1 minute for testing)
  5. Wake up device and LoRa radio
  6. Restore previously saved session data using LMIC_setSession()
  7. Repeat from step #2

The uplink message is received by the server as unconfirmed, but it is rejected with the following error

Sep 04 11:18:01 rak-gateway loraserver[548]: time="2019-09-04T11:18:01-07:00" level=error msg="processing uplink frame error" data_base64=QKsjAQCAAAABFXvlQq7sWi5Rd7DT error="get device-session error: device-session does not exist or invalid fcnt or mic"

I am not sure what device-session is?

Well, I found the issue. The fCnt was wrong and always set to 0. That’s because on the end device, the counters must be set after the call to restore the LMIC session, otherwise the counters are reset.

So the correct LMIC sequence call is

 LMIC_setSession(netid, devaddr, nwkKey, artKey);
 LMIC.seqnoUp = last_sequence_up;
 LMIC.seqnoDn = last_sequence_dn;

Now the Lora Server is happy :wink: and fCnt is incremented as expected