Disabling WiFi Powersaving on Linux

I typically disable wifi powersaving on devices that are acting as servers instead of clients. Here’s how.

NetworkManager

Raspberry Pi defaults to using NetworkManager for their networking now, so use this if you’re using their OS. Or any other NetworkManager machine.

Do this as root:

mkdir -p /etc/NetworkManager/conf.d
printf '[connection]\nwifi.powersave = 2\n' | tee /etc/NetworkManager/conf.d/powersave.conf
chmod 600 /etc/NetworkManager/conf.d/powersave.conf

“2” apparently means disable powersave. I think 0 is do not manage powersaving, and 1 is explicitly enable it, but I might have those swapped. We’re not here to turn it on, we’re here to turn it off, so I do not care.

Then reboot or restart NetworkManager. This should apply to all radios. I don’t know if you need the chmod but when I was reading forum posts on the raspberry pi forums, someone had the chmod in there, so I did it on my thing too. Doesn’t hurt, anyway.

iw (for wpa_supplicant or manual config)

wpa_supplicant does not care what your wifi device’s powersave settings are and does not manager them. But you can use the iw command line tool to set it, as root:

iw wlp3s0 set power_save off

Replace wlp3s0 with yor wifi device name.

The annoying thing is some wifi radios forget the setting when they lose connection, so what I usually do is shove this into a crontab to keep running every few minutes:

*/5	*	*	*	*	iw wlp3s0 set power_save off

There is probably a smarter way with some kind of hook system. But the power consumption of turning power save off is much higher than the consumption of running a command every few minutes, so I do not care.

Why

If you’re curious, here’s why I do this:

The way wifi powersaving works is pretty transparent on a client, because when you send an outbound packet, wifi stays awake for a bit to listen for a response, and so latency stays good. And it also stays awake as long as inbound packets continue to come in. You pretty much never notice it’s a thing on a laptop in normal use, for example.

If this isn’t going on, the wifi device will check in way less often for packets, and so incoming packets will get dropped unless they happen to get sent in the window where the device is listening.

On a server it’s common for no network traffic to happen for long (in computer terms…) periods of time, wifi sleeps, and the device gets hard to talk to. If you’ve ever SSH’d into an idle laptop or a raspberry pi over wifi, and sometimes keystrokes are randomly laggy and then fine for a bit, this is what’s going on 98% of the time.

It’s even worse if you don’t have any active connections. Sometimes my pi zero w goes idle so long that my router forgets how to route to it (I guess it stops responding to arp too?) and so I have to ping the thing for a bit until it finally wakes up, and then I can connect in.

But if you disable wifi powersaving, the problem is solved! At the expense of power, of course, since the device is now always chatting on wifi. It should then be as responsive as something over an ethernet link, plus the extra few-ms latency inherent to wifi.