H
@oligauc
Can you tell what is wrong with this code then:
from network import LoRa
import socket
import binascii
import settings
import sys
import time
import pycom
LORA_FREQUENCY = 923000000
LORA_FREQ_ADD = 20000
LORA_GW_DR = "SF10BW125"
LORA_NODE_DR = 2
# 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.AS923, device_class=LoRa.CLASS_C)
# create an OTA authentication params
dev_eui = binascii.unhexlify('70b3d5499da97f9c')
app_eui = binascii.unhexlify('ADA4DAE3AC12676B')
app_key = binascii.unhexlify('11B0282A189B75B0B4D2D8C7FA38548B')
# set the 3 default channels to the same frequency (must be before sending the OTAA join request)
print('Adding channels')
lora.add_channel(0, frequency=923200000, dr_min=0, dr_max=5)
#join a network using OTAA
print('Joining...')
lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0, dr=LORA_NODE_DR)
#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 joined yet...')
print('Joined')
# remove all the non-default channels
print('Removing other channels')
for i in range(1, 16):
lora.remove_channel(i)
# 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, LORA_NODE_DR)
#test set unconfirmed.
s.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED, 0)
# make the socket blocking
s.setblocking(False)
time.sleep(5.0)
pkt = b'PKT #' + bytes([i])
print('Sending:', pkt)
s.send(pkt)
time.sleep(4)
print('Listening...')
while True:
rx, port = s.recvfrom(256)
if rx:
print('Received: {}, on port: {}'.format(rx, port))
time.sleep(1)