Cornell University ECE4760
Access point with HTTP plus Client

Pi PicoW RP2040

Access point server and client
The access point example code in the WIFI section of the picoW examples shows how to build a simple web server. In this example, the web server was modified to be a HTTP server to serve text pages (including embedded data) to a HTTP client. The client was based on the simplest TCP example given in Fairhead and James (reference at bottom of page). The modified client displays the text pages on a terminal emulator and accepts commands to send back to the server as an HTTP GET request. Data is sent both directions across the HTTP link and identified by source on the text pages. The server maintains state. This example is intended to show how to set up simple text pages so that the client can control processes on the server.

The example access_point/server code brings up a stand-alone WIFI access point, with DHCP server, DNS server and HTTP server.
The code serves two pages, entitled ledpage and adcpage. The first image below shows the content of the default ledpage displayed by the client. The second is the adcpage.
-- Ledpage has commands to change server LED state, set variables on the server, displays the internal server temperature, and the time in seconds since boot.
You can tell the server to switch to the adcpage. There is also one client command which turns on auto-reload at an interval given in milliseconds.
Since it takes around 50-60 mSec to load a page, the usable reload interval range is is probably 100 to 10000 mSec.
To turn off auto-reload you must type any one character.
-- The adcpage sends temperature and ADC channel_zero voltage data from the client to the server, which displays the data on this page.
You can tell the server to switch to the ledpage, and tell the client to auto-reload, as above.
To turn off auto-reload you must type any one character.

The client PuTTY window supports limited color text, text intensity, new page, tab, and newline.
There is enough control to format simple data-display server pages. The data and command list are sent from
the server. The response time (for debugging) and command prompt are generated by the client.
Typing at the command prompt causes the client to assemble a HTTP GET request including any parameters set by the
user. The general form of this GET request is
sprintf(header,"GET %s?led=%01d&test=%d&test2=%d HTTP/1.1\r\n\r\n ", site, led, test, test2)
where the variables are set at the command line on the client. The GET request is sent to the server
which replies with a newly constructed page which includes any user input.

There are two required executables: the server and the client. Beause I am not very good with Cmake you will need to build and download each separately using the source codes below.
Demo functionality:

Designing or extending the text pages sent is quite easy.
Only ASCII text can be sent, but the PuTTY terminal emulator does understand a few ANSI terminal control codes for text color and intensity.
Tested control codes are listed below:
Note that ASCII codes are all OCTAL base
-- Newline \12\15
-- Newpage \14
-- Tab \11

ANSI terminal control codes
-- Boldface \33[1m
-- Normaltext \33[0m (undoes all text highlighting and color)
-- Greentext \33[32m
-- BoldGreentext \33[1;32m

Server Code, Client Code, ZIP of project
Note that you will need to delete the build directory and specify a new one.
You will need to compile the client and server separately by modifying which source file is used in CmakeLists.txt


References:

  1. Master the Raspberry Pi Pico in C: WiFi with lwIP & mbedtls
    IO Press, 2023, page 42
    by Harry Fairhead and Mike James.

    There does not seem to be any specific license for code use mentioned on the book webpage, or within the book itself.
    If anyone can clarify the license I will be happy to modify this page.
  2. C SDK examples page: https://github.com/raspberrypi/pico-examples
  3. If you are looking for an example that just moves arrays back and forth from client to server, there is a pair of examples
    (tcp_client, tcp_server) which work together on the C SDK examples page in the WIFI section of the picoW examples.

Copyright Cornell University January 5, 2024