I came across an infuriating problem where my Pi would randomly become inaccessible over WiFi. Turns out the problem was that the Pi WiFi controller has power_save on by default even with a ‘Lite’ headless build.
Use this command to read the current power saving mode of your Pi:
sudo iw wlan0 get power_save
And this one to turn power_save off:
sudo iw wlan0 set power_save off
To make this permanent add the following line to /etc/rc.local:
/sbin/iw dev wlan0 set power_save off
Note: the keyword dev is not used in the interactive commands but it is good practice to include it in a script
Note2: Make sure you add this above any exit lines (e.g. exit 0) otherwise it will never run! – Thanks AthlonFX
If this problem is affecting you then you should see the following in your syslog:
{TIMESTAMP} raspberrypi dhcpcd[{PID}]: wlan0: carrier lost
Thanks for this, it has been driving me crazy for weeks. Strange thing is that is was dropping out during downloading so there must be a problem with the Stretch power saving code. This little trinket also seems to have improved download speed. Hopefully this is sorted for me but i’ll let you know otherwise. It might help others of lesser coding EXP if you stated it should be first in the script as mine defaults to some exit code.
LikeLike
Nice trick!
LikeLike
Thanks
LikeLike
Thank you very much for this tutorial. You should state that the line
“/sbin/iw dev wlan0 set power_save off”
has to be ABOVE the line
“exit 0”
in the file “/etc/rc.local”.
LikeLike
Im unable to edit the file as it opens a new file, looks like the file is read only. Im using RPi zeroW with raspbian stretch, strange thing is the same rpi with the same image but a different sd card worked like a charm with no issues. Dont know why I can not edit even with sudo
LikeLike
Which file is it you’re having trouble with?
LikeLike
rc.local, im trying sudo nano /etc/rc.local,but nano actually opens a new file
LikeLike
That’s fine, it could be that there is no rc.local present on your install, or the file is empty. As long as your spelling is right, it shouldn’t matter.
LikeLike
rc.local is present but its not in text format, looks like it is a bash file as it has > icon
LikeLike
Bash files are in text format, so I’m not sure what you mean. You can only have one file with a given name, so even if it exists as a binary nano wouldn’t open a new blank file with the same name.
My advice is to run the command as you have been, enter the information in the blank file and save it. If you’re worried then back it up first using the the ‘cp’ command.
LikeLike
Thx
LikeLike