Prevent Raspberry Pi Dropping WiFi

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

 

11 comments

  1. 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.

    Like

  2. 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”.

    Like

  3. 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

    Like

    • 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.

      Like

Leave a reply to raza Cancel reply