Asyncio web server (ultimately for mjpeg stream)

Discussion related to "under the hood" OpenMV topics.
Stub
Posts: 28
Joined: Mon Dec 23, 2019 8:30 am

Asyncio web server (ultimately for mjpeg stream)

Postby Stub » Mon Feb 22, 2021 12:00 pm

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?

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))
User avatar
kwagyeman
Posts: 5001
Joined: Sun May 24, 2015 2:10 pm

Re: Asyncio web server (ultimately for mjpeg stream)

Postby kwagyeman » Mon Feb 22, 2021 12:36 pm

Ah, I've never tested that new MicroPython module. Ibrahim?
Nyamekye,
Stub
Posts: 28
Joined: Mon Dec 23, 2019 8:30 am

Re: Asyncio web server (ultimately for mjpeg stream)

Postby Stub » Mon Feb 22, 2021 1:16 pm

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?
User avatar
iabdalkader
Posts: 1326
Joined: Sun May 24, 2015 3:53 pm

Re: Asyncio web server (ultimately for mjpeg stream)

Postby iabdalkader » Mon Feb 22, 2021 3:11 pm

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.
User avatar
iabdalkader
Posts: 1326
Joined: Sun May 24, 2015 3:53 pm

Re: Asyncio web server (ultimately for mjpeg stream)

Postby iabdalkader » Mon Feb 22, 2021 3:42 pm

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.
Stub
Posts: 28
Joined: Mon Dec 23, 2019 8:30 am

Re: Asyncio web server (ultimately for mjpeg stream)

Postby Stub » Mon Feb 22, 2021 5:29 pm

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!

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 4 guests