pycom.wifi_on_boot(False) pycom.heartbeat(False) lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868, bandwidth=LoRa.BW_125KHZ, sf=7) MAC = str(ubinascii.hexlify(lora.mac()))[2:-1] print("LoRa MAC: %s" % MAC) mesh = Loramesh(lora) # waiting until it connected to Mesh network and # it has some valid neighbors while True: mesh.led_state() print("%d: State %s, single %s" % (time.time(), mesh.cli('state'), mesh.cli('singleton'))) time.sleep(2) if not mesh.is_connected(): continue neigbors = mesh.neighbors_ip() if len(neigbors) == 0: print('No neighbor') continue print('Neighbors found: %s' % neigbors) break # create UDP socket s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) myport = 1234
from loramesh import Loramesh pycom.wifi_on_boot(False) pycom.heartbeat(False) lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868, bandwidth=LoRa.BW_125KHZ, sf=7) MAC = str(ubinascii.hexlify(lora.mac()))[2:-1] print("LoRa MAC: %s"%MAC) mesh = Loramesh(lora) # waiting until it connected to Mesh network while True: mesh.led_state() print("%d: State %s, single %s"%(time.time(), mesh.cli('state'), mesh.cli('singleton'))) time.sleep(2) if not mesh.is_connected(): continue print('Neighbors found: %s'%mesh.neighbors()) break # create UDP socket sockets = [] s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) myport = 1234 s.bind(myport) sockets.append(s) # handler responisble for receiving packets on UDP Pymesh socket