Web Control Panel - Micropython asyncio and dual core web server for Raspberry Pi Pico, ESP32

preview_player
Показать описание
In our previous tutorial we built a web server but the code halted the processor while it waited for the next HTTP request.

In this tutorial I'll show you how to use asynchronous coding with the Asyncio package and dual core processing to build a non blocking web server that will run the HTTP protocol in the background while your microcontroller gets on with its tasks in the foreground.

The asyncio code will work for any microcontroller. The multi core code will need a Raspberry Pi Pico or ESP32 or another board with multiple cores.

Previous tutorials

Github Code Repository

BytesNBits web page - circuit diagram, etc.

0:00 Introduction
2:22 The blocking web server problem
3:56 Asynchronous server with uasyncio
4:50 The demo circuit
8:13 The asyncio code
31:13 Dual core solution
39:11 Combining asyncio and multi core to use all processor resources
Рекомендации по теме
Комментарии
Автор

Great video. I was trying to figure this out by myself before finding your video showing how to do exactly what I wanted to do while much better than my cobbled together attempts.

TehSpork
Автор

Just what I was looking for and great timing. Thanks and you got my subscribe.

keithlohmeyer
Автор

Wow, what a great video and your web tutorial was was just as good. I have to say though, you mentioned this would work on the esp32 and since I had one already setup with all my sensors, I used it instead of my picow but just couldn’t get it to work. I’m certain it was something I did but I messed with it for several hours when I figured I’ll just try it with a picow, w/ nothing attached, and it worked right away. Your videos and web pages have saved me months of research. Thank you so much for the countless hours of research, coding, creating web pages, and making and editing these awesome videos. I look forward to more content.

robleepetty
Автор

Nice work, what caught my eye was the displayed graphics. As for myself, I've decided to upgrade my PIC24 remote server (that controls antennas; transmitters, etc.) to using the Raspberry pi4. Since I've not done any webserver sites since the early 2000's, need to learn how to use PHP, JavaScript, CGI, etc. all over again. To bad this is all done in Python and not in C or C+. Not for me, but will watch the video's. Could be something interesting.

dalesmith
Автор

I hope you will be able to find the time to solve the threading/dual core issues and post the 3rd video in this series. It has taught me a lot. Thank you!

johncutler
Автор

It's a pity that MicroPython refers to the multi-core library on the RP2040 as _thread; it should be called _core instead. This had caused a great deal of confusion. While the ESP32 has two cores, the first core, core0, is dedicated to system-specific tasks such as WIFI and Bluetooth. MicroPython operates on the second core, core1. On the ESP32, the _thread is preemptive multitasker, and we can have up to 25 threads running concurrently.

shariltumin
Автор

thank you! this topic has almost no tutorials and you made it easy.
i love how you combined the two approaches in the end.

i noticed there was a delay between the colored displayed on the web server and the neo pixels hardware, is this due to internet speed or does this mean asyncio introduces some delay?

thanks a lot.

qozia
Автор

34:35 - thank you very much for the sanity check. I was attempting to do just this and saw this exact behavior (first request processes, then that loop hangs without error)

cabasse_music
Автор

Thx for this info. I’ve been pulling my hair out for 3 days trying to get multi core working on my project with a web server running on the second core. I get exactly as you describe, it seems to run for a few loops, maybe even get a web page to display remotely on another machine, but then it all hangs and even stops the main thread on the first core too. I searched and searched for a reason but came to the conclusion that _thread just isn’t ready yet and was going to give up. I’ll now try swapping the threads over and try running the web server on the first core. Hoefully this will resolve my issue.

pdenny
Автор

Thank you so much for this amazing tutorial. I am trying to achieve something similar, but by using W5500 from wiznet instead of wifi (wanna have wired connection and PoE). Unfortunately it looks like the uasyncio server_start cannot start the coroutine (looks like does not have access to the network). However standard socked does. Did you have similar issue? Do you have any sugestion? At the end, it looks like, I will end up with multithreating, looks like the mentioned bug is fixed. Thank you. Briliant work.

Автор

Really great stuff here man. just a quick question
i have tried with my own custom built webserver that also manages ap and wifi connections (will share soon) but i have encontered a problem. I use thonny to run the code and when stop the code it seems that the code actually stop but id restart and stop again the pico starts to be unreachable.

Have you used thonny? Did you experience the same behaviour?

Thanks a lot for all your hard work!

stefanotuv
Автор

Overall how do you find uasyncio running on the Pico? I believe they still consider it experimental. Based on what you've experienced, do you think it's stable enough at this point? What are the main areas you need to be careful about when setting up uasyncio? Are there limits to the number of tasks you can setup and have successfully managed by the scheduler? How much bigger are your programs when uasyncio is included? Have you found it to be consistent across different uprocessors (not sure if you've used uasyncio with processors other than the Pico)? Getting rid of blocking code is so important and necessary to allow for more advanced projects.

Would be great if you produced a video on more details about how to setup and use uasyncio. I was somewhat expecting a bit more info on the general setup of and do's & don'ts for structuring your tasks. Maybe something for the future. Thanks.

christopherlyons
welcome to shbcf.ru