Asyncio web server (ultimately for mjpeg stream)

Hi,

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?

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))

Ah, I’ve never tested that new MicroPython module. Ibrahim?

Hi,

I think I am missing an await before the uasyncio.start_server. However that results in a new error. A dialog appears in the IDE: File Error - OpenMV IDE. Could not open F:\uasyncio\stream.py for reading. Either the file does not exist or you do not have permissions to open it. F: is the SD card drive of the camera. So maybe we are simply missing some external files?

This will Not work because we have a different sockets implementation for WINC1500 than the one in micropython that this was written for, so you’ll get errors like that.

So for example, Server class sets socket.SO_REUSEADDR we don’t have that flag in WINC1500, and it tries to set blocking before listen stuff like that throw these errors, but even if I fix those and that’s easy to do, it needs polling for this to work and polling is Not implemented in our WINC driver.

Hi,

Thanks very much for your time and for the info. I will try another approach…

(I am thinking of using Udp to send large images as that’s non blocking and work out which packets don’t arrive to drop frames or replace bits).

Thanks again for looking. Cheers!