To totally unlock this section you need to Log-in
The following small article will show how to prevent, also after a reboot, to have the WiFi connection in sleeping mode after a while on Raspberry Pi 4. This is quite useful if you establish, for example, a server role on Raspberry Pi 4 and the only connection used, in a LAN environment, is by using WiFi technology and not wired Ethernet.
To prevent Wifi to go on sleeping mode on a Raspberry Pi 4 we can just issue the following command (if our WiFi network module is seen in Linux as wlan0, and usually it will be wlan0 if you will use the embedded module on the device), but take not that :
iwconfig wlan0 power off
To be sure that, after each reboot of the Raspberry Pi, it will does not let WiFi module to go on sleep after a while, we can modify the /etc/rc.local file (with root access or by using sudo) in the following way (basically adding the above command in the last part of the file):
# sudo nano /etc/rc.local #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi iwconfig wlan0 power off exit 0
After saving this small change, we can reboot the device to check the Power Management status will be to off by using iwconfig command:
# iwconfig wlan0 IEEE 802.11 ESSID:"Flag5" Mode:Managed Frequency:5.22 GHz Access Point: F8:08:4F:21:C5:34 Bit Rate=195 Mb/s Tx-Power=31 dBm Retry short limit:7 RTS thr:off Fragment thr:off Encryption key:off Power Management:off Link Quality=40/70 Signal level=-70 dBm Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 Tx excessive retries:1 Invalid misc:0 Missed beacon:0
Check the connection info
When you have the WiFi up and running, what are the output of iw wlan0 link and iw wlan0 station dump? Then once the wifi is lost, what are the output of both commands?
And once you have lost wifi, are you still able to view your wifi network?
sudo iw wlan0 scan | less
Run the above on your RPi when it has lost the connection, and see in the output (might take several seconds to be displayed) if there is your wifi network name.