ESP32 & ESP8266 Connectivity · Intermediate · MQTT
ESP8266 MQTT Sensor Node
A sensor that publishes to your own broker and subscribes to a command topic.
Firmware status: Generated from this project's own pin map and compiled with arduino-cli for esp8266:esp8266:nodemcuv2 before publication; bench validation on your hardware is still required..
Hardware scope
MQTT publish and subscribe, retained state, reconnect with backoff. Pins assigned by the generator: out 1 → GPIO5, sense → GPIOA0.
Components
- ESP8266 board
- Analog sensor on A0
- LED or relay on a GPIO
- Local MQTT broker (Mosquitto on any machine)
Tools
- USB programming cable
- Multimeter
- Current-limited bench supply (for anything that switches a load)
- Small screwdriver and wire cutters
Build steps
- Run a broker and confirm it is reachable from the network with a laptop client first.
- Set the broker address and flash. Watch the connect line and the subscribe acknowledgement.
- Publish `1` to `<prefix>/set` from the broker's own client and watch the output change.
- Stop the broker, watch the node report failures, restart it and watch the node reconnect unattended.
Test and expected result
Telemetry appears on the broker every fifteen seconds, the command topic switches the output, and the node reconnects after the broker restarts.
Acceptance checks
telemetry published, command switches output, reconnect after broker restart
Safety and limits
MQTT here is unencrypted and unauthenticated on the local network. Do not carry credentials or personal data over it.
Guide source: Generated from this project's own pin map and compiled with arduino-cli for esp8266:esp8266:nodemcuv2 before publication; bench validation on your hardware is still required.
Download connection diagram SVG
Related projects
- ESP32 Captive Portal Wi-Fi Manager — Boot the ESP32 with no credentials and configure its network from a phone, with the portal saved to flash.
- ESP8266 Config Portal — The same idea on the cheapest board that can do it: an ESP8266 that configures itself from a browser.
- ESP8266 Sensor Portal Logger — A battery-minded sensor node you configure in the field, with the reading shown on its own setup page.
