Exemple #1
0
async def main(client):
    try:
        await client.connect()
    except OSError:
        print('Connection failed.')
        return
    n = 0
    while True:
        await asyncio.sleep(5)
        print('publish', n)
        # If WiFi is down the following will pause for the duration.
        await client.publish('result', '{} {}'.format(n, client.REPUB_COUNT), qos = 1)
        n += 1

# Define configuration
config['subs_cb'] = sub_cb
config['wifi_coro'] = wifi_han
config['connect_coro'] = conn_han
config['clean'] = True

# Set up client
MQTTClient.DEBUG = True  # Optional
client = MQTTClient(config)

asyncio.create_task(heartbeat())
try:
    asyncio.run(main(client))
finally:
    client.close()  # Prevent LmacRxBlk:1 errors
    asyncio.new_event_loop()
Exemple #2
0
def test():
    try:
        asyncio.run(irq_test())
    finally:
        asyncio.new_event_loop()
Exemple #3
0
                wday=c[-7],
                month=c[-6],
                mday=c[-5],
                hrs=c[-4],
                mins=c[-3],
                secs=c[-2],
                times=c[-1]))
    # asyncio.create_task(schedule(restart, hrs=23, mins=56, secs=00))  # restart the system daily.
    while True:
        await asyncio.sleep(60)  # Keeps scheduler running forever.


############################ Program starts here ###############################
log(dfl.RESET_CAUSE[machine.reset_cause()], type='e')
welcome_msg()
asyncio.create_task(blink(4, 1, 2000, stop_evt=timesync))  # Blue, no gps fix.
asyncio.create_task(blink(3, 100, 1000,
                          cancel_evt=scheduling))  # Yellow, initialisation.
asyncio.create_task(blink(2, 1, 2000, start_evt=timesync))  # Green, operating.
asyncio.create_task(cleaner())
asyncio.create_task(listner(trigger))
asyncio.create_task(alerter(alert))

try:
    asyncio.run(main())
    loop.set_exception_handler(_handle_exception)
except KeyboardInterrupt:
    pass
finally:
    asyncio.new_event_loop()  # Clear retained state.
def test(master):
    try:
        asyncio.run(main(master))
    finally:  # Reset uasyncio case of KeyboardInterrupt
        asyncio.new_event_loop()
Exemple #5
0
def demo_async():
    try:
        asyncio.run(test_async())
    finally:
        asyncio.new_event_loop()
Exemple #6
0
async def main():
    rotary_encoder_1 = RotaryIRQ(pin_num_clk=14,
                                 pin_num_dt=15,
                                 min_val=0,
                                 max_val=5,
                                 reverse=False,
                                 range_mode=RotaryIRQ.RANGE_WRAP)

    rotary_encoder_2 = RotaryIRQ(pin_num_clk=32,
                                 pin_num_dt=33,
                                 min_val=0,
                                 max_val=20,
                                 reverse=False,
                                 range_mode=RotaryIRQ.RANGE_WRAP)

    # create tasks that use the rotary encoders
    app1 = Application1(rotary_encoder_1)
    app2 = Application2(rotary_encoder_1, rotary_encoder_2)

    # keep the event loop active
    while True:
        await asyncio.sleep_ms(10)


try:
    asyncio.run(main())
except (KeyboardInterrupt, Exception) as e:
    print('Exception {} {}\n'.format(type(e).__name__, e))
finally:
    ret = asyncio.new_event_loop()  # Clear retained uasyncio state
def test(n=0):
    try:
        asyncio.run(tests[n]())
    finally:
        asyncio.new_event_loop()
def test():
    try:
        asyncio.run(main())
    finally:  # Reset uasyncio case of KeyboardInterrupt
        asyncio.new_event_loop()
        print('asnano_sync.test() to re-run test.')
Exemple #9
0
def run_async(func):
    "run a function asynchronously"
    try:
        asyncio.run(func())
    finally:
        asyncio.new_event_loop()  # Clear retained state