Hello,
not sure what i am missing but i can’t get my lora node on lopy 4 to work. I have pasted my code below but when i run it i first get the error -
Traceback (most recent call last):
File “”, line 7, in
ImportError: no module named ‘config’
so i comment out the line ‘import config’ and then i get the next error -
Traceback (most recent call last):
File “”, line 12, in
AttributeError: type object ‘LoRa’ has no attribute ‘AU915’
what am i missing?
I have updated firmware and i successfully built the gateway following your tutorial so not sure what i’m doing wrong this time.
from network import LoRa
import socket
import binascii
import struct
import time
import config
LORA_FREQUENCY = 916800000
LORA_NODE_DR = 5
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AU915) # Australia
# create an ABP authentication params
dev_addr = struct.unpack(">l", binascii.unhexlify('number i got from TTN'))[0]
nwk_swkey = binascii.unhexlify('a really long number from TTN'')
app_swkey = binascii.unhexlify('as above another long number'')
# remove all the non-default channels
for i in range(0, 72): # Australia
lora.remove_channel(i)
# set the 3 default channels to the same frequency
lora.add_channel(0, frequency=LORA_FREQUENCY, dr_min=0, dr_max=5)
lora.add_channel(1, frequency=LORA_FREQUENCY, dr_min=0, dr_max=5)
lora.add_channel(2, frequency=LORA_FREQUENCY, dr_min=0, dr_max=5)
# join a network using ABP (Activation By Personalization)
lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
# 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 blocking
s.setblocking(False)
for i in range (200):
pkt = b'PKT #' + bytes([i])
print('Sending:', pkt)
s.send(pkt)
time.sleep(4)
rx, port = s.recvfrom(256)
if rx:
print('Received: {}, on port: {}'.format(rx, port))
time.sleep(6)