Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Last active August 3, 2022 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lupyuen/c03870b103f51649dcf608ffb1bc9e6b to your computer and use it in GitHub Desktop.
Save lupyuen/c03870b103f51649dcf608ffb1bc9e6b to your computer and use it in GitHub Desktop.
Troubleshoot LoRaWAN on NuttX

Troubleshoot LoRaWAN on NuttX

Suppose our NuttX Device failed to join the LoRaWAN Network and send data packets. Let's walk through the steps to troubleshoot this...

Which LoRaWAN Gateway?

Which LoRaWAN Gateway are we using? ChirpStack or The Things Network?

The troubleshooting steps will be slightly different...

Verify Join Accept in LoRaWAN Gateway

Let's assume that we're using a ChirpStack LoRaWAN Gateway.

Verify that ChirpStack has received the Join Request packet and has returned a Join Accept packet...

https://lupyuen.github.io/articles/wisgate#inspect-the-raw-packets

For The Things Network: Check the logs and look for Join Request and Join Accept.

LoRaWAN is Time Sensitive

LoRaWAN is time sensitive, try to disable the logging...

https://lupyuen.github.io/articles/lorawan3#lorawan-is-time-sensitive

The LoRaWAN Gateway will return the Join Accept response in 5 to 6 seconds after the Join Request...

https://gist.github.com/lupyuen/1d96b24c6bf5164cba652d903eedb9d1

That's a one-second window for receiving the Join Accept response.

If our device is too busy and we miss the Receive Window, we won't be able to join the LoRaWAN Network.

Modify Receive Window

To check whether we missed the Receive Window (perhaps because our device was too busy), we reduce RxWindow1Delay from the default 5 seconds to 4 seconds.

This means that our device will start listening earlier for the Join Accept response, at 4 seconds after sending the Join Request. (Instead of the default 5 seconds)

Edit nuttx/libs/liblorawan/src/mac/LoRaMac.c

Override RxWindow1Delay in ProcessRadioTxDone like this...

static void ProcessRadioTxDone( void )
{
    ////TODO: We override RxWindow1Delay so that we start RadioRx in 4 seconds 
    ////instead of default 5 seconds. Join Accept Response is returned in 5 to 6 seconds
    ////but somehow the default 5 seconds will miss the Join Accept Response.
    ////See https://gist.github.com/lupyuen/1d96b24c6bf5164cba652d903eedb9d1
    puts("Warning: Override RxWindow1Delay to 4 seconds");  ////TODO
    MacCtx.RxWindow1Delay = 4000;  ////TODO
    printf("ProcessRadioTxDone: RxWindow1Delay=%d\n", MacCtx.RxWindow1Delay);  ////TODO

(Source)

Retest and see whether it receives the Join Accept Response.

If it still fails, reduce RxWindow1Delay and retest.

The log should look like this...

###### =========== MLME-Request ============ ######
######               MLME_JOIN               ######
###### ===================================== ######

// We have just transmitted Join Request
IRQ_TX_DONE

// We sleep for 4 seconds (instead of default 5 seconds)
ProcessRadioTxDone: RxWindow1Delay=4000

// 4 seconds later, we listen for Join Accept response at 923.4 MHz
RadioSetChannel: freq=923400000

// We will listen for the next 3 seconds
RadioRx: timeout=3000

// We receive the Join Accept Response
IRQ_PREAMBLE_DETECTED
IRQ_HEADER_VALID
IRQ_RX_DONE

// We have successfully joined the LoRaWAN Network
###### =========== MLME-Confirm ============ ######
STATUS      : OK
OnJoinRequest
###### ===========   JOINED     ============ ######

(Source)

Here's what I did previously to troubleshoot the Receive Window...

https://codeberg.org/JF002/loramac-node/pulls/1

https://gist.github.com/lupyuen/1aa766ecae70d8fb83b3061476b97434

Verify Radio Frequency of Join Accept

Check the Radio Frequency of the Join Accept response that's transmitted by the LoRaWAN Gateway.

For ChirpStack: Click on the Join Accept response, look at txInfo → Frequency (like 923.4 MHz)...

https://lupyuen.github.io/images/Screenshot%202022-05-28%20093348.png

This should match the Radio Frequency that our device listens to for the Join Accept response...

###### =========== MLME-Request ============ ######
######               MLME_JOIN               ######
###### ===================================== ######

// We have just transmitted Join Request
IRQ_TX_DONE

// We sleep for 5 seconds (default)
ProcessRadioTxDone: RxWindow1Delay=4988

// 5 seconds later, we listen for Join Accept response at 923.4 MHz
RadioSetChannel: freq=923400000

// TODO: Verify the above Join Accept Radio Frequency
// in the ChirpStack / The Things Network log

// We will listen for the next 3 seconds
RadioRx: timeout=3000

// We receive the Join Accept Response
IRQ_PREAMBLE_DETECTED
IRQ_HEADER_VALID
IRQ_RX_DONE

// We have successfully joined the LoRaWAN Network
###### =========== MLME-Confirm ============ ######
STATUS      : OK
OnJoinRequest
###### ===========   JOINED     ============ ######

(Source)

I think the LoRaWAN Gateway alternates between 2 Radio Frequencies when transmitting the Join Accept response.

One of the frequencies should match.

Timer Issues

There's a slight possibility that the Timers are not working right on our device.

Observe with a stopwatch and verify that our device actually waits 5 seconds before receiving the Join Accept Response...

https://www.youtube.com/watch?v=JX7rWqWTOW4

At 0:43 in the video, we can see that our device waits 5 seconds before listening for the response (at 0:48 in the video).

Troubleshooting Tips

More troubleshooting tips...

https://lupyuen.github.io/articles/lorawan3#troubleshoot-lorawan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment