
In the meantime, I started to write HTTP client for it: https://github.com/pfalcon/micropython-uaiohttpclient
Great!fma wrote:Last night, I made a short talk to present micropython to AFPY guys, and someone also presented asyncio.
Yes, as the previous message says, uasyncio.core was specifically split to let it being used on PyBoard. Full uasyncio module cannot be used on PyBoard, because it used Linux async i/o implementation (epoll). Surely, that will change with time.At the end of the talk, we tried to use uasyncio to blink leds, but it failed. It seems that asyncio can't work on pyboard, because the ffi module is missing.
Am I right?
Is it possible to only use usayncio.core on pyboard to make a basic asyncio demo?
I don't have a PyBoard with me, so don't to post unverified code, so here's code which will "blink" ON/OFF messages on your desktop monitor:How do I use it?
Thanks for your help.
Code: Select all
import logging
try:
import uasyncio.core as asyncio
except ImportError:
import asyncio
def loop():
while True:
print("ON")
yield from asyncio.sleep(1)
print("OFF")
yield from asyncio.sleep(1)
logging.basicConfig(level=logging.ERROR)
asyncio.get_event_loop().run_until_complete(loop())
Code: Select all
import logging
import uasyncio.core as asyncio
import pyb
@asyncio.coroutine
def light(led, delayOn, delayOff):
"""
"""
while True:
print(repr(led))
led.on()
yield from asyncio.sleep(delayOn)
led.off()
yield from asyncio.sleep(delayOff)
def main():
"""
"""
logging.basicConfig(level=logging.ERROR)
loop = asyncio.get_event_loop()
leds = [pyb.LED(1), pyb.LED(2), pyb.LED(3), pyb.LED(4)]
#delays = [(1, 2), (1, 0.5), (0.5, 0.5), (0.25, 1)]
delays = [(1, 1), (1, 2), (2, 1), (2, 2)]
tasks = [asyncio.async(light(led, *delay)) for led, delay in zip(leds, delays)]
# loop.run_until_complete(asyncio.wait(tasks)) # not implemented
for task in tasks:
loop.call_soon(task)
loop.run_forever()
if __name__ == "__main__":
main()