from network import LoRa import socket import time import binascii # use the LoRaWAN stack lora = LoRa(mode=LoRa.LORAWAN) app_eui = binascii.unhexlify('5F4170704555495F') app_key = binascii.unhexlify('5F4170706C69636174696F6E4B65795F') # join by OTAA print("Ask OTAA") lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0) # wait for network to accept OTAA for wait_time in [2,4,6,8,10]: if not lora.has_joined(): time.sleep(2) print("Waited {}s".format(wait_time)) else: break while not lora.has_joined(): time.sleep(1) if lora.has_joined(): # socket setup out = socket.socket(socket.AF_LORA, socket.SOCK_RAW) out.setsockopt(socket.SOL_LORA, socket.SO_DR, 5) # send your first data! print(out.send("Hello world!")) # log how many bytes are sent else: print("Could not join by OTAA")