I have managed to get the asyncio to do simultaneous tasks, like capture and blink the LED, however it is the web server for mjpeg streaming I am really interested in making non-blocking. I have tried many different things and I am probably just doing something silly, but the web server cxserver never runs - the print does not happen (and checked with an LED to ensure print is not the problem). I have removed all the led and capture stuff (and my wifi details!) - so you have a minimum non-working source code example. Would you expect this to work?
Code: Select all
import sensor, image, time, network, usocket import time from pyb import LED import uasyncio SSID ='' # Network SSID KEY ='' # Network key HOST ='' # Use first available interface PORT = 8080 # Arbitrary non-privileged port IPADDRESS = "192.168.1.10" async def cxstream(reader,writer): print ('Got connection') writer.write("HTTP/1.0 404 NA\r\n\r\n") writer.drain() async def main(led1, led2): cxserver = uasyncio.start_server(cxstream,IPADDRESS,PORT,5) await uasyncio.sleep_ms(10_000) print("Trying to connect... (may take a while)...") wlan = network.WINC() wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) # We should have a valid IP now via DHCP print(wlan.ifconfig()) while(True): uasyncio.run(main(1, 2))