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

    lora.nvram example needed

    Scheduled Pinned Locked Moved LoPy
    nvramdeepsleeplopy nvramlopy lorawan
    8 Posts 6 Posters 2.5k Views 6 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.
    • L Offline
      luc hanneuse
      last edited by

      Hi,
      I've searched for some functioning example of lora.nvram and found none. Can someone send one ?
      It's absolutely needed for deepsleep function.

      L J 2 Replies Last reply Reply Quote 0
      • L Offline
        livius @luc hanneuse
        last edited by

        @luc-hanneuse said in lora.nvram example needed:
        alway look into official documentation. There is
        https://docs.pycom.io/chapter/firmwareapi/pycom/network/lora.html#loranvramsave
        https://docs.pycom.io/chapter/firmwareapi/pycom/network/lora.html#loranvramrestore
        https://docs.pycom.io/chapter/firmwareapi/pycom/network/lora.html#loranvramerase

        if you need save some custom information use
        https://docs.pycom.io/chapter/firmwareapi/pycom/pycom.html#pycomnvssetkey-value
        https://docs.pycom.io/chapter/firmwareapi/pycom/pycom.html#pycomnvsgetkey
        https://docs.pycom.io/chapter/firmwareapi/pycom/pycom.html#pycomnvserasekey

        think about people first, then computers

        L H 2 Replies Last reply Reply Quote 0
        • L Offline
          luc hanneuse @livius
          last edited by luc hanneuse

          @livius
          I read the documentation.
          I need a full example.

          I've a written a code and I tried to use those functions lora.nvram_save() and lora.nvram_restore() . But it doesn't seem to work. The "counter" of LoRaWan message reset.

          1 Reply Last reply Reply Quote 0
          • J Offline
            jcaron @luc hanneuse
            last edited by

            @luc-hanneuse

            It's quite simple... When you boot, lora.nvram_restore(). Before you go to sleep, lora.nvram_save().

            L 1 Reply Last reply Reply Quote 0
            • L Offline
              luc hanneuse @jcaron
              last edited by

              @jcaron
              That's what I'm doing.

              It's just a bit illogical for me, I've to try 5 or 6 different codes to find a working one. The place of the lora.nvram_restore() isn't obvious ... If I place it just after the lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868) then it's not working !

              My working example :

              print("deepsleep prog")
              
              from network import LoRa
              import socket
              import binascii
              import struct
              import time
              import utime #utime
              
              init_timer = time.time()
              
              # Initialize LoRa in LORAWAN mode.
              lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)
              
              
              # create an ABP authentication params
              dev_addr = struct.unpack(">l", binascii.unhexlify('00 00 00 00'.replace(' ','')))[0]
              nwk_swkey = binascii.unhexlify('000000000000000000000000000000000')
              app_swkey = binascii.unhexlify('000000000000000000000000000000000')
              
              print("start join LoRa")
              print(utime.localtime())#utime
              print(utime.time())#utime
              # 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)
              lora.nvram_restore() #strange place for the restore but working.
              
              # make the socket blocking
              # (waits for the data to be sent and for the 2 receive windows to expire)
              s.setblocking(True)
              
              while(True):
                  print(".")
                  # save the coordinates in a new variable
                  coord = l76.coordinates()
                  # verify the coordinates received
                  if coord == (None,  None) and time.time() < 200:
                      print("Getting Location...")
                      pycom.rgbled(0x7f7f00) #jaune
                      print(utime.time())#utime
                      continue
                  # send the Coordinates to LoRA
                  print("sending")
                  pycom.rgbled(0x0000ff) #bleu
                  s.send(struct.pack("<i",  int(coord[0]*100000))+struct.pack("<i",  int(coord[1]*100000))+struct.pack("<H",  int(utime.time())))
                  time.sleep(1)
                  lora.nvram_save() #nvram
                  print("sent")
                  print(time.time())
                  print(utime.localtime())#utime
                  print(utime.time())#utime
                  pycom.rgbled(0x000000)
                  #sleep
                  print("sleep")
                  py.setup_sleep(600 - time.time())
                  py.go_to_sleep()
              

              If someone has something smarter with an ABP connection, help me.

              1 Reply Last reply Reply Quote 0
              • H Offline
                han @livius
                last edited by

                @livius I also appreciate it when there comes a working example for the using of the nvram and restore function.
                Everybody at the forum is from do this but by the most of us it isn`t working either.

                1 Reply Last reply Reply Quote 2
                • T Offline
                  tuftec
                  last edited by

                  @luc-hanneuse did you manage to solve this issue.
                  I have a similar problem.
                  I have place the lora.nvram_restore() after my lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AU915) command. This seems like the logical place to put it.
                  However after waking from sleep a few times, it appears that restore does not work correctly.

                  I am also having problems making the app_eui and app_key available for use between different functions (def) within the same file/module. I am using global app_eui, app_key in both functions but I get an error after waking with app_eui undefined!!!! Any ideas??

                  Peter.

                  1 Reply Last reply Reply Quote 0
                  • G Offline
                    goldfishalpha
                    last edited by

                    I know this is an old post but for me this is still an issue.
                    Any may of learning more about the specifics would be very much appreciated e.g what does

                    pycom.nvs_get(key) 
                    

                    return?
                    Should I see somthing in the REPL?
                    Example:

                    >>> lora.nvram_save()
                    >>> l= pycom.nvs_get('lora')
                    >>> print(l)
                    None
                    

                    Am I going about this in completely the wrong way?

                    1 Reply Last reply Reply Quote 0

                    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