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.
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 [email protected]
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 [email protected]
rpi ~$ sudo systemctl enable [email protected]
# or
rpi ~$ sudo systemctl disable [email protected]
rpi ~$ sudo systemctl enable [email protected]
journalctl | grep brcmfmac
doesn't report anything, but iw wlan0 get power_save
reports Power save: on
. I'm using a Edimax Wifi dongle.
Commented
Apr 18, 2019 at 16:29
powersave disabled
on operating system Raspbian to powersave enabled
on the Raspberry Pi OS.
brcmfmac
shows power save enabled
on the journalctl - we must remember that Raspi isn't just the hardware, it depends on which flavor people are using ;) So while that could be truth for latest (or other versions of) Raspberry Pi OS, it may not be for others.
Commented
Mar 17, 2023 at 23:08
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.
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
cat
the file, the configuration was still there... but I was back on having trouble until I sudo iwconfig wlan0 power off
it.
Commented
Mar 17, 2023 at 23:15
The "accepted" answer remains accurate, but is showing its age through its choice of iwconfig
- as opposed to the newer iw
.
I also wonder about use of the deprecated /etc/rc.local
in the most-voted answer; it may still work, but why risk getting crossed up with systemd
?
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 off
permanent?
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 LP's software "solutions":
sudo nmcli con mod preconfigured wifi.powersave disable