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

    Cannot join using OTAA using AU915

    Scheduled Pinned Locked Moved LoPy
    6 Posts 3 Posters 37 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.
    • snorkmanS Offline
      snorkman
      last edited by Gijs

      Greetings from Argentina :-)
      I had my code working fine when I was working in EU and with TTN for months. Now I moved to this side of the globe and therefore had to re configure my LoPy’s firmware.
      My main issue right now is that the node never goes beyond the activation, it is always prompting:
      3e69dc4d-afec-410b-bd10-0babe78400b0-image.png

      My GW is a Dragino LG308 multichannel. Do you see anything wrong in the config?

      cace71df-5a25-4235-80a5-643cef845689-image.png

      4673496e-4236-420c-98d1-5dc88404227c-image.png

      and my code running on the LoPy looks like

      from network import LoRa
      import socket
      import time
      import ubinascii
      import machine
      import pycom
      pycom.heartbeat(False)
      
      adc = machine.ADC()
      
      # create an OTAA authentication parameters
      APP_EUI = ubinascii.unhexlify('bbbbbbb')
      APP_KEY = ubinascii.unhexlify('aaaaaaaaa')
      
      def enter_deepsleep(interval=1):
          lora.nvram_save()
          print("Deep Sleeping for {0} minutes".format(interval))
          machine.deepsleep(interval * 60000)
          print("AWAKE!!! entering normal operation mode")
      
      def connect_to_ttn(lora_object):
          """Receives a lora object and tries to join"""
          # join a network using OTAA (Over the Air Activation)
          lora_object.join(activation=LoRa.OTAA, auth=(APP_EUI, APP_KEY), timeout=0)
          # wait until the module has joined the network
          while not lora_object.has_joined():
              time.sleep(1)
              print('Not yet joined...')
              pycom.rgbled(0xff0000)
      
      def get_supercap_voltage():
          samples = []
          supercap_pin = adc.channel(pin='P13', attn=adc.ATTN_11DB)   #analog pin on P13
          for sample in range(20):
              val = supercap_pin()# read an analog value
              samples.append(val)
              time.sleep_ms(1)
          average = sum(samples)/len(samples)
          return average
      
      def compress_analog_reading_payload(mediciones):
           payload = 0
           tribble_shifts = len(mediciones) - 1
           for medicion in mediciones:
               payload = payload | (medicion << (12 * tribble_shifts))
               tribble_shifts -=1
           return(payload)
      
      # Initialise LoRa in LORAWAN mode.
      # Please pick the region that matches where you are using the device:
      # United States = LoRa.US915
      #lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)
      lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AU=915)
      for index in range(0, 8): lora.remove_channel(index)
      for index in range(16, 65): lora.remove_channel(index)
      for index in range(66, 72): lora.remove_channel(index)
      
      lora.nvram_restore() #if there is nothing to restore it will return a False
      
      if not lora.has_joined():
          connect_to_ttn(lora)
      else:
          print("CONNECTED!!")
          pycom.rgbled(0x00ff00)
          lora.nvram_erase()
      
      # 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, 3)
      
      # 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
      while lora.has_joined():
          supercap_voltage = int(get_supercap_voltage())
          s.setblocking(True)
          payload = compress_analog_reading_payload([1700, 1000, 2800, 300, supercap_voltage])
          payload_in_bytes = list(payload.to_bytes(8, 'big'))
          s.send(bytes(payload_in_bytes))
      
      # make the socket non-blocking
      #(because if there's no data received it will block forever...)
          s.setblocking(False)
      
      # get any data received (if any...)
          data = s.recv(64)
      
          if data:##print(data)
              pycom.rgbled(0xff0000)
              time.sleep(0.5)
              pycom.rgbled(0x00ff00)
              time.sleep(0.5)
              pycom.rgbled(0x0000ff)
              time.sleep(0.5)
          print(data)
          enter_deepsleep(5)
      

      and the firmware running on the LoPy:

      >>> os.uname()
      (sysname='LoPy4', nodename='LoPy4', release='1.20.2.r2', version='v1.11-3a7776d on 2020-11-23', machine='LoPy4 with ESP32', lorawan='1.0.2', sigfox='1.0.1', pybytes='1.6.1')
      

      Am I doing something wrong?

      robert-hhR 1 Reply Last reply Reply Quote 0
      • G Offline
        Gijs
        last edited by

        Hi,

        From your TTN logs, it seems the gateway is receiving a join request (yellow lightning bolt), and sending out a join accept (green lightning bolt). And that seems to work fine! Also the time difference (4 seconds) is similar to what Im getting here. I dont actually know if the message is sent out (maybe you can look at the terminal of the dragino gateway?). Also, verify the settings with the settings mentioned here: https://github.com/TheThingsNetwork/gateway-conf/blob/master/AU-global_conf.json

        In your code, I found a typo here: lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AU=915) at AU=915. Other than that, I cant really tell anything wrong.

        snorkmanS 1 Reply Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh @snorkman
          last edited by

          @snorkman Which TTN router do you use? There were posts here telling that the Australian router was very slow. Maybe you could try other routers.

          snorkmanS 2 Replies Last reply Reply Quote 0
          • snorkmanS Offline
            snorkman @robert-hh
            last edited by

            @robert-hh I was using the default one for Australia. Iwill try with a different on and keep you posted.

            1 Reply Last reply Reply Quote 0
            • snorkmanS Offline
              snorkman @Gijs
              last edited by

              @Gijs yeah that was a typo when I did C&P.
              I am using a Dragino LG308

              1 Reply Last reply Reply Quote 0
              • snorkmanS Offline
                snorkman @robert-hh
                last edited by

                @robert-hh
                It seems like a firmware upgrade on the LG308 did the job.
                The code is working fine and I can successfully join the network without retrials.

                1e386495-77b7-43c2-be79-44b46086f4c1-image.png

                Thanks!

                1 Reply Last reply Reply Quote 3

                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