Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Lorawan ABP Frame counts

    Scheduled Pinned Locked Moved LoPy
    lopy4lorawan abplorawan otaalopy loralopy lorawan
    6 Posts 3 Posters 1.3k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Harish kumar
      last edited by Harish kumar

      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.

      J robert-hhR 2 Replies Last reply Reply Quote 0
      • J Offline
        jcaron @Harish kumar
        last edited by

        @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.

        H 1 Reply Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh @Harish kumar
          last edited by robert-hh

          @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.

          H 1 Reply Last reply Reply Quote 0
          • H Offline
            Harish kumar @jcaron
            last edited by

            @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)
            s.setblocking(True)
            
            # get any data received...
            data = s.recv(64)
            print(data)
            
            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)
            lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
            
            # 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
            # (waits for the data to be sent and for the 2 receive windows to expire)
            s.setblocking(True)
            
            # send some data
            s.send(data)
            print('data sent')
            
            J 1 Reply Last reply Reply Quote 0
            • H Offline
              Harish kumar @robert-hh
              last edited by

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

              1 Reply Last reply Reply Quote 0
              • J Offline
                jcaron @Harish kumar
                last edited by

                @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.).

                1 Reply Last reply Reply Quote 1

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • 1 / 1
                • First post
                  Last post

                Pycom on Twitter

                Pycom