示例#1
0
async def async_main():
    global mqclient
    # get an initial connection
    board.blue_led(True)
    try:
        await mqclient.connect()
    except OSError:
        print('Connection failed')
        return
    # play watchdog
    while True:
        print("Still running...")
        await asyncio.sleep(10)
示例#2
0
async def main():
    global mqclient
    # get an initial connection
    board.blue_led(True)
    try:
        await mqclient.connect()
    except OSError:
        print('Connection failed')
        return
    # Start repl
    global mqrepl
    mqrepl = MQTTRepl()
    loop.create_task(mqrepl.sender(repl_pub))
    await asyncio.sleep_ms(10)
    os.dupterm(mqrepl, 0)
    await asyncio.sleep_ms(10)
    # TODO: wait for time sync
    # launch tasks
    #loop.create_task(query_sensors(client))
    #loop.create_task(poll_uarts(client))
    # play watchdog
    while True:
        print("Still running...")
        await asyncio.sleep(10)
示例#3
0
async def pulse():
    board.blue_led(True)
    await asyncio.sleep_ms(100)
    board.blue_led(False)
示例#4
0
    await asyncio.sleep_ms(10)
    os.dupterm(mqrepl, 0)
    await asyncio.sleep_ms(10)
    # TODO: wait for time sync
    # launch tasks
    #loop.create_task(query_sensors(client))
    #loop.create_task(poll_uarts(client))
    # play watchdog
    while True:
        print("Still running...")
        await asyncio.sleep(10)

# Start MQTT (and Wifi)
config['subs_cb'] = sub_cb
config['wifi_coro'] = wifi_cb
config['connect_coro'] = conn_cb
config['keepalive'] = 120
#MQTTClient.DEBUG = True
mqclient = MQTTClient(config)

#import uasyncio, logging
#logging.basicConfig(level=logging.DEBUG)
#uasyncio.set_debug(True)

print("Starting loop...")
try:
    loop.run_until_complete(main())
finally:  # Prevent LmacRxBlk:1 errors.
    mqclient.close()
    board.blue_led(True)