Recently I set up a Raspberry Model A+ with a Python script to log temperature to the internet. I used an Edimax EW-7811 WiFi dongle to connect to it using SSH. This worked fine but occassionally I would lose the connection for no apparent reason.
After a bit of Googling it appeared that a power saving mode might be responsible. It seems the dongle turns off if no one is typing at a keyboard. Even if the dongle is constantly transferring data via WiFi it just gives up. Not sure why the hardware would be programmed to do that because it’s completely insane. I’m all for power saving but I like WiFi to stay up when I’m actually transferring data over it!
Luckily there is a solution. It involves disabling the power management so the dongle stays connected. The following technique should work for all WiFi dongles that use the Realtek RTL8192 chipset.
Disable Power Management
First you read the power management flag using :
cat /sys/module/8192cu/parameters/rtw_power_mgnt
This will report a value of “1”.
To set it to zero you can use :
sudo nano /etc/modprobe.d/8192cu.conf
and add the following line :
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
To quit from nano use [CTRL-X], [Y] then [ENTER].
You are now ready to reboot using :
sudo reboot
Options
The two options we set in the configuration are rtw_power_mgnt and rtw_enusbss. If you are interested they take the values defined below :
- rtw_power_mgnt
- 0 = disable power saving
- 1 = power saving on, minPS
- 2 = power saving on, maxPS
- rtw_enusbss
- 0 = disable auto suspend
- 1 = enable auto suspend
So setting them both to zero disables “power saving” and “auto suspend”.
External References
Here are a couple of sites I used on my quest :
6 Comments
I was wondering why I was getting disconnected
Thanks,
Thank you so much, this had been bugging me for ages.
What worked for me was to add wireless-power off to the /etc/network/interfaces file after the wpa supplicant statement e.g. auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
wireless-power off
iface default inet dhcp
http://www.jamesrobertson.eu/blog/2015/jun/15/solution-raspberry-pi-wifi-cutting.html
Does this apply to the Raspberry Pi 3 as well?
Probably not as it will use a different hardware device with a different driver.
It’s a known problem on the Pi 3. “Makezine” has quoted Eben Upton as saying it will be fixed “eventually”. Make what you will of that. I have experienced the same problem and have, for the moment, abandoned the WiFi interface on the PI 3 and gone back to wired Ethernet. I have put a USB “WiPi” dongle on one of my other Pi’s to free up a port on my router.