jcberthon / networkmanager-wifi-powersave.md
NetworkManager supports WiFi powersaving but the function is rather undocumented.
From the source code: wifi.powersave can have the following value:
- NM_SETTING_WIRELESS_POWERSAVE_DEFAULT (0): use the default value
- NM_SETTING_WIRELESS_POWERSAVE_IGNORE (1): don’t touch existing setting
- NM_SETTING_WIRELESS_POWERSAVE_DISABLE (2): disable powersave
- NM_SETTING_WIRELESS_POWERSAVE_ENABLE (3): enable powersave
Then I propose 2 files, only one of them needs to be put under /etc/NetworkManager/conf.d/ .
One is forcing to disable powersaving, while the other one enable it.
Once you have put the file in the right folder, simply restart NetworkManager:
sudo systemctl restart NetworkManager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
# File to be place under /etc/NetworkManager/conf.d |
[connection] |
# Values are 0 (use default), 1 (ignore/don’t touch), 2 (disable) or 3 (enable). |
wifi.powersave = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
# File to be place under /etc/NetworkManager/conf.d |
[connection] |
# Values are 0 (use default), 1 (ignore/don’t touch), 2 (disable) or 3 (enable). |
wifi.powersave = 3 |
Thnaks for this, used for my connection and latency in ssh sessions seems to be imroved:
CONN=»my wifi conn»; nmcli con mod «$CONN» 802-11-wireless.powersave 2
How to prevent wifi sleep after suspend
Every time I open my notebook lid I have to wait a few seconds for wifi to reconnect. I remember that in Windows it was already connected. I need a way to prevent wifi from disconneting on suspend. The closest answer I found was https://askubuntu.com/a/961460/613425 but it didn’t work. I also tried the iwconfig wlan0 poweroff in the answer but it didn’t work even before reboot.
So, unlike the question you linked above, your WiFi is not unstable. It connects and works fine after you open the lid and wake up the laptop from sleep. You want WiFi to connect more quickly. What would happen when you move your laptop 20 miles while it was sleeping? Would it still remain connected?
@user68186 it never remains connected, even in the same place after I reopen the lid. I have to wait for it to connect again.
Do you mean it never remains connected while it sleeps? I once knew someone who used to talk while sleeping, but my laptop doesn’t do that. I don’t think what you want is possible unless you stop your laptop from sleeping altogether.
What’s the output to iwconfig ? Please edit your question to provide the output there instead of here in the comments.
3 Answers 3
There are two ways of enabling WiFi after sleep. The first is a common patch to Network Manager as you can see I’ve made by listing the file:
Turn off or enable power savings as illustrated below:
$ cat /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf [connection] wifi.powersave = 3 # Slow sleep fix: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1670041 #wifi.powersave = 2
- Edit the Network Manager file shown above.
- Change WiFi.powersave from 2 to 3 (Enable power saving).
- If it’s already set to 3 try setting it to 2 (Disable power saving).
- After saving the file run sudo systemctl restart NetworkManager
The second is a systemd script which reloads the WiFi kernel module when resuming from suspend. It comes from this answer: Wifi available networks not showing up suddenly:
This script is written for iwlwifi` which is the common Intel driver name. If your’s is different change that name below:
#!/bin/sh # NAME: /lib/systemd/system-sleep/iwlwifi-reset # DESC: Resets Intel WiFi which can be flakey after a long suspend. # DATE: Apr 1, 2017. Modified August 30, 2017. MYNAME=$0 restart_wifi() < /usr/bin/logger $MYNAME 'restart_wifi BEGIN' /sbin/modprobe -v -r iwldvm # This removes iwlwifi too /sbin/modprobe -v iwlwifi # This starts iwldvm too # systemctl restart NetworkManager.service /usr/bin/logger 'systemctl restart NetworkManager.service (SUPPRESSED)' /usr/bin/logger $MYNAME 'restart_wifi END' >/usr/bin/logger $MYNAME 'case=[' $' ]' case "$/$" in hibernate|suspend|pre*) ;; resume|thaw|post*) restart_wifi;; esac
NOTE: Sometimes simply resetting network manager is all that is needed. In that case un-comment the line above by removing # . Then comment out the two lines above it by putting # at the beginning of those two lines.
You’ll need to create this script, called iwlwifi-reset , with sudo powers and save it into the directory /lib/systemd/system-sleep . Then mark it executable using:
chmod a+x /lib/systemd/system-sleep/iwlwifi-reset
How to turn off Wireless power management permanently
In Linux Mint 17.3 / 18 iwconfig says the power management of my wireless card is turned on. I want to turn it off permanently or some workaround on this issue. sudo iwconfig wlan0 power off works, until I reboot the laptop. Also, if I randomly check iwconfig , sometimes it’s on, despite I did run this command. I read some articles about making the fix permanent. All of them contained the first step «Go to directory /etc/pm/power.d «, which in my case did not exist. I followed these steps:
sudo mkdir -p /etc/pm/power.d sudo nano /etc/pm/power.d/wireless_power_management_off
#!/bin/bash /sbin/iwconfig wlan0 power off
sudo chmod 700 /etc/pm/power.d/wireless_power_management_off
But after reboot the power management is back on. iwconfig after manually turning power management off
eth0 no wireless extensions. wlan0 IEEE 802.11abgn ESSID:"SSID" Mode:Managed Frequency:2.462 GHz Access Point: 00:00:00:00:00:00 Bit Rate=24 Mb/s Tx-Power=22 dBm Retry short limit:7 RTS thr:off Fragment thr:off Power Management:off Link Quality=42/70 Signal level=-68 dBm Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 Tx excessive retries:2 Invalid misc:18 Missed beacon:0 lo no wireless extensions.
I don’t think this question applies only to Linux Mint, it is a general issue of particular wireless adapters.
Turn off WiFi adapter power saving mode
By default, some wireless adapters enable “Power Saving”. This is a “sleep mode”, or rather an energy-saving feature. This means that the adapter will turn off the network connection when inactive. This is not a problem when using Raspberry Pi as a client. Then the WiFi connection is simply reactivated. But if you want to remotely access Raspberry Pi via SSH for example, it may not be accessible. Then it looks like the WiFi adapter is not working. Only the energy saving function is active.
So it is necessary to turn off the power saving function.
For each wireless adapter, switching off the power saving function looks different. As a rule, the energy-saving function is always active. If you have problems reaching Raspberry Pi via the WiFi adapter you should first locate the manufacturer, if you do not already know that. Often, however, one also has to do with noname products.
In the short term, the problem can be solved by staking out the WiFi adapter and plugging it in again. Then it is reinitialized and Raspberry Pi is again accessible via the WiFi. However, this does not help as a permanent solution. So it’s about switching off the energy saving function permanently.
overview
To turn off the power saving mode of a wireless adapter, there are several options that do not all work. It essentially depends on whether the kernel supports the feature for the wireless adapter, or whether you need to choose a product-specific solution.
- Switch off energy-saving mode via the network settings (variant 1)
- Switch off energy-saving mode via the network settings (variant 2)
- Shut down energy-saving mode of a Wi-Fi adapter from Edimax (Realtek chipset)
If the first two variants do not work for the WiFi adapter used, then you should look for a product-specific solution.
Note: Name of the network interfaces
Since Raspbian Stretch, the Ethernet and WiFi network interfaces have different names. So no longer “eth0” and “wlan0”, but “enx …” and “wlx …”. This concerns USB-connected network adapters whose names differ from the designations mentioned here. This means that one must first determine the individual name or change the naming to the old method.
version 1
If there is no product-specific solution, you can try it via the network settings. To do this, open the file with the network settings:
sudo nano /etc/network/interfaces
Enter the following lines or add missing lines:
allow-hotplug wlan0 iface wlan0 inet manual wireless-power off
After saving and closing with Ctrl + O, Return, Ctrl + X all you have to do is reboot.
Note: Unfortunately, this setting does not work with some kernel versions.
version 2
To do this, open the file with the network settings:
sudo nano /etc/network/interfaces
Enter the following lines or add missing lines:
allow-hotplug wlan0 iface wlan0 inet manual post-up iw dev wlan0 set power_save off
This switches off the energy-saving mode due to the condition.
Save, close the file and restart the system.
Solution: Disable energy-saving mode of a WiFi adapter from Edimax (chipset from Realtek)
For this solution to work, the wireless adapter must have a Realtek chipset. In this example RTL8192CU.
Of course, there is the question of whether you have a wireless adapter with this chipset.
If the module “8192cu” is located in one line, then you can create a configuration file for the driver.
sudo nano /etc/modprobe.d/8192cu.conf
Insert the following line into this file:
options 8192cu rtw_power_mgnt = 0 rtw_enusbss = 0
For the shutdown is active, you should restart Raspberry Pi.
Solution: Check power management status
Whether the energy-saving mode of the WiFi adapter in question is actually switched off can only be checked in practice during runtime. But you can at least check whether the setting was adopted.
We install the wireless tools for this.
sudo apt-get install iw wireless tools
The command “iwconfig” informs about the WiFi interfaces.
Here the option “Power Management” should be set to “off”. But that does not mean it really works. Sometimes a configuration change of the drivers is necessary.
An alternative source of information for power management status:
Comments
Ubuntu 20.04: Why does turning off «wi-fi can be turned off to save power» turn my wi-fi off?
You can see that the option is currently turned on. That should mean that the system is allowed to turn off the Wi-Fi to save power. However, when I turn off that option, my Wi-Fi is disabled (turned off). I’m attempting to tell the system that it is not allowed to turn off Wi-Fi to save power. However, when I turn off the option it actually turns off the Wi-Fi. It’s seems that this item is not described properly in the Power. Settings. Note: This option was the same under Ubuntu 18.04 also.
2 Answers 2
That’s not what it means. Turning that off turns the WI-FI off, not the computer’s ability to turn Wi-Fi off. It has the «turning Wi-Fi off can save power» subtitle to tell you why you might want to turn Wi-Fi off. Just leave it on if you want Wi-Fi, or off if you don’t.
Oh, wow, that extra subtitle / comment needs to be changed. «Turning off the Wi-Fi functionality can save power.» or «If Wi-Fi is turned off, it can save power.» Windows(OS) had an option that the system could manage your wi-fi for you and turn it off and that is what led me to believe this meant that.
Oh, also notice that this is under the Power Saving features and under Blank Screen which is set to automatically go blank after 15 minutes. So, it puts you in a mental context that this will be the system deciding that «Wi-Fi can be turned off» to save power. It makes you think it is a system controlled thing like the blank screen is.
and that’s the reason why I had to travel back to my country to repair wifi of my remote computer that I controlled with TeamViewer or RDC . sad story. please, ubuntu developers, change that comment to explain first what it does. I just wanted to prevent my pc from turning wifi off to save battery in any situation and this options looked like thats what I needed, it did opposite. or at least, please, make alert message to confirm the action where you warn user.