- Nov 24, 2026
- 3 min read
Reason 15: The Wi-Fi Password That Was Right and Wrong
New firmware flashed. Serial log:
[WiFi] Connecting to '<my-ssid>'...
[WiFi] Connecting to '<my-ssid>'...
[WiFi] Connecting to '<my-ssid>'...
Forever. The password came straight from my laptop’s NetworkManager profile, the one it was connected with right now. It had to be right.
Stop guessing: ask the radio
Instead of re-flashing with variations, I flashed a throw-away diagnostic
sketch. It uses the same generated config.h as the real firmware, scans,
prints each network’s channel and signal, and prints the disconnect reason.
It prints the password’s length, never the password:
WiFi.mode(WIFI_STA);
int n = WiFi.scanNetworks();
for (int i = 0; i < n; i++)
Serial.printf("'%s' ch%d %ddBm\n", WiFi.SSID(i).c_str(), WiFi.channel(i), WiFi.RSSI(i));
Serial.printf("ssid_len=%d pass_len=%d\n", strlen(WIFI_SSID), strlen(WIFI_PASSWORD));
WiFi.onEvent([](WiFiEvent_t e, WiFiEventInfo_t info) {
if (e == ARDUINO_EVENT_WIFI_STA_DISCONNECTED)
Serial.printf("disconnected reason=%d\n", info.wifi_sta_disconnected.reason);
});
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Two facts came back:
- The network was there: channel 8, −63 dBm. Not a range problem.
- Disconnect reason 15: 4-way handshake timeout.
| Reason | Meaning | Usual cause |
|---|---|---|
| 2 / 202 | auth expired / auth fail | wrong password or security mode |
| 15 / 204 | 4-way handshake timeout | wrong password |
| 201 | no AP found | SSID typo, or a 5 GHz-only network |
| 200 / 203 | beacon timeout / assoc fail | weak signal, busy AP |
How the right password was wrong
The laptop was connected on the 5 GHz band. The ESP32 only speaks 2.4 GHz. And the laptop had three saved profiles with the same SSID, created at different times, with different passwords. The active one was the 5 GHz profile. An older profile had the password that the 2.4 GHz band actually accepts.
So both statements were true: the password was correct for the network the laptop was on, and wrong for the network the ESP32 could see.
Comparing secrets without showing them
I didn’t want any of the passwords on screen, in a terminal log or in shell history. NetworkManager can print a secret to a pipe, so the profiles were compared by hash:
for n in "<ssid>" "<ssid> 1" "<ssid> 2"; do
echo "$n $(nmcli -s -g 802-11-wireless-security.psk connection show "$n" | sha256sum | cut -c1-8)"
done
Two profiles matched each other; the old one was different. The working one went straight into a private file, and a sanity check printed only its length and whether it contained special characters:
umask 077
nmcli -s -g 802-11-wireless-security.psk connection show "<ssid>" | head -c -1 > ~/.esp32-wifi-pass
Flashed. An IP address within seconds.
The $ that Make would have eaten
That password contains a $. Passing it as a Make variable
(make upload WIFI_PASSWORD=...) would have been silently wrong: Make expands
$ sequences itself. So the build takes a file instead:
make -f linux.mk upload SKETCH=esp32_panel_dht_pump_winter PORT=/dev/ttyACM0 \
WIFI_PASSWORD_FILE=$HOME/.esp32-wifi-pass
rm -f ~/.esp32-wifi-pass
The Makefile copies the sketch to a temporary build folder, writes config.h
there with 0600 permissions, and deletes it after a successful upload. The
secret never lives in the repo, the command line or the build output.
A related one from the Windows side: the network profile there was named
<ssid> 3, and that name, not the broadcast SSID, ended up in the firmware.
That’s reason 201, “no AP found”, for a network that was right there.
Takeaways
- Print the disconnect reason before changing anything. Reason 15 means password; 201 means name or band.
- ESP32 is 2.4 GHz only. The laptop’s current band tells you nothing.
- Same SSID, several profiles, different passwords is more common than it sounds.
- Compare secrets by hash, store them
0600, and keep them out of Make variables.
Next in this series: Home Energy From a Shelly Pro EM: Trust the Counters
Part 6 of 8. Start with the series overview.