def __init__(self, meshaging, lora=None): """ Constructor """ if lora is None: # lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868, # bandwidth=LoRa.BW_125KHZ, sf=7) lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868, frequency=863000000, bandwidth=LoRa.BW_500KHZ, sf=7) self.lora = lora # enable Thread interface self.mesh = Loramesh(self.lora) self.MAC = self.mesh.MAC self.sock = None self.leader_ts = -self.LEADER_INTERVAL self.router_ts = 0 self.leader_data_ok = False self.interrogate_leader_ts = -self.LEADER_INTERVAL self.messages = meshaging self.send_table = {} self.rx_cb_registered = False self.file_packsize = 0 self.file_size = 0 self.send_f = None pass
def __init__(self, meshaging, config, message_cb): """ Constructor """ # enable Thread interface self.mesh = Loramesh(config) self.MAC = self.mesh.MAC self.sock = None self.leader_ts = -self.LEADER_INTERVAL self.router_ts = 0 self.leader_data_ok = False self.interrogate_leader_ts = -self.LEADER_INTERVAL self.messages = meshaging self.send_table = {} self.rx_cb_registered = False self.file_packsize = 0 self.file_size = 0 self.send_f = None self.br_handler = None self.EXTERNAL_IP = self.EXTERNAL_NET + hex(self.MAC & 0xFFFF)[2:] self.ext_mesh_ts = -30 self.message_cb = message_cb self.br_message_cb = None pass
from loramesh import Loramesh from Networkmesh import * pycom.wifi_on_boot(False) pycom.heartbeat(False) lora = LoRa(mode=LoRa.LORA, region=LoRa.US915, tx_power=20, bandwidth=LoRa.BW_125KHZ, sf=11) print(lora.tx_power()) #lora = LoRa(mode=LoRa.LORA, region=LoRa.US915, bandwidth=LoRa.BW_125KHZ, sf=11) #lora = LoRa(mode=LoRa.LORA, region=LoRa.US915,frequency=903000000,tx_power=19, bandwidth=LoRa.BW_125KHZ, sf=12) MAC = str(ubinascii.hexlify(lora.mac()))[2:-1] print("LoRa MAC: %s" % MAC) loram = Loramesh(lora) mesh = NetworkMesh(loram, MAC, 1) #-------------------------------------------------------------------------------- # waiting until it connected to Mesh network # se queda intentando conectarse y muestra los vecinos mesh.connect() # create UDP socket #creo un socket LoRa mesh.createSocket(1234) # infinite main loop #funcion principal mesh.listen()
import time import utime import ubinascii import pycom import machine 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 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