Sometimes folks report lost WiFi connections - one reason can be the WiFi power management deciding to lower the power consumption of the WiFi chip.
To see if power management is on:
$ iwconfig wlan0
...
wlan0 IEEE 802.11 ESSID:"MYSSID"
Mode:Managed Frequency:2.452 GHz Access Point: xx:xx:xx:xx:xx:xx
Bit Rate=65 Mb/s Tx-Power=31 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:on <-- POWER MANAGEMENT is ON
=== INSTALL WIRELESS-TOOLS for iwconfig
sudo apt-get install wireless-tools
=== TURN POWER MANAGEMENT OFF to limit Tx excessive retries and ping request timeouts
set temporarily with:
sudo iwconfig wlan0 power off
set permanently with:
See (wifi - Make "iw wlan0 set power_save off" permanent - Raspberry Pi Stack Exchange
$ sudo systemctl --full --force edit wifi_powersave@.service
[Unit]
Description=Set WiFi power save %i
After=sys-subsystem-net-devices-wlan0.device
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/iw dev wlan0 set power_save %i
[Install]
WantedBy=sys-subsystem-net-devices-wlan0.device
Then
$ sudo systemctl enable wifi_powersave@off.service
and reboot.
(Check it with “iwconfig wlan0” again)
If ever want it back on:
$ sudo systemctl disable wifi_powersave@off.service
$ sudo systemctl enable wifi_powersave@on.service
===== Another method ====
Supposedly there is a simpler method, (with a different effective time during the boot):
Add a line to /etc/rc.local
/sbin/iwconfig wlan0 power off
ahead of exit 0