Skip to content

Instantly share code, notes, and snippets.

@mkb
Last active March 3, 2022 19:12
Show Gist options
  • Save mkb/40bf48bc401ffa0cc4d3 to your computer and use it in GitHub Desktop.
Save mkb/40bf48bc401ffa0cc4d3 to your computer and use it in GitHub Desktop.
Disable power management on Raspberry Pi USB Wifi interface

Too early to tell whther this solved my problem but recording for posterity anyway. In theory this will stop my Raspberry Pi from dropping off the network after it has been idle for a while.

Before

pi@dashboard ~ $ iwconfig
wlan0     IEEE 802.11bgn  ESSID:"Professor Ping"
     Mode:Managed  Frequency:2.437 GHz  Access Point: B8:E6:25:9B:62:02
     Bit Rate=39 Mb/s   Tx-Power=20 dBm
     Retry  long limit:7   RTS thr:off   Fragment thr:off
     Power Management:on
     Link Quality=43/70  Signal level=-67 dBm
     Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
     Tx excessive retries:70  Invalid misc:14   Missed beacon:0

lo        no wireless extensions.

eth0      no wireless extensions.

Note: Power Management:on

Then

sudo nano  /etc/network/interfaces

add line: wireless-power off

After

pi@dashboard ~ $ iwconfig
wlan0     IEEE 802.11bgn  ESSID:"Professor Ping"
          Mode:Managed  Frequency:2.437 GHz  Access Point: B8:E6:25:9B:62:02
          Bit Rate=26 Mb/s   Tx-Power=20 dBm
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=43/70  Signal level=-67 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:29  Invalid misc:8   Missed beacon:0

lo        no wireless extensions.

eth0      no wireless extensions.

Note: Power Management:off

OK, new theory: pm-utils is disabling the interface.

Based on pm-utils info on ArchWiki I found a hook invoking wpa_supplicant to disable the wifi interface:

$ cat /usr/lib/pm-utils/sleep.d/60_wpa_supplicant

#!/bin/sh

# /etc/pm/sleep.d/60_wpa_supplicant
# Action script to notify wpa_supplicant of pm-action events.

PATH=/sbin:/usr/sbin:/bin:/usr/bin

WPACLI=wpa_cli

case "$1" in
    suspend|hibernate)
        $WPACLI suspend
        ;;
    resume|thaw)
        $WPACLI resume
        ;;
esac

exit 0

To disable that hook I created a dummy hook in 1/etc/pm/sleep.d/`:

sudo touch /etc/pm/sleep.d/60_wpa_supplicant
sudo chmod 644 /etc/pm/sleep.d/60_wpa_supplicant # Instructions said no exec flag

I rebooted for good measure. We'll see whether this one takes.

@mapagm
Copy link

mapagm commented Aug 27, 2017

I'm also interested...

@dachshund-digital
Copy link

dachshund-digital commented Sep 19, 2017

Did this work? Trying to ensure USB power management is disabled on a Raspberry Pi, but typical Debian Jessie install on Raspberry Pi, does not have pm-utils installed, does not have a /etc/pm directory tree at all.

@LiquidFire
Copy link

Thank you so much! For me the solution in gistfile2.md works (on RPi 4, Raspbian buster) and the WiFi finally works properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment