Disabling WiFi Power Management Permanently for Raspberry PI 3 with Raspbian Jessie
- Ben Liebowitz
- 24
- 8408
One problem I found when playing with my Raspberry PI3 (running Raspbian Jessie), is that the WiFi would drop after a certain amount of inactivity. This was problematic at VMUG Meetings, and due to lack of having a screen to connect, I was forced to power-cycle the unit to get it back online. After doing some googling, I found the built-in WiFi for the Raspberry PI 3 had some Power Management features, which were enabled by default.
You can check the status by running the follow command:
sudo iwconfig wlan
I found a simple command to disable the power management features, however the command only lasted until the next reboot and then went back to the default setting. The command is below
sudo iwconfig wlan0 power off
After doing some investigating, I came across this blog post on how to run a script at startup. This enabled me to put the above command into a script and run it at startup! http://www.raspberrypi-spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/
The steps were simple.
1. Make sure you’re in the /home/pi directory
2. Run the command below to create a script :
sudo nano script.sh
3. Enter the command above into the new script.sh file. Don’t forget to include the first line though, or it won’t run properly. You also don’t need SUDO before iwconfig here, as the script is being run at an elevated level already. 🙂
#!/bin/sh - iwconfig wlan0 power off
CTRL-X then Y and Enter will save the file.
4. Next, we have to create a configuration file (aka a unit file) that tells systemd what we want to do when…
sudo nano /lib/systemd/system/myscript.service
5. Enter the text below into the text editor
[Unit] Description=My Script Service After=multi-user.target [Service] Type=idle ExecStart=/home/pi/script.sh [Install] WantedBy=multi-user.target
6. The permissions on the unit file need to be set to 644.
sudo chmod 644 /lib/systemd/system/myscript.service
7. Verify the permissions were set properly.
ls –l /lib/systemd/system/myscript*
8. Now that the unit file has been defined, we can tell systemd to start it during the boot sequence.
sudo systemctl daemon-reload
9. Next.
sudo systemctl enable myscript.service
10. Finally, REBOOT!
sudo reboot
11. Once your PI is back online, login and check the status now…
sudo iwconfig wlan0
Enjoy!
Ben Liebowitz, VCP, vExpert
NJ VMUG Leader
24 thoughts on “Disabling WiFi Power Management Permanently for Raspberry PI 3 with Raspbian Jessie”
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
…that’ll work, but adding the ‘iwconfig wlan0 power off’ command to the /etc/rc.local script is a much simpler solution!
Yes. Worked for me!
Glad to be of help!
@Antoine Megans – Thank You for the simple way.
For me, this reduces excessive tx retries by factor of 10, and ping “Request timeout” by factor of 2 on Pi3 onboard WiFi.
Antoine Megens Sir,
This is the perfect solution. All the above description are just waste of time. Thank you Sir.
Yes, it is enough!
more simply is to specify “wireless-power off” in /etc/network/interfaces no annoying script and self documented setup, enjoy!
iface wlan0 inet manual
wireless-essid myessid
wireless-power off
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
How do i go on about this? sorry i dont know anything about anything about Pi. step by step would be nice, because the instructions above dont work. Step 7 ” ls –l /lib/systemd/system/myscript*” doesnt exists etc.
This method is only for Raspian Jessie and not any other OS version of Raspian?
and adding it to /etc/network/interfaces is the best solution!
In Raspian Stretch on my Pi3, adding “iwconfig wlan power off” to /etc/network/interfaces did not turn power management off. I had to add it to the /etc/rc.local to make it take effect.
thanks works also with me on raspbian “iwconfig wlan0 power off” is the right string
For script.sh, I needed to do a chmod+x to get this to work.
/etc/network/interfaces was empty on a clean install of Raspian Stretch.-has it been deprecated in Stretch?
New to Raspbian, but supposedly the point of doing it this way was to make sure that the system was in a known state before executing the script file
Works great for setting up an raspberry pi 2 as an airplay receiver.
This was written against a PI running a version of Raspbian from 2016. I can’t guarantee it will work with newer releases of the OS.
Thanks for this, something I’ve found, and not just with your commands; when I copy them into putty ssh the ‘l’ (L) becomes a ‘1’ (one) and the command is rejected…
Hmm, that sounds like a problem with your PC and the clipboard. Sorry.
If you have entered all the information and it does not seem to work..
Try: “sudo systemctl status myscript.service” to output the status of your service.
If the output says “203 Exec failure” you might need to add the following to the script.sh file (note the part after ‘ExecStart=’:
[Service]
Type=idle
ExecStart=/bin/bash /home/pi/script.sh
Hope this helps for people struggling with this!
A much easier way, that doesn’t even require a script, is to use cron to run your command for you on boot. Since you want the command run as root, we will put it in the root crontab. We will be editing here, so be sure to set your EDITOR variable first if you don’t want nano — I’m an old UNIX guy so I use vi.
# Edit root’s crontab
$ sudo crontab -e -u root
Add a line that looks like:
@reboot iwconfig wlan0 power off
Save the file and reboot. Cron will run the command as root each time your Pi boots.
That method works too. Thanks for sharing!
Add one more line into the instruction: chmod +x script.sh
Thanks a lot, this resolved my issue as script was not working 🙂
Glad this helped!
I found that before I could enable the .service file through systemctl, I had to specify and alias as well.
For some reason – my entry of the iwconfig command would not take effect in either /etc/rc.local or root’s crontab @reboot. I looked around among those initialization scripts in init.d and systemd but I didn’t see much of anything that could have led to persistent power: on state. So to keep it simple, I decided to just leave the command in the pi user’s .bashrc – this is one of the final steps after startup, so I assume it would override any prior action that still eludes me.
#.bashrc
sudo iwconfig wlan0 power off