An extensible HTTP server for zeptoforth on the Pico 2W or Pico Plus 2W

Have you ever wished you could serve web pages from your PicoCalc?

Now you can, with extra/rp_common/net_tools/http_server.fs on zeptoforth on a Pico 2W or Pico Plus 2W with zeptoIPv4 or zeptoIPv6 installed.

First install zeptoforth with either zeptoIPv4 or zeptoIPv6 on your PicoCalc, then load extra/rp_common/net_tools/pico_w_ipv4_base_no_handler.fs (for zeptoIPv4) or extra/rp_common/net_tools/pico_w_ipv4_base_no_handler.fs (for zeptoIPv6) on your PicoCalc.

Then execute:

s" my-ssid" s" my-password" s" picocalc.local" pico-w-net::init-wifi

where my-ssid is your WiFi SSID, my-password is your WiFi password, and picocalc.local is your Multicast DNS name (which must end in .local).

Then execute:

80 pico-w-net::my-interface @ net-http::start-server

to start your HTTP server.

Well, what can you do with it?

You can set up an HTTP file server to serve files from your PicoCalc! (Mind you, this is HTTP not HTTPS, so the only security is that you can limit it to a particular filesystem and directory (and its sub-directories), with it rejecting URI’s crafted to include . or ...)

To do so, load extra/rp_common/net_tools/http_server_files.fs and then execute:

s" /" fat32-tools::sd-fs@ s" /files/" net-http-files::init-files

and tada, you now have an HTTP file server serving files in the / directory of your SD card from http://picocalc.local:80/files/ (or like). Replace s" /" with, say s" /FOOBAR/" if you want to make the root of the HTTP file server /FOOBAR/.

You can do other things with your PicoCalc, such as to turn your PicoCalc into a clock that you can access from http://picocalc.local:80/time with loading extra/rp_common/net_tools/http_server_time.fs and then executing:

net-http-time::init-time

or to control your Pico 2W or Pico Plus 2W’s LED from http://picocalc.local:80/led/ by loading extra/rp_common/net_tools/http_server_led.fs and then executing:

net-http-led::init-led

or if you have no concerns about adding a gaping security hole (no authentication or encryption whatsoever!) to your PicoCalc, you can send commands remotely to your PicoCalc with that you can access from http://picocalc.local:80/console-in by loading extra/rp_common/net_tools/http_server_console_in.fs and executing:

net-http-console-in::init-console-in
net-http-console-in::enable-console-in

(Note that you will not be able to use the console on your PicoCalc for input until you execute the below after this point.)

If you grow tired of that or paranoid about someone gaining access to your PicoCalc from outside, execute:

net-http-console-in::disable-console-in

And guess what? You can to all these things at once because this is an extensible HTTP server. You can even write your own web pages for your PicoCalc on the side by doing things such as executing:

: hello ( -- )
  s" text/html" net-http::http-ok.
  net-http-method@ net-http::method-head = if exit then
  ." <html>"
  ." <head><title>Hello, world!</title></head>"
  ." <body><h1>Hello, world!</h1></body>"
  ." </html>"
;

: init-hello ( -- ) ['] hello s" /hello.html" net-http::register-fixed-uri ;

init-hello

After which you can access your new web page (alongside all the other ones you have installed) at http://picocalc.local:80/hello.html!

(One disclaimer: .local domains are network-local, so don’t try accessing them from your cell phone unless you are using it on the same WiFi router as your PicoCalc.)

(Another disclaimer: please don’t really try to use the console input HTTP server if you are using zeptoIPv6, as it certainly will be exposed to the open Internet then, and you don’t want someone getting in and deciding to be a jackass by erasing the flash on your Pico 2W or Pico Plus 2W or, worse yet, writing to the OTP in your RP2350.)

1 Like