How to check if a session is currently established or not / LMIC is still joining or not?

@tmm
How to check if a session is currently established or not / LMIC is still joining or not?

When using OTAA there are two ways that a join can be initiated:

  1. Implicity, by scheduling an uplink message which will then automatically start the join process.
  2. By explicitly calling LMIC_startJoining().
  • Is there a simple and reliable way, e.g. by checking values in the LMIC structure or otherwise to check if LMIC is still joining (but the join has not yet completed)?
  • Is it possible to check the following separately?:
    • Check if a session is established or not.
    • Check if LMIC is currently (still) joining or not.

If not, this apparently will have to be done using events:

While handling EV_JOINED, a global variable isJoined (static volatile bool isJoined = false) can be set to true.
The isJoined variable can then be checked to see whether the device is joined / a session is currently established or not.

  • In which cases and when should the isJoined variable be set to false again?
    (What can cause the session to be no longer valid?)

A session is established if and only if LMIC.devAddr is non-zero. This can be relied upon. (We really ought to have an API for getting the value rather than inspecting the database; but LMIC.devAddr != 0 is what the LMIC itself uses.)

1 Like

Thanks.

If a session is invalidated (for whatever reason / if possible) will LMIC.devaddr be ‘automatically’ reset to 0?

Yes. In fact, resetting LMIC.devaaddr to zero is how sessions are invalidated (internally).

1 Like