Q How can I make iw wlan0 set power_save off permanent for stretch? What's the proper way to do it?
Edit I'm using an r-Pi 1 Mod. B with an Edimax wifi dongle and Raspian stretch.
Q How can I make iw wlan0 set power_save off permanent for stretch? What's the proper way to do it?
Edit I'm using an r-Pi 1 Mod. B with an Edimax wifi dongle and Raspian stretch.
I did it by simply adding a line to /etc/rc.local
/sbin/iwconfig wlan0 power off
Add that ahead of
exit 0
and it will run at every boot.
Power save mode was an issue years ago on older versions of Raspbian. It was fixed for a while, but has now (like a zombie) come back. It was disabled by default with the WiFi driver brcmfmac for a while - but not any longer. You will find it if you grep the systemd journal for the driver:
rpi ~$ journalctl | grep brcmfmac:
Apr 02 02:42:37 raspberrypi5 kernel: brcmfmac: brcmf_cfg80211_set_power_mgmt: power save enabled
And if you're not particularly keen on sifting through systemd's overly verbose "journal", a better way to determine the status of power_save is:
$ iw wlan0 get power_save
Power save: on
As you see, it is power_save on; it is enabled. One may wonder what sort of thinking led to a default setting of power save enabled on a device that is plugged into a mains outlet, but it is a mind fart that should probably be disabled on the Raspberry Pi.
One way to accomplish this is to build a systemd unit file which can execute the necessary command at boot. I will give you here a bit more comfortable example for switching off or on power_save. Create a Unit file with:
rpi ~$ sudo systemctl --full --force edit wifi_powersave@.service
In the empty editor insert these statements, save them and quit the editor:
[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
Now enable just what you want on boot up:
rpi ~$ sudo systemctl disable wifi_powersave@off.service
rpi ~$ sudo systemctl enable wifi_powersave@on.service
# or
rpi ~$ sudo systemctl disable wifi_powersave@on.service
rpi ~$ sudo systemctl enable wifi_powersave@off.service
The "accepted" answer remains accurate, but is showing its age through its choice of iwconfig - as opposed to the newer iw.
And the most-voted answer still advocates use of the long-ago deprecated /etc/rc.local. Too many answers here in SE are never updated!
N.B. : the default setting for power_save in (at least) both recent OS releases ('bullseye', 'bookworm') is enabled. This "power saving" is a poor tradeoff because it leads to balky SSH sessions - and maybe other issues. AFAICS there is no reason to enable WiFi power_save on a mains-powered Raspberry Pi!
In Other Words: The OP's question remains valid, or has regained validity:
How can I make
iw wlan0 set power_save offpermanent?
There are (at least) three ways to accomplish this, and as the accepted answer, and the most-voted answer failed to mention two of them, I feel duty-bound to add these answers :)
cron to "permanently" disable WiFi power_save:$ sudo crontab -e
which opens the root crontab in your chosen editor...
add the following line at the bottom of the root crontab:
@reboot /usr/sbin/iw wlan0 set power_save off > /home/<user>/power_save_log.txt 2>&1
be sure to substitute a valid folder name for '<user>' in the line above
cron is:
systemd unit fileWhy use anything else?
Well... what about using nmcli - the designated network manager for RPi??
nmcli:This will also work, but you must deal with the dyslexic syntax of another one of RedHat's software "solutions":
sudo nmcli con mod preconfigured wifi.powersave disable
This is still relevant for me when I want to use the RPi headless and log in through SSH, as there are no input devices plugged in and power management kicks in too early. Sometimes I couldn't log in via SSH, because the interface was already down. To permanently turn off WiFi power management, edit "/etc/network/interfaces" and add:
allow-hotplug wlan0
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
wireless-power off
# For second WiFi device, e.g. via USB
#allow-hotplug wlan1
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
#wireless-power off