- This repository provides an example of using MQTT on ESP32 with Rust, including TLS support for secure communication.
- This repo only supports MQTT3 now. I'm planning for MQTT5 in the future.
- Connect ESP32 to an MQTT broker using Rust.
- Secure communication with TLS support.
- Lightweight and efficient implementation.
- Rust toolchain (nightly recommended)
- ESP32 toolchain (esp-rs)
- Cargo and cargo-espflash
- An MQTT broker (e.g., Mosquitto, EMQX, or HiveMQ)
Follow the official esp-rs setup guide to install the necessary tools.
git clone https://github.com/TuEmb/mqtt-esp-rs-example.git
cd mqtt-esp-rs-example
- put your certs at
certs
- Update your MQTT info at
src/tasks/mod.rs
Run the following command to build and flash the firmware:
SSID="your-wifi" PASSWORD="your-wifi-password" cargo r --release
Once flashed, the ESP32 will:
- Connect to the configured Wi-Fi network.
- Establish a TLS-secured MQTT connection.
- Publish to a topic.
- Add support for all ESP variants (esp32c6 for now)
This project is licensed under the MIT License.
Contributions are welcome! Feel free to open an issue or submit a pull request.