# OTAA then ABP

**URL:** <https://www.thethingsnetwork.org/forum/t/otaa-then-abp/12377>\
**Category:** Uncategorized\
**Created:** [February 5, 2018, 11:35pm UTC](https://www.thethingsnetwork.org/forum/t/otaa-then-abp/12377 "2018-02-05T23:35:26Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [February 6, 2018, 5:35pm UTC](https://www.thethingsnetwork.org/forum/t/otaa-then-abp/12377/5 "2018-02-06T17:35:49Z")

</div>

> [@AdamJP](#):
>
> Should all node send one OTAA request to join (assuming its successful) then use ABP to send data unless otherwise told to OTAA join again?

No, not really:

- OTAA activation gets the device the NwkSKey, AppSKey and DevAdr from the server, plus network settings such as additional frequencies and RX settings. (Join Request sent, Join Accept received.)

- ABP “activation” sets the NwkSKey, AppSKey and DevAdr into the device while programming, and also requires one to program the network settings. (No network traffic for the “activation” at all.)

- While transmitting uplinks or while decrypting downlinks, your LoRaWAN library does not care how the device got all these settings.

- **Only when the device somehow loses its configuration one can avoid having to do an OTAA activation again by storing the OTAA responses in non-volatile memory and then mimic an ABP “activation”.** If this only happens when the device is restarted or the battery is empty: don’t worry, just do OTAA again. (Also nice to allow for simply joining a different network.) If it happens for every (deep) sleep, then store and re-use the settings and frame counters, [and much more](https://www.thethingsnetwork.org/forum/t/otaa-best-practice-how-to-not-join-every-time/14601/9).

Some libraries or devices might support this without doing anything special in code, or with a single line of code to save the settings.

- For RN2483 and RN2903, `mac join abp` after an earlier `mac join otaa` and frequent usage of `mac save` (to save a long but [possibly incomplete](https://www.thethingsnetwork.org/forum/t/acknowledge-to-confirmed-downlink-was-received-gateway-traffic-but-not-shown-in-console/34069/6) list of settings) should do the trick, though one might first need to [set dummy values for DevAddr, AppSKey and NwkSKey to make that work](https://www.thethingsnetwork.org/forum/t/how-often-should-a-node-do-an-otaa-join-and-is-otaa-better-than-abp/11192/47).

- For LMiC, one needs to store and retrieve settings manually: after deep sleep, configure your node as an ABP node using `LMIC_setSession(...)`, and set the frame counters to their last stored values, using `LMIC.seqnoUp = ...` and `LMIC.seqnoDn = ...`. The session secrets have different names (which originate from the early days where LoRaWAN was still called LoRaMAC). [The documentation shows](https://github.com/matthijskooijman/arduino-lmic/blob/master/doc/LMiC-v1.5.pdf):

Be careful _where_ to save such details:

> [@Where in LMiC is the "fCnt" parameter stored?](https://www.thethingsnetwork.org/forum/t/where-in-lmic-is-the-fcnt-parameter-stored/3082/5):
>
> EEPROMs usually have limited write cycles and the datasheet for both Arduinos and the PIC18LF46K22 micros inside the RN2483 module lists 100,000 erase/write cycles.
> 
> This means if you’re sending 5 messages/hour every day and recording to EEPROM every time you’ll potentially kill the EEPROM in about 2 years.

And if one happens to use an ESP32:

> [@Big ESP32 + SX127x topic part 2](https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-2/11973/90):
>
> You can now use SPIFFS for ESP32 (Remembers things even after a powerdown)  
> [arduino-esp32/libraries/SPIFFS at master · espressif/arduino-esp32 · GitHub](https://github.com/espressif/arduino-esp32/tree/master/libraries/SPIFFS)
> 
> This is great explanation of how it is used for the ESP8266  
> [https://www.youtube.com/watch?v=jIOTzaeh7fs](https://www.youtube.com/watch?v=jIOTzaeh7fs)

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/otaa-then-abp/12377)._
