Search For Pico W Web Server Led To MicroWebSrv2

One of the bare minimalist examples I saw while readingConnecting to the Internet with Raspberry Pi Pico W” was a simple HTTP web server. It only serves a single page which is represented by a string embedded in the source code. This is obviously not going to work for anything serious.

Fortunately, the popularity of ESP8266 and ESP32 pioneered an ecosystem of web servers suitable for running on microcontrollers. Many of which have already been adapted to run on the Pico W, as the new hotness on the block. They all meet the primary requirement: Serving static files on board microcontroller flash storage, rather than strings embedded in source code. This is important because I want to update them without having to touch my web server files, and second because I don’t want to hassle with string escape and other inconveniences of embedding HTML/CSS/JS syntax inside valid C or Python syntax.

Most of these web server options were written in Arduino or another C-based framework like ESP-IDF, but a few of them were written in MicroPython so I thought I would look at those first. Beyond serving static files, many of them have routing and associated mechanisms for dynamic server-side responses. Several such frameworks said they’re modeled after Flask, which I’ve played with before, and makes sense in a Python context.

But the one feature I would like is web socket support. I want to try porting my micro Sawppy interface to such a system and that uses web sockets to communicate between the cell phone browser acting as remote control and the microcontroller driving my mini rover. This surprisingly eliminated almost all of the candidates. I found only MicroWebSrv2 for MicroPython compatible web server framework with web socket support.

I am intrigued after a cursory glance over MicroWebSrv 2 README. Especially the claim that MicroWebSrv2 can run on desktop computer Python as well as microcontroller MicroPython. In my earlier development efforts for micro Sawppy interface, I wrote the server-side code twice. Once in NodeJS (JavaScript) as a stub to help me develop on the desktop, and again in ESP-IDF to run on an ESP32. It would be great if I can have a single chunk of Python code that handles both cases. I have to review my code to see what other support infrastructure I would need. The first one off the top of my head is a JSON parsing library, which is included in MicroPython, a good start.

Leave a comment