Although Pycom states they utilize The Things Network, I could not ‘join’ my FiPy device. I suspect no coverage near me. However, I also have been trying senet using its appEUI and appKEY. Still will not connect. My device is registered at portal.senetco.io (my device appears on the dashboard) and am using below example code. Please help.
from network import LoRa
import socket
import time
import ubinascii
Initialise LoRa in LORAWAN mode.
United States = LoRa.US915
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.US915)
create an OTAA authentication parameters
app_eui = ubinascii.unhexlify(‘00250C000XXXXXX’)
app_key = ubinascii.unhexlify(‘9014A658F6B2CB462745D66CXXXXXXXX’)
initialize LoRa
lora.init(mode=LoRa.LORAWAN, adr=True, public=True)
join a network using OTAA (Over the Air Activation)
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), dr=0, 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 LoRaWAN, ',lora.has_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) # for OTAA
#s.setblocking(False) # for ABP
send some data
print(‘Sending 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) # for OTAA
get any data received (if any…)
data = s.recv(64)
print(data)