Maker tech hub — AI · 3D print · Pi · ESP32 · plus the classic tech archive.

Free ESP32 kit · AI tools directory · Books · Archive

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…

Written by

Avery J. Parker

IT veteran, maker educator, and author of Network Ninja, 3D Printing Mastery, and AI Workflow Mastery. Business IT: Diversified Tech Solutions.

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.

Pi coordinator with ESP32 nodes over MQTT
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 command path that survives reboot.

Architecture roles

RoleHardwareResponsibility
CoordinatorPi 4/5 + Ethernet preferredMosquitto, logging, optional automation
Sensor nodeESP32 + BME280/DHTPublish telemetry JSON
Actuator nodeESP32 + opto relaySubscribe to safe low-V commands

BOM (starter lab)

ItemQtyBallpark USD
Raspberry Pi 4/5 + PSU1$55–90
microSD A2 or NVMe (Pi 5)1$10–40
ESP32 DevKit2$8–24
BME280 or DHT221–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

  1. Image Pi OS, SSH key login, updates.
  2. sudo apt install mosquitto mosquitto-clients
  3. Local pub/sub: mosquitto_sub -t 'lab/#' -v in one shell; mosquitto_pub -t lab/sys/heartbeat -m ok in another.
  4. Password auth before any non-lab exposure; firewall: no MQTT on WAN.

Validation tests (pass/fail)

TestPass criteria
Local pub/subPi sees its own message
Node onlineTelemetry within 30 s of power-up
Reboot PiBroker returns; node reconnects ≤2 min
Reboot nodeStatus + telemetry resume without reflash
Command pathSafe load toggles only on valid payload
WAN checkMQTT 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.

Related: Mosquitto review · home lab AI stack · gear

Repo pack: pi-esp32-mqtt-lab.zip