Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/olegccc/esp32-axum-ws
Rust for ESP32 with Axum and Websockets
https://github.com/olegccc/esp32-axum-ws
axum esp-rs esp32 preact rust tokio-rs vite
Last synced: 4 days ago
JSON representation
Rust for ESP32 with Axum and Websockets
- Host: GitHub
- URL: https://github.com/olegccc/esp32-axum-ws
- Owner: olegccc
- Created: 2024-04-22T22:10:28.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-04-23T09:13:10.000Z (8 months ago)
- Last Synced: 2024-10-31T09:42:02.072Z (about 2 months ago)
- Topics: axum, esp-rs, esp32, preact, rust, tokio-rs, vite
- Language: Rust
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rust for ESP32 with Axum and Websockets
This repository provides base but working functionality for ESP32 board with Rust environment
based on `esp-rs` project, where it runs fully functional web server based on Axum web framework
with the support of Websockets. Axum by itself is based on Tokio.rs asynchronous runtime.Once you have built and run the code, it opens a web server page where you can manage state of a LED:
turn it on and off and query its status. All the communication is done through a Websocket channel.The `client` folder contains basic but fully functional React-based web application that knows
to open Websocket channel and use it to communicate with the device.Tested on ESP32S3 dev board (Seeed Studio XIAO ESP32S3). Note that the configured LED pin number (21) triggers physical
LED on this board. This will work on any ESP32 board but you will need to know and adjust the pin number for your board.I don't see any reason why it may not work on any other ESP32 board with enough flash memory
(its image size is about 2.4MB and current partition layout is set to have at least 3MB flash memory).In general, I think it is the best of all known ways to build a secure, reliable web application that requires intensive communication
with ESP32 device. It is enough to write only web interface, without the need of developing mobile applications
(however Websockets work perfectly with Android and iOS native apps, Flutter apps etc).The fact that it is based on Tokio and Rust opens all the existing ecosystem of Rust libraries for you.
You can write tests and debug your app on desktop, before moving to mobile device.This configuration works on macOS and Linux, it will require minor changes to work on Windows.
## Setup build environment
Install Rust on ESP build environment
https://github.com/esp-rs/rust-buildInstall latest NodeJS LTS
https://nodejs.org/en/downloadInstall Yarn
https://yarnpkg.com/getting-started/install## Prepare
Copy `.env.default` to `.env` and change default values to the actual ones.
To prepare the build environment, execute the following command each time you open a terminal window:
`. ~/export-esp.sh`
## Build
To build the project, use the following command:
`cargo build`
To run the project, use the following command:
`cargo run`
## Reference links
* Rust-ESP installation process https://github.com/esp-rs/rust-build
* Tokio.rs asynchronous runtime https://tokio.rs/tokio/tutorial
* Axum web application framework https://github.com/tokio-rs/axum
* Seeed Studio XIAO ESP32S3 https://wiki.seeedstudio.com/xiao_esp32s3_getting_started/
* Awesome ESP Rust https://github.com/esp-rs/awesome-esp-rust
* esp32-s3-rust-axum-example (used as a prototype for this project) https://github.com/aedm/esp32-s3-rust-axum-example/