24

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.

4 Answers 4

26

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]
13
  • 1
    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
  • 7
    " Now it is disabled by default with the WiFi driver brcmfmac" - Not the case on my Raspberry 4 with default settings. It says "power save enabled". Commented Dec 5, 2020 at 17:53
  • 4
    "Now it is disabled by default with the WiFi driver brcmfmac" seems to be OS version related. Power Management is enabled on my Raspberry Pi 3 Model B Rev 1.2 using Raspberry Pi OS Lite released 2021-03-04. Like @PhilippLudwig I created a standard service. Commented May 8, 2021 at 12:48
  • 5
    @PeterGloor As far as I know the Foundation changed the default setting from powersave disabled on operating system Raspbian to powersave enabled on the Raspberry Pi OS.
    – Ingo
    Commented Jun 21, 2021 at 8:43
  • 1
    I'm using a Raspi Zero W with onboard wifi, but for a retropie. It seems the retropie's latest Raspi Zero image comes with powersave enabled - I remember having set if off the first time I sat with it, but now when I came to mess with it the second time, all the ssh suffering started again. 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
27

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.

2
  • 1
    haha googling for the subject I found your post on the official forums! This one worked, and I thank you and upvote you! Commented Mar 17, 2023 at 23:20
  • A smart one :-)
    – domi27
    Commented Mar 20 at 18:32
5

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
2
  • This works! Only thing that did on a 3A+ with 64bit raspberry pi os.
    – cmc
    Commented Mar 1, 2023 at 21:58
  • I had upvoted, but this one failed me =( this setting makes no difference for the Raspi Zero W running retropie... I restarted the device, 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
2

It's 2024; the most popular answers here are out-of-date

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?

Instead, use one of the two current solutions below.

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 :)

Answer 1: Use 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:

  1. not deprecated
  2. so much simpler than creating a systemd unit file
  3. the most reliable option, and has exactly the same effect

Why use anything else?

Well... what about using nmcli - the designated network manager for RPi??

Answer 2: Use 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

Not the answer you're looking for? Browse other questions tagged or ask your own question.