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

    nvram lopy Errno 100

    Scheduled Pinned Locked Moved LoPy
    lopypysenseerror
    12 Posts 4 Posters 2.1k Views 4 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
      han
      last edited by

      Re: lora.nvram example needed

      Hello Pioneers,

      I am using the Lopy to send data from the pysense and a external sensor.
      When I work without the lora.nvram_restore() & save() function, it works fine but the module does not connect after coming out of deepsleep.

      When i use the nvram function there pops up a error message: OSError:
      File "main.py", line 74, in <module>
      [Errno 100] ENETDOWN

      Line 74 is "s.send(enc)"

      Does somebody know how to resolve this?
      I am using a LoPy and a Pysense with the newest firmware version.
      Atom 1.25.0 and Pymakr plugin 1.2.11.
      On KPN LoRa network

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

        @han Can you provide the relevant parts of your code? My guess is that you don't have the nvram_save and nvram_restore calls in the right places, but it's hard to tell without code...

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

          Hello @jcaron
          This is my code.

          # LoRaWAN (ABP)
          from network import LoRa
          from mqtt import MQTTClient
          import socket
          import binascii
          import struct
          import time
          from deepsleep import DeepSleep
          
          import ujson
          
          import gc
          
          from pysense import Pysense
          from SI7006A20 import SI7006A20
          from LTR329ALS01 import LTR329ALS01
          from MPL3115A2 import MPL3115A2,ALTITUDE,PRESSURE
          
          py = Pysense()
          mp = MPL3115A2(py,mode=ALTITUDE)
          mpp = MPL3115A2(py,mode=PRESSURE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals
          si = SI7006A20(py)
          lt = LTR329ALS01(py)
          ds = DeepSleep()
          
          gc.enable()
          
          # 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('xxxxxx'.replace(' ','')))[0]
          nwk_swkey = binascii.unhexlify('xxxxxxx'.replace(' ',''))
          app_swkey = binascii.unhexlify('xxxxxxx'.replace(' ',''))
          
          # join a network using ABP (Activation By Personalization)
          lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
          print('Joined LoRa network')
          
          # wait until the module has joined the network
          while not lora.has_joined():
              time.sleep(2.5)
              print('Not joined yet...')
          
          # remove all the non-default channels
          for i in range(3, 16):
              lora.remove_channel(i)
          
          # 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()
          
          # make the socket blocking
          # (waits for the data to be sent and for the 2 receive windows to expire)
          s.setblocking(True)
          
          time.sleep(5)
          
          for i in range (200):
              mqData = {}
              gc.collect()
              mqData ["data"] = {}
              mqData ["data"]["Temperature"] = mp.temperature()
              mqData ["data"]["Pressure"] = (mpp.pressure()/100)
              mqData ["data"]["Relative Humidity"] = si.humidity()
              mqData ["data"]["Battery voltage"] = py.read_battery_voltage()
              enc = ujson.dumps(mqData)
              gc.collect()
              s.send(enc)
              print('STA node sending packet ...')
              time.sleep(5)
              nvram_save()
              print("ready to DeepSleep")
              time.sleep(1)
              print("Going to DeepSleep")
              py.setup_sleep(15*60)
              py.go_to_sleep()
          

          code

          robert-hhR J 2 Replies Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @han
            last edited by

            @han if you enclose your code in line with three backticks (```), the structure is maintained.

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

              @robert-hh Thanks for the tip. I will do it the next time when I have to upload a piece of code.

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

                @han not sure about ABP but for OTAA you definitely don’t join every time. You should just do nvram_restore() just after you create the lora object, and only join if has.joined() returns false.

                robert-hhR H 2 Replies Last reply Reply Quote 0
                • robert-hhR Offline
                  robert-hh @jcaron
                  last edited by

                  @jcaron As far as I could see it, there is no actual communication done for ABP join. Just the device ID and the respective keys are set in the MAC layer.
                  Either way, nvram_save() and nvram_restore() should be used to ensure the monotonic increase of the packet counters.

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

                    @jcaron
                    What do I have to do to make it work?

                    If I deleted the deepsleep part it work fine, but with the deepsleep the LoPy will not join again.

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

                      @han As I said, move the lora.nvram_restore() just after creating of the loraobject, then test if lora.has_joined() and only do the join and probably the channel stuff if it has not joined yet.

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

                        @jcaron did you find anything strange in my code?

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

                          @jcaron
                          as I understood your tips.
                          Then should it be something like this. Right?

                          # LoRaWAN (ABP)
                          
                          from network import LoRa
                          import socket
                          import binascii
                          import struct
                          import time
                          import pycom
                          from deepsleep import DeepSleep
                          
                          import ujson
                          
                          import gc
                          
                          from pysense import Pysense
                          from SI7006A20 import SI7006A20
                          from LTR329ALS01 import LTR329ALS01
                          from MPL3115A2 import MPL3115A2,ALTITUDE,PRESSURE
                          
                          py = Pysense()
                          mp = MPL3115A2(py,mode=ALTITUDE)
                          mpp = MPL3115A2(py,mode=PRESSURE)
                          si = SI7006A20(py)
                          lt = LTR329ALS01(py)
                          ds = DeepSleep()
                          
                          gc.enable()
                          
                          loraSaved = pycom.nvs_get('loraSaved')
                          
                          if not loraSaved:
                              # 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('14 20 36 XX'.replace(' ','')))[0]
                              nwk_swkey = binascii.unhexlify('d0 ad 96 bb 95 0c b1 72 6a a4 3f 85 2f 4a XX XX'.replace(' ',''))
                              app_swkey = binascii.unhexlify('d5 ac 3b 1c 70 6c f8 2a 46 f2 2f eb 57 12 XX XX'.replace(' ',''))
                          
                              # join a network using ABP (Activation By Personalization)
                              lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
                              print('Joining the LoRa network')
                          
                              # wait until the module has joined the network
                              while not lora.has_joined():
                                  time.sleep(2.5)
                                  print('Not joined yet...')
                                  machine.idle()
                          
                              # 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
                              s.setblocking(False)
                          
                              time.sleep(5)
                          
                              s.send('LoRa Saved')
                              print("LoRa saved")
                          
                              time.sleep(5)
                              lora.nvram_save()
                              pycom.nvs_set('loraSaved', 1)
                          
                              time.sleep(5)
                          
                          else:
                              lora = LoRa(mode=LoRa.LORAWAN)
                              lora.nvram_restore()
                          
                              s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
                          
                              s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
                          
                              s.setblocking(False)
                              mqData = {}
                              gc.collect()
                              mqData ["m"] = {}
                              mqData ["m"]["T"] = mp.temperature()
                              mpp = MPL3115A2(py,mode=PRESSURE)
                              mqData ["m"]["P"] = (mpp.pressure()/100)
                              mqData ["m"]["H"] = si.humidity()
                              mqData ["m"]["B"] = py.read_battery_voltage()
                              enc = ujson.dumps(mqData)
                              gc.collect()
                              s.send(enc)
                              pycom.nvs_set('loraSaved', 0) # reset for next test
                              print('STA node sending packet ...')
                              print(enc)
                              print('LoRa data saved')
                              time.sleep(5)
                              print("Going to DeepSleep")
                              ds.enable_pullups('P17')  # can also do ds.enable_pullups(['P17', 'P18'])
                              ds.enable_wake_on_fall('P17') # can also do ds.enable_wake_on_fall(['P17', 'P18'])
                              ds.go_to_sleep(30*60)  # go to sleep for 15 minutes
                          
                          # get any data received...
                          data = s.recv(64)
                          print(data)
                          
                          

                          I still have the errno 100 error code. This time on rule 89.

                          1 Reply Last reply Reply Quote 0
                          • F Offline
                            ferfersan6
                            last edited by

                            Hey! Did you solve it? I am having the same problem... Can't fix it. Thanks!

                            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