ESP32 Guides
Practical guides for connecting ESP32 microcontrollers to RosFit — from simple MQTT sensors to micro-ROS motor controllers and mesh networks.
Smart greenhouse sensor node
Build an environmental monitoring node that reports temperature, humidity, soil moisture, and light levels to RosFit.
What you'll build:
- ESP32 with DHT22 (temp/humidity), capacitive soil moisture sensor, and BH1750 light sensor
- Connect to RosFit via MQTT over Wi-Fi with token authentication
- Publish sensor readings every 30 seconds to separate telemetry topics
- Configure dashboard gauges for each metric
- Set up threshold alerts (temperature > 35°C, soil moisture < 20%)
Hardware: ESP32-WROOM-32, DHT22, soil moisture sensor, BH1750, breadboard.
#include <WiFi.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
const char* mqtt_server = "emqx.rosfit.local";
const int mqtt_port = 1883;
const char* device_id = "sensor-greenhouse-01";
const char* mqtt_token = "mqtt_tok_greenhouse01";
WiFiClient espClient;
PubSubClient client(espClient);
void publishTelemetry() {
JsonDocument doc;
doc["temperature"] = readDHT22Temp();
doc["humidity"] = readDHT22Humidity();
doc["soil_moisture"] = readSoilMoisture();
doc["light_lux"] = readBH1750();
doc["timestamp"] = millis();
char buffer[256];
serializeJson(doc, buffer);
String topic = String("rosfit/") + device_id + "/telemetry/environment";
client.publish(topic.c_str(), buffer, true);
}
micro-ROS motor controller
Run micro-ROS on an ESP32 to control DC motors through the ROS 2 graph, bridged to the cloud via RosFit.
What you'll build:
- ESP32 running micro-ROS agent over serial or Wi-Fi
- Subscribe to
geometry_msgs/Twiston/cmd_velfor differential drive control - Publish encoder-based odometry on
/odom - Bridge both topics to RosFit cloud via a co-located micro-ROS agent
- Control the robot from the dashboard joystick widget
Hardware: ESP32, L298N motor driver, DC motors with encoders.
Key topics covered: micro-ROS setup, XRCE-DDS agent, Twist message handling, encoder odometry.
# Flash micro-ROS firmware
ros2 run micro_ros_setup create_firmware_ws.sh freertos esp32
# Start the micro-ROS agent
ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyUSB0
# Register the device
rosfit devices add --name "esp32-motor-01" --type micro_ros_mcu --group lab
Battery-powered field sensor
Build a low-power sensor node that wakes periodically, sends data, and sleeps to conserve battery.
What you'll build:
- ESP32 deep sleep cycle: wake every 5 minutes, connect to Wi-Fi and MQTT, publish readings, sleep
- Optimize connection time with static IP and BSSID caching
- Publish battery voltage alongside sensor data for remote monitoring
- Configure RosFit alerts for low battery (< 3.3V) and missed check-ins
- Achieve 6+ months on a 3000mAh LiPo battery
Hardware: ESP32, BME280 (temp/humidity/pressure), solar panel (optional), LiPo battery.
Key design decisions:
| Strategy | Power Saved | Trade-off |
|---|---|---|
| Deep sleep between readings | ~99% | Latency between updates |
| Static IP assignment | ~0.5s per wake | Manual network config |
| BSSID caching | ~1s per wake | Breaks if AP changes |
| QoS 0 (fire and forget) | ~0.2s per wake | No delivery guarantee |
| Disable Bluetooth | ~10mA idle | No BLE capability |
ESP32-CAM security camera
Stream JPEG snapshots from an ESP32-CAM module through RosFit to the dashboard camera feed widget.
What you'll build:
- ESP32-CAM capturing JPEG frames at configurable resolution
- Publish compressed frames to MQTT as base64-encoded payloads
- View the live feed in the dashboard camera widget
- Trigger snapshot capture via RosFit commands
- Configure motion detection alerts using frame differencing
Hardware: ESP32-CAM (AI-Thinker module), OV2640 camera.
Bandwidth considerations:
| Resolution | JPEG Size | At 2 FPS | At 10 FPS |
|---|---|---|---|
| QVGA (320×240) | ~8 KB | ~16 KB/s | ~80 KB/s |
| VGA (640×480) | ~25 KB | ~50 KB/s | ~250 KB/s |
| SVGA (800×600) | ~40 KB | ~80 KB/s | ~400 KB/s |
| XGA (1024×768) | ~70 KB | ~140 KB/s | ~700 KB/s |
For MQTT, keep frame size under 256 KB (EMQX default max packet size). Use QVGA or VGA for reliable streaming.
BLE sensor mesh with RPi gateway
Build a mesh of BLE sensor nodes that report through a Raspberry Pi gateway to RosFit.
What you'll build:
- Multiple ESP32 nodes advertising BLE sensor data (temperature, motion, door state)
- Raspberry Pi running a BLE scanner and MQTT gateway
- Gateway registers as a
gatewaydevice type in RosFit - Sub-device telemetry published under the gateway's topic namespace
- Dashboard shows the gateway with expandable sub-device list
Hardware: 3+ ESP32 BLE beacons, Raspberry Pi 4, USB BLE dongle (optional).
Architecture:
[ESP32 BLE #1] ──┐
[ESP32 BLE #2] ──┼── BLE ──▶ [Raspberry Pi Gateway] ── MQTT ──▶ [RosFit Cloud]
[ESP32 BLE #3] ──┘
The gateway aggregates BLE advertisements and publishes structured telemetry:
{
"gateway_id": "gw-rpi-01",
"sub_devices": [
{ "id": "ble-temp-01", "temperature": 22.5, "rssi": -45 },
{ "id": "ble-motion-02", "motion_detected": true, "rssi": -62 },
{ "id": "ble-door-03", "door_open": false, "rssi": -38 }
],
"timestamp": "2026-03-30T10:05:00Z"
}
OTA firmware updates via RosFit
Push firmware updates to ESP32 devices over-the-air using the RosFit OTA system.
What you'll build:
- Compile ESP32 firmware with OTA partition scheme
- Upload firmware binary to RosFit via the API or CLI
- Create a deployment targeting individual devices or a group
- ESP32 firmware includes an OTA listener that downloads and applies updates
- Implement rollback on failed boot with a watchdog timer
Key steps:
- Partition the ESP32 flash with two OTA slots (
ota_0,ota_1) - Include the RosFit OTA client library in your firmware
- Upload the binary:
rosfit deploy firmware-v1.2.0.bin --version 1.2.0 --target greenhouse-sensors - The OTA service publishes the update URL to
rosfit/{device_id}/ota/update - The device downloads, verifies the checksum, flashes to the inactive slot, and reboots
- On successful boot, the device reports the new firmware version in its shadow state
# Upload and deploy firmware
rosfit deploy build/firmware.bin \
--version 1.2.0 \
--target greenhouse-sensors \
--rollback-on-failure