Utility · keep open during the lab
Troubleshoot
Networked systems fail in layers, and the layers fail differently: a firewall drops silently, a missing listener refuses loudly, a topic typo delivers nothing while everything reports success. Climb in order, each layer has a one-command test, and read the failure's signature before changing anything.
Debug in layers
connect_wifi print an address; B, does mosquitto_sub -h <pi-address> from another machine connect (and which way does it fail); C, does the client's connect() return without an exception; D, does mosquitto_sub -t "#" -v on the Pi show your message, with the exact topic you think.Symptoms and fixes
| Layer | Symptom | Likely cause | Fix |
|---|---|---|---|
| A | The bench/home SSID never appears to the node; phones see it fine | 5 GHz-only network: the ESP32's radio is 2.4 GHz only | Use a 2.4 GHz network or enable the router's 2.4 GHz band; hotspots often have a "compatibility" toggle |
| A | connect_wifi times out with the right SSID | Wrong password; or the network needs a login page (captive portal), which the node cannot complete | Re-enter credentials in config.py; use the bench network, not a portal network |
| B | Connecting hangs, then ETIMEDOUT / "no route" | Dropped silently: UFW on the Pi has no 1883 rule, or wrong BROKER_IP, or different networks | sudo ufw allow 1883; re-check hostname -I; confirm both machines are on the same LAN |
| B | ECONNREFUSED, immediately | Reached the Pi; no listener accepted: bench.conf missing, mistyped, or Mosquitto not restarted/failed | Re-check /etc/mosquitto/conf.d/bench.conf, restart, then systemctl status mosquitto and journalctl -u mosquitto -e |
| C | Connects, then drops at once (older setups: connect error 5) | Listener without allow_anonymous true: the broker demands credentials nobody sends | Add the line to bench.conf, restart, re-check status |
| C | Two stations take turns dying every few seconds | Duplicate client id: each connect kicks the other off | Station-unique ids: node-s07, monitor-s07 |
| C | ImportError: no module named 'umqtt' | Firmware without the frozen module | After Wi-Fi is up: import mip; mip.install("umqtt.simple"), or Thonny's package manager; see the node page |
| D | Node publishes happily; subscriber prints nothing; both report connected | Topic mismatch: case, a typo, s7 vs s07, or a stray space; topics are exact strings | Run the firehose, mosquitto_sub -t "#" -v, and compare the printed topic to the subscription, character by character |
| D | Python subscriber never fires callbacks, script just ends | No network loop running | End with loop_forever() (or run a background loop); callbacks only fire inside the loop |
| D | Monitor goes permanently silent after a broker restart, yet shows connected | Subscribed outside on_connect: the auto-reconnect carried no subscriptions | Move subscribe() inside on_connect, the reconnect-safe home |
| D | Prints b'42.3', or float() raises on a healthy-looking payload | Payload is bytes, not str | msg.payload.decode() before parsing; the node's .encode() is the other half of the contract |
| D | Every new subscriber instantly receives a stale or test value | Ghost retained message left on the topic | Clear it with an empty retained publish: mosquitto_pub -t "bench/s07/light" -r -n |
| D | Pasted tutorial code raises TypeError about callback arguments, or paho warns about a deprecated API | Online examples mostly predate paho-mqtt 2.x; the callback signatures changed | Construct with mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) and use this hub's signatures |
| D | Node ignores commands, telemetry fine | No check_msg() in the loop, or subscribed after messages were sent with nothing retained | Add client.check_msg() each cycle; re-send the command after the subscriber is up |
Before you ask for help
- Name your layer: which single-command test is the first one that fails?
- Name the signature: timeout or refused? Silent or an exception? Copy the exact message.
- Show the firehose:
mosquitto_sub -t "#" -voutput while your publisher runs settles most "it sends but nothing arrives" disputes in one line. - Say what you changed last, config files and restarts included;
systemctl status mosquittooutput in hand.