Cornell University ECE4760
Access point and web server
as Control Panel
version 3

Pi Pico RP2040

Access point and web server
The access point example code in the WIFI section of the picoW examples runs as-is, but I hacked it out of the examples build-structure to compile alone, then added a VGA driver. The code brings up a stand-alone WIFI access point, with DHCP server, DNS server and web server. The supplied code serves one page, with one clickable link that toggles the picoW on-board LED. I added a bunch of comments, generalized the query-string parser (query-string is the part of URL after the ? character), and adding ability to serve several pages of html. Since there is no file system, and no outside connection to the internet, the page request processing had to be quite simple, but supports run-time modifiable pages, text, html forms, hyperlinks, and javascript. The javascript, of course, runs on the browser.

This example is intended to show how to set up simple web pages for process control, not to produce a general web server. Web pages are written in raw HTML. Simple text has the usual formatting tags and can be modifed on the fly by the server for text-based output. The example has input interactors (HTML forms) for text input, number input, graphic sliders to set numerical values, and drop down select menus. HTML form input events oninput and onchange are used to produce better interaction. Output includes simple SVG graphics and a meter construct for ranges of numerical values.

The web pages displayed correctly on Android Chrome, iPad Safari, and iPad Firefox. The application code running on the rp2040 was just a video thread running on core1 which displayed the status of the server and browser variables. LWIP is running on core0, along with a serial thread for debugging and a thread to make a software 100 Hz PWM. My Android phone and iPad connected to the picoW with no complaints. The code runs without a serial monitor or VGA attached, but obviously then you can only interact via browser.
Demo functionality:

Three screens are shown below refecting different views of the program state. First is a browser window running on my cellphone and after pressing the submit buttion. Notice that there is no internet connection and that the IP I chose for the server is 192.168.4.1. The page is ledtest. The second image shows page 2 of the browser interface. The third image is the server-attached VGA screen showing the status of all the browser variables.

----------

---------

CODE, ZIP of project
Note that you will need to delete the build directory and specify a new one.

You can implement an auto-reload for any web page by inserting the following JavaScript
into the body of the page. The ugly back-slashes are there because the html is defined as
an long, multi-line, string:
<script> \
setTimeout(function(){ location.reload(); }, 2000); \
</script>\

VGA driver and LWIP considerations
Both the VGA driver written by Hunter Adams (and converted to 256 colors by Bruce) and the LWIP supplied as part of the C SDK use significant hardware to accelerate operations. The VGA driver uses 4 DMA channels and all 4 state machines in one PIO. The LWIP uses 2 DMA channels and two PIO state machines. LWIP defaults to PIO1 (see cyw43_bus_pio_spi.c), so the VGA must use PIO0. The LWIP uses the claim mechanism to grab DMA channels. This means that any unused channel may be grabbed. The VGA driver was modified to use the claim system so that it does not step on the channels used by LWIP. Once this small change was made, the two libraries played nicely together.


Copyright Cornell University November 29, 2023