23

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.

Ingo
  • 42,107
  • 20
  • 85
  • 197
participant
  • 951
  • 2
  • 7
  • 20

3 Answers3

26

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.

Dougie
  • 5,301
  • 10
  • 19
  • 28
25

Power save mode was an issue years ago on older versions of Raspbian. But it is fixed for a long time. Now it is disabled by default with the WiFi driver brcmfmac. You will find it if you grep the journal for the driver:

rpi ~$ journalctl | grep brcmfmac:
Apr 14 22:13:28 raspberrypi kernel: brcmfmac: F1 signature read @0x18000000=0x15264345
Apr 14 22:13:28 raspberrypi kernel: brcmfmac: brcmf_fw_map_chip_to_name: using brcm/brcmfmac43455-sdio.bin for chip 0x004345(17221) rev 0x000006
Apr 14 22:13:28 raspberrypi kernel: brcmfmac: brcmf_c_preinit_dcmds: Firmware version = wl0: Feb 27 2018 03:15:32 version 7.45.154 (r684107 CY) FWID 01-4fbe0b04
Apr 14 22:13:28 raspberrypi kernel: brcmfmac: brcmf_c_preinit_dcmds: CLM version = API: 12.2 Data: 9.10.105 Compiler: 1.29.4 ClmImport: 1.36.3 Creation: 2018-03-09 18:56:28
Apr 17 09:01:27 raspberrypi kernel: brcmfmac: power management disabled

As you see, it is power management disabled. So there is no need to worry about it. You don't need to disable it again.

Update after getting information about used hardware:
If you do not have an on-board WiFi and using an USB/WiFi dongle then you will not find brcmfmac because there is another driver loaded for the dongle. To execute programs on boot up you can use a systemd Unit file. 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
Ingo
  • 42,107
  • 20
  • 85
  • 197
  • 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. – participant Apr 18 '19 at 16:29
  • @participant It is an important information. You should have said it in your question. On a Raspberry Pi with on-board WiFi wlan0 is used for it and wlan1 for additional USB/WiFi dongle. So what version of Raspberry Pi do you use? Please edit your question and complete it. – Ingo Apr 18 '19 at 17:01
  • @participant I have updated my answer. – Ingo Apr 18 '19 at 21:22
  • Isn't rpi ~$ sudo systemctl enable|disable wifi_powersave@off.service sufficient, because the default behavior is power save on? – participant Apr 23 '19 at 21:01
  • @participant Yes, it's only nice to have to switch off and on, maybe for testing. Maybe the Edimax wifi dongle supports power save? If you only want one service then replace %i with off and sudo systemctl enable wifi_powersave.service. – Ingo Apr 24 '19 at 09:49
  • Awesome systemd magic. I modified this on my system be @$WLANDEV instead of @STATE (/sbin/iw dev %i set power_save off) just in case there are multiple Wifi devices. – Samveen Sep 05 '20 at 11:51
  • 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". – Philipp Ludwig Dec 05 '20 at 17:53
  • Oh and your systemd service does not work the way you describe it, as systemctl cannot find the service. Therefore I created a standard service the usual way. – Philipp Ludwig Dec 05 '20 at 17:59
  • 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. – Peter Gloor May 08 '21 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 Jun 21 '21 at 08:43
  • 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. – João Ciocca Mar 17 '23 at 23:08
4

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
Bim
  • 151
  • 3
  • This works! Only thing that did on a 3A+ with 64bit raspberry pi os. – cmc Mar 01 '23 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. – João Ciocca Mar 17 '23 at 23:15