Tech
19 Sep 2026
5 min read
ESP32 MQTT Sensor State: Publishing DHT22 Temperature and Humidity as One JSON Message
A DHT22 read produces temperature and relative humidity from the same sampling event. Publishing them on separate MQTT topics works, but it also creates two independent message boundaries. A subscriber can receive the new temperature before the matching humidity value arrives. Putting both measurements in one payload preserves the relationship explicitly: {"temperature":25.34,"humidity":60.21} MQTT does not require JSON. The useful property here is that both measurements travel in one publication and can be treated as one sensor-state snapshot.