Skip to content

Instantly share code, notes, and snippets.

@tairea tairea/
Created Apr 18, 2017

What would you like to do?
LoPy node
""" OTAA Node example compatible with the LoPy Nano Gateway """
from network import LoRa
import socket
import binascii
import struct
import time
# Initialize LoRa in LORAWAN mode.
lora = LoRa(mode=LoRa.LORAWAN)
# create an OTA authentication params
dev_eui = binascii.unhexlify('70B3D5499852A8CB'.replace(' ',''))
app_eui = binascii.unhexlify('70B3D57EF0004674'.replace(' ',''))
app_key = binascii.unhexlify('9897E97CE0FBD2224AC559EDD224BB67'.replace(' ',''))
# instead of set the 3 default channels to the same frequency. loop to remove all existing channels add just one - @jmarcelino
for channel in range(0, 72):
lora.add_channel(0, frequency=915100000, dr_min=0, dr_max=4)
# join a network using OTAA
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():
print('Not joined yet...')
# remove all the non-default channels
for i in range(3, 16):
# 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
for i in range (200):
s.send(b'PKT #' + bytes([i]))
rx = s.recv(256)
if rx:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.