Skip to content

bill-callahan/esp32-axum-helloworld

Repository files navigation

[Rust] Tokio/Axum running on esp32!

After going down various and several rabbitholes, trying to get my little ESP32 to serve a webpage, I stumbled across Jasta's esp32-tokio-demo which did exactly what I was trying to do:

  • - Get my ESP32 to startup wifi, and connect to it
  • - [Bonus] do it asynchronously
  • use Tokio's TcpListener to bind to the wifi address
  • - startup a webserver (various out there like Axum, Actix, Tide, etc but all heavily use Tokio, which until now wasn't ESP32 friendly)

This repo demonstrates a working hello world utilizing upstreamed tokio support for esp32.
The tokio executor and I/O reactor are both working fully with no known gotchas. Third party libraries utilizing tokio can also be used freely, such as coap-server-rs. I elected to do an axum server, in this repo.

Quickstart

Recommended that you use an ESP32C3 as upstream Rust support is currently better, though if you do choose any other in the ESP32 family be sure to check out the guides in the Rust on ESP Book.

  • This repo works on an ESP32
git clone https://github.com/bill-callahan/esp32-axum-helloworld your-project-name
cd your-project-name
code .
#  src/main.rs # <-- edit the WIFI_SSID/WIFI_PASS variables!
cargo run --release   <-- greatly reduces size of binary, and takes awhile to compile first-time

After the board connects to Wi-Fi, you can test that things are working with:

  • A web browser - point to http://{ip-obtainded-from-wifi}:3000
  • ThunderClient (vscode extension) - 'New Request" --> http://{ip-addr}:3000/ --> "Send" -- you should see an HTML Response and a Status: 200 OK

Try:

  • / - simple Hello World response
  • /clock - a static page that displays the time (in browser)

You may optionally use cargo run --target xtensa-esp32-espidf or any of the other supported targets which should work provided that you followed the esp-rs installation instructions above.

About

A working basic (Hello World) Axum server on ESP32.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages