I have a Raspberry Pi Zero W project that needs a network connection for some of its functionality. The device normally does not have a keyboard and display attached, as it's operated by hardware switches and sensors. Most of the updating/debugging is done via an
ssh connection. So it's a big pain if the WiFi connection goes bad.
What could be the possible explanation for the following WiFi connection problem:
The device boots up and the boot log kind of confirms that connecting to the network is successful:
[ OK ] Started WPA supplicant [ OK ] Reached target Network
$ ifconfig wlan0 shows that it has received its assigned IP address 192.168.x.x. But it can neither be pinged from another PC in the network nor the router address 192.168.1.1 can be pinged from the Pi. Actually, when trying to ping the Pi from another PC, instead of "Destination Host Unreachable" it just gets stuck, ping does not generate new retries.
$ sudo iwlist wlan0 scan gives a list of available networks, so apparently there is no problem with the antenna. Running
$ sudo wpa_cli -i wlan0 reconfigure does not fix the situation.
And then, after a while, spontaneously, it can suddenly reconnect and everything is fine until it's not again.
Update with Info from comments:
I use just a plain raspbian default. When the device spontaneously reconnects, there are no connection problems, both from Pi and to Pi.
There are two wifi network configurations, one for the router, another for my mobile hotspot. But the hotspot is not active, and the IP address that I get with ifconfig wlan0 is the one that is properly assigned by the router's DHCP. Ok, I don't know, maybe it's not freshly received, maybe it's remembering the last address somehow.