← All Articles

Building a Self-Healing Sensor Network with ESP32 and MQTT

Most DIY sensor setups fail silently — a node drops off the network and you don't notice until your grow tent cooks your seedlings at 3am.

The architecture

After three iterations, here's what I settled on:

Why MQTT

MQTT's publish/subscribe model means nodes don't need to know about each other — they just publish to topics. The broker handles routing.

client.will_set("sensors/tent1/status", "offline", retain=True)
client.connect("broker.local", 1883)
client.publish("sensors/tent1/status", "online", retain=True)

The retain=True flag is the trick: any subscriber that connects later immediately gets the last known status.

Results

Twelve nodes across the shop, running for three months. Two hardware failures, both caught within minutes instead of hours. The seedlings survived.

Building a Self-Healing Sensor Network with ESP32 and MQTT · reannafrancis.dev