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

    Connecting FiPy to TTN with Dragino Gateway

    Scheduled Pinned Locked Moved FiPy
    1 Posts 1 Posters 50 Views 1 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.
    • B Offline
      bluegnome
      last edited by

      I am pretty new to python and iOT but hoping to make some headway in basic testing. Using a FiPy connected to a PySense and looking to connect it to the Things Network via my Dragino LG01-N gateway. Far as I can tell the gateway is setup correctly. Its on the 915 Mhz Band (im in canada) and showing as "online" in TTN.

      Below is my code I am running to just test the connection from the PySense/FiPy via LoRa to TTN. Can anyone see an obvious errors or things I am missing? When I Run the code i just prints "not joined" continuously and never sees the gateway which it is sitting right next to in the office.

      from network import LoRa
      import socket
      import time
      import ubinascii

      Initialise LoRa in LORAWAN mode.

      Please pick the region that matches where you are using the device:

      Asia = LoRa.AS923

      Australia = LoRa.AU915

      Europe = LoRa.EU868

      United States = LoRa.US915

      lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.US915)

      create an OTAA authentication parameters, change them to the provided credentials

      app_eui = ubinascii.unhexlify('myappeui')
      app_key = ubinascii.unhexlify('myappkey')
      #uncomment to use LoRaWAN application provided dev_eui
      #dev_eui = ubinascii.unhexlify('')

      join a network using OTAA (Over the Air Activation)

      #uncomment below to use LoRaWAN application provided dev_eui
      lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
      #lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0)

      wait until the module has joined the network

      while not lora.has_joined():
      time.sleep(2.5)
      print('Not yet joined...')

      print('Joined')

      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

      s.send(bytes([0x01, 0x02, 0x03]))

      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)
      print(data)

      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