Lorawan ABP Frame counts

  • Hi Everyone !
    I send data from Pycom to cloud through Lorawan ABP. But whenever I send I have to reset the frame counts. So I need to know how to change the Frame counts in ABP pycom ?
    Thank you in Advance.

  • @harish-kumar Well, you're not sleeping, so you shouldn't need to nvram_save/restore, but you're re-creating the LoRa object (twice!) in your loop, using two different modes (raw LoRa and LoRaWAN), and re-joining each time, so no wonder your frame counters get re-initialised.

    I'm really not sure you can use the current LoRa stack like this to achieve what you want. I'm quite certain it would require some extensive changes to the stack, especially if you really want to maintain true LoRaWAN compatibility (i.e. including ADR, MAC commands, etc.).

  • Hi @robert-hh Thanks for you reply. I got it now.

  • @jcaron Thanks for your reply. This is my code. I mean like saying whenever I go to TTN console, previous data are stored there, so I have to reset the frame counts to see my new data.

    from network import LoRa
    import socket
    import binascii
    import struct

    while True:

    lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868, sf = 7, frequency = 868500000)
    # create a raw LoRa socket
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    # get any data received...
    data = s.recv(64)
    lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868,  sf = 12)
    # create an ABP authentication params
    dev_addr = struct.unpack(">l", binascii.unhexlify('26010000'))[0]
    nwk_swkey = binascii.unhexlify('9A51C4DD083444A24000000000000000')
    app_swkey = binascii.unhexlify('7DF13A7CD2B2AA078000000000000000')
    # join a network using ABP (Activation By Personalization)
    # create a LoRa socket
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    # set the LoRaWAN data rate
    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
    # make the socket blocking
    # send some data
    print('data sent')

  • @harish-kumar In order to get proper frame counts through resets, you have to use lora.nvram_save() to save the Lora communication parameters before a shutdown and use lora.nvram_restore() to retrieve these on the next startup. That restores also also the session keys, so you do not need to join again after a successful nvram_restore(). See https://docs.pycom.io/chapter/firmwareapi/pycom/network/lora.html
    For testing, you can also disable in both the TTN or Loriot console the sequence number checking.

  • @harish-kumar Why do you need to reset the frame counters? Or do you mean they are reset instead of increasing?

    Are you using deep sleep? If so, are you using nvram_save / nvram_restore? Please share your code and clarify what you currently get and what you want to get.

Pycom on Twitter