Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
77 lines (63 sloc) 2.15 KB
#!/usr/bin/env python
# Copyright (c) 2019, Pycom Limited.
# This software is licensed under the GNU GPL version 3 or any
# later version, with permitted additional terms. For more information
# see the Pycom Licence v1.0 document supplied with this file, or
# available at
""" OTAA Node example compatible with the LoPy Nano Gateway """
from network import LoRa
import socket
import binascii
import struct
import time
import config
# initialize 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 OTA authentication params
dev_eui = binascii.unhexlify('AABBCCDDEEFF7778')
app_eui = binascii.unhexlify('70B3D57EF0003BFD')
app_key = binascii.unhexlify('36AB7625FE770B6881683B495300FFD6')
# remove all the channels
for channel in range(0, 72):
# set all channels to the same frequency (must be before sending the OTAA join request)
for channel in range(0, 72):
lora.add_channel(channel, frequency=config.LORA_FREQUENCY, dr_min=0, dr_max=3)
# join a network using OTAA
lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0, dr=config.LORA_NODE_DR)
# wait until the module has joined the network
join_wait = 0
while True:
if not lora.has_joined():
print('Not joined yet...')
join_wait += 1
if join_wait == 5:
lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0, dr=config.LORA_NODE_DR)
join_wait = 0
# 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, config.LORA_NODE_DR)
# make the socket non-blocking
for i in range (200):
pkt = b'PKT #' + bytes([i])
print('Sending:', pkt)
rx, port = s.recvfrom(256)
if rx:
print('Received: {}, on port: {}'.format(rx, port))
You can’t perform that action at this time.