This project is a simple rust implementation for the ESP32C3-Devkit-M1 to be used as a HTTP(S) REST-API to control a 3-color LED RGB stripe via PWM/ RMT. The server can be requested with commands shown here.
The server uses RGB channels to control the proportion of each color channel in the light. The fourth channel, the alpha/ brightness channel, scales down/ up to control the light's brightness over all 3 color channels.
I also wrote a native Android client to make request to the server's API, it is called StripeBuddy.
Setup rust nightly with the ESP32 toolchain. You'll need the rust nightly toolchain, ldproxy and setup support for RISC-V.
A short guide for this can be found here (only ldproxy, RISC-V setup).
To properly flash the binary on to the board, you need the espflash tool, can be installed with:
cargo install cargo-espflash
.
- please make sure that your nightly rust setup for RISC-V and esp32 is complete (see here).
- rename
cfg.toml.example
tocfg.toml
and enter your wifi-credentials in there - (optional if you want to use the android client, or want to use a self-signed ssl certificate): Generate a certificate authority certificate, use this certificate to sign a server ssl certificate to use server's HTTPS API. For this please take a look at the scripts at
/certs
. After generating the certificates, copy the byte arrays for the server certificate and server key in the responding fieldscfg.toml
. Sadly I could not figure out a better way, but after this you need to edit the lines in thestruct Settings
that specify the expected length of the struct'sssl_server_cert
andssl_server_key
fields. If you use rust-analyzer as LSP, the linter should tell you the number you have to enter as the expected length for the byte array. For even more information to generate self-signed SSL certificates take a look at my other repo. - run
cargo espflash /dev/ttyUSB0 --speed 921600 -s 4MB --monitor --release --partition-table=partition.csv
to compile and flash the code on your board - enjoy controlling your RGB LED stripe with the ESP32C3
Command | Description | Returns | Status Codes |
---|---|---|---|
\health | Indicates if the server is running | Returns string "I am alive" | 200 (OK) |
\help | Shows a help page | Returns help text as string | 200 (OK) / 400 (Error) |
\setRGBA?r=RED&g=GREEN&b=Blue&a=BRIGHTNESS | Sets the RGBA values according to their values, not all values need to be specified at the same time | all RGBA values in CSV format without header after 'set' request | 200 (Ok) / 400 (Error) |
\getRGBA | Retrieve current set RBGBA values | all RGBA values in CSV format without header | 200 (OK) / 400 (Error) |
TODO