from loranode import RN2483Controller from commands import * import time # LoRaController OTAA based join and message test if __name__ == "__main__": set_debug_level(Level.DEBUG) port = "COM3" appkey = "58FF3007CAED02xxxxxxxxxxxxxxxxxxxx" appeui = "70B3D57Exxxxxxxxxxxxxx" deveui = "0004A30xxxxxxxxxxx" # Test controller lc = RN2483Controller(port) if lc.test(): printd("[+] Connected to LoRa RN2483 device", Level.INFO) lc.serial_sr(CMD_GET_VERSION) lc.serial_sr(CMD_GET_HWEUI) lc.get_freq() else: printd(clr(Color.YELLOW, "[-] Failed to get version from LoRa device"), Level.WARNING) lc.set_pwr(15) lc.set_adr(False) lc.serial_sr(CMD_SET_SF, "sf7") # sf12, sf7 # Join and send a message if lc.join_otaa(appkey, appeui, deveui): printd("[+] Connected to gateway", Level.INFO) # Data-1 printd("[+] Sending packet #1", Level.INFO) timeStr = time.strftime("%H%M", time.gmtime()) if lc.send(timeStr, ack=False): printd(clr(Color.GREEN, "[+] Send-1 succeeded"), Level.CRITICAL) else: printd(clr(Color.RED, "[+] Send-1 failed"), Level.CRITICAL) time.sleep(15) # Data-2 printd("[+] Sending packet #2", Level.INFO) timeStr = time.strftime("%H%M", time.gmtime()) if lc.send(timeStr, ack=False): printd(clr(Color.GREEN, "[+] Send-2 succeeded"), Level.CRITICAL) else: printd(clr(Color.RED, "[+] Send-2 failed"), Level.CRITICAL) time.sleep(15) del lc exit() del lc printd(clr(Color.RED, "[-] Test failed"), Level.CRITICAL)
from loranode import RN2483Controller import platform from commands import * import time # LoRaController ABP based join and ACK test if __name__ == "__main__": set_debug_level(Level.DEBUG) port = "COM3" nwkskey = "58AA52E96035Axxxxxxxxxxxxxxxxxxxx" appskey = "381B1C9206E9BE9xxxxxxxxxxxxxxxxxxx" devaddr = "B639xxxx" lc = None try: # Test controller lc = RN2483Controller(port) if lc.test(): printd("[+] Connected to LoRa RN2483 device", Level.INFO) lc.serial_sr(CMD_GET_VERSION) lc.serial_sr(CMD_GET_HWEUI) lc.get_freq() else: printd(clr(Color.YELLOW, "[-] Failed to get version from LoRa device"), Level.WARNING) except Exception, e: print "Error: " + str(e) if lc is None: printd(Color.YELLOW, "Error: cannot connect to device") exit() lc.set_adr(False) lc.set_pwr(15) lc.serial_sr(CMD_MAC_PAUSE) lc.serial_sr(CMD_SET_SF, "sf12") # sf12, sf7 lc.serial_sr(CMD_MAC_RESUME) # Join and send a message if lc.join_abp(nwkskey, appskey, devaddr): printd("[+] Connected to gateway", Level.INFO) # Data-1 printd("[+] Sending packet #1", Level.INFO) timeStr = time.strftime("%H%M", time.gmtime()) if lc.send(timeStr, ack=False): printd(clr(Color.GREEN, "[+] Send-1 succeeded"), Level.CRITICAL) else: printd(clr(Color.RED, "[+] Send-1 failed"), Level.CRITICAL) time.sleep(15) # Data-2 printd("[+] Sending packet #2", Level.INFO) timeStr = time.strftime("%H%M", time.gmtime()) if lc.send(timeStr, ack=False): printd(clr(Color.GREEN, "[+] Send-2 succeeded"), Level.CRITICAL) else: printd(clr(Color.RED, "[+] Send-2 failed"), Level.CRITICAL) time.sleep(15) del lc exit() printd(clr(Color.RED, "[-] Test failed"), Level.CRITICAL) del lc
Source: https://habr.com/ru/post/398247/