def do_loop(lora): global msgCount lastSendTime = 0 interval = 0 NODE_NAME = config_lora.get_nodename() while True: now = config_lora.get_millis() if now < lastSendTime: lastSendTime = now if (now - lastSendTime > interval): lastSendTime = now # timestamp the message interval = (lastSendTime % INTERVAL) + INTERVAL_BASE # 2-3 seconds message = gen_message(NODE_NAME, msgCount, now) sendMessage(lora, message) # send message key = '{}_{}'.format(NODE_NAME, msgCount) messages[key] = {'node': NODE_NAME, 'msgCount': msgCount, 'ping': now, 'pong': None, 'done': False, 'elipse': None} msgCount += 1 lora.receive() # go back into receive mode
def ping_pong(lora): display = Display() display.show_text_wrap("LoRa Duplex with callback {0}".format(config_lora.get_nodename())) time.sleep(5) lora.onReceive(on_receive) # register the receive callback do_loop(lora)
def ping_pong(lora): display = Display() display.show_text_wrap("LoRa Duplex with callback, my name is Tamas{0}".format(config_lora.get_nodename())) # display.show_text_wrap("Nemsokara beindul a vibrator") time.sleep(5) lora.onReceive(on_receive) # register the receive callback do_loop(lora)
def do_loop(lora): global msgCount lastSendTime = 0 interval = 0 while True: now = config_lora.get_millis() if (now - lastSendTime > interval): lastSendTime = now # timestamp the message interval = (lastSendTime % INTERVAL) + INTERVAL_BASE # 2-3 seconds message = "{} {}".format(config_lora.get_nodename(), msgCount) print(interval, 'interval') sendMessage(lora, message) # send message msgCount += 1 lora.receive() # go into receive mode
# gps uart = UART(1, rx=34, tx=17) # init with given baudrate uart.init(9600, bits=8, parity=None, stop=1) # init with given parameters my_gps = MicropyGPS() # wlan station = network.WLAN(network.STA_IF) if (settings['status'] == _booting): sensor.enable_irq_mode() #machine.freq(80000000) #machine.idle() settings['status'] = _sleeping lastUpdateTimes = [0, 0, 0, 0, 0, 0] NODE_NAME = config_lora.get_nodename() data = { 'nodes': [], 'imu': [], 'satellites': 0, 'gps': [], 'speed': "", 'time': [] } def update_data(): global config_lora, station, my_gps, sensor, data, intervalUpdates, lastUpdateTimes now = config_lora.get_millis()
import machine, json, gc, time from machine import Pin import credentials from message_store import MessageStore from config_lora import get_nodename ########## CONSTANTS ########## IS_BEACON = False # Used for testing range BLE_ENABLED = True # Used for testing BLE_NAME = 'ulora2' if IS_BEACON else 'ulora' # Name BLE will use when advertising # BLE_NAME = 'ulora2' if get_nodename() == "ESP_30aea4bfbe88" else "ulora" # NOTE: USE ONLY FOR DEV SYNC_INTERVAL = 5000 # How often (ms) to send sync packet after last packet was sent NODE_NAME = get_nodename() ########## LORA ########## from config_lora import parameters, device_spi, device_pins from sx127x import SX127x # Restart machine if we get the 'invalid version' error try: lora = SX127x(device_spi, pins=device_pins, parameters=parameters) except: time.sleep(1) # this try/except can get caught in an uninterruptible loop, sleep gives us a chance machine.reset() def on_lora_rx(): global previous_sync_time if lora.received_packet(): lora.blink_led() payload = lora.read_payload()
def ping_pong(lora): print("LoRa Duplex with callback {0}".format(config_lora.get_nodename())) time.sleep(5) lora.onReceive(on_receive) # register the receive callback do_loop(lora)