Project · Intermediate · Raspberry Pi
Raspberry Pi + ESP32 Mesh for Smart Home (Local MQTT Architecture)
Pi runs the broker; ESP32 nodes publish sensors and subscribe to commands. LAN only for v1. Companion to the paid ESP32 + Pi Project Bundle and free Pi weekend PDF. Goal: one broker, one publishing node, one com…
Project template
- Goal & materials
- Steps / firmware
- Troubleshooting
- AI assist notes
- Related gear & books
Versions under test
Pin Mosquitto package version, Pi OS release, and ESP32 Arduino-esp32 core in NOTES.md. Architecture compared against cloud MQTT — we reject WAN exposure for v1.
Companion to the paid ESP32 + Pi Project Bundle and free Pi weekend PDF. Goal: one broker, one publishing node, one command path that survives reboot.
Architecture roles
| Role | Hardware | Responsibility |
|---|---|---|
| Coordinator | Pi 4/5 + Ethernet preferred | Mosquitto, logging, optional automation |
| Sensor node | ESP32 + BME280/DHT | Publish telemetry JSON |
| Actuator node | ESP32 + opto relay | Subscribe to safe low-V commands |
BOM (starter lab)
| Item | Qty | Ballpark USD |
|---|---|---|
| Raspberry Pi 4/5 + PSU | 1 | $55–90 |
| microSD A2 or NVMe (Pi 5) | 1 | $10–40 |
| ESP32 DevKit | 2 | $8–24 |
| BME280 or DHT22 | 1–2 | $3–12 |
| Opto relay module (low-V practice load) | 1 | $3–8 |
| Ethernet switch (optional calm) | 1 | $15–30 |
Topic plan (v1)
lab/{room}/telemetry # sensors → Pi
lab/{room}/cmd/relay # Pi → actuator
lab/{room}/status # online / fw / last_boot
lab/sys/heartbeat # optional coordinator liveness
Sample payloads
// telemetry
{"t_c":24.1,"rh":41.0,"rssi":-62,"fw":"1.0.0","node":"esp32-lab-1","ts":1710000000}
// command (require TTL once you leave pure demos)
{"relay":1,"state":"on","by":"pi-rules","ttl_s":300}
Pi broker checklist
- Image Pi OS, SSH key login, updates.
sudo apt install mosquitto mosquitto-clients- Local pub/sub:
mosquitto_sub -t 'lab/#' -vin one shell;mosquitto_pub -t lab/sys/heartbeat -m okin another. - Password auth before any non-lab exposure; firewall: no MQTT on WAN.
Validation tests (pass/fail)
| Test | Pass criteria |
|---|---|
| Local pub/sub | Pi sees its own message |
| Node online | Telemetry within 30 s of power-up |
| Reboot Pi | Broker returns; node reconnects ≤2 min |
| Reboot node | Status + telemetry resume without reflash |
| Command path | Safe load toggles only on valid payload |
| WAN check | MQTT port not reachable from outside LAN |
Security minimums
- No open MQTT on WAN for v1 — ever.
- Unique passwords; do not reuse Wi-Fi PSK as MQTT password.
- Low-voltage practice loads until enclosures and ratings are real.
Export it like code
lab-mesh/
docs/TOPICS.md
pi/mosquitto.conf.snippet
esp32-node/ (PlatformIO project)
payloads/examples.json
TESTS.md # checkbox results with dates
Verdict
A “mesh” marketing word is not a plan. MQTT on LAN with boring JSON is a plan. Get one sensor publishing before you buy five more boards.