15

I am running my Raspberry Pi headlessly, connecting via SSH over the network. I am having a problem that I can consistently reproduce. I will leave a Python script running on my Raspberry Pi and come back a few hours later and SSH connections to the Raspberry Pi will time out.

If I ping it I get the following:

C:\Users\andrew>ping 192.168.1.42

Pinging 192.168.1.42 with 32 bytes of data: Reply from 192.168.1.46: Destination host unreachable.

The only way I can get it back on the network is to restart it (pull out the power).

Has anyone experienced this? Are there any log files I can look at to diagnose the issue?

Andy Smith
  • 432
  • 1
  • 5
  • 19

5 Answers5

9

The wireless device goes to sleep after a period of no activity. It's a powersaving scheme.

You need to turn off the powersave feature of wlan0.

I'm using an edimax wireless usb receiver:

Bus 001 Device 005: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]

It uses the 8192cu module in the kernel.

To turn off powersave, add the following to /etc/modules, or create a file (8192cu.conf) in /etc/modprobe.d/ with the line(s):

# prevent power down of wireless when idle
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

Next reboot (or rmmod/insmod) it should disable the sleepy mode and your pi will be accessible all the time.

I create the file for /etc/modprobe.d and it's part of a script I built to do preliminary setup on a new build.

lornix
  • 1,066
  • 8
  • 13
2

The problem for me was power management on the wifi as well, but I was not using a 8192cu chipset, so the instructions in the other answer didn't work for me.

Run iwconfig and look for the line that starts with power management

If it says that power management is on, you can turn it off with:

iwconfig wlan0 power off

N Reed
  • 121
  • 3
2

It is common for a router to disconnect inactive clients to free up router resources. This can happen at random times if the client has not been active.

1

I discovered that extensively ping-ing does bring up the wifi-connection again in my case. I observed that after the 70-100th ping the Pi starts responding and after that a ssh-connection can be initiated successfully.

Edit Turn power save off

iw wlan0 set power_save off

Click here for details.

participant
  • 981
  • 2
  • 8
  • 20
0

Earlier Raspberry Pis had issues with the wireless power management. Other answers have covered this. The power management can be turned off (until reboot) with iwconfig wlan0 power off or iw wlan0 set power_save off to check whether this helps.

Old Raspberry Pis that use ifupdown configure the wlan0 interface in /etc/network/interfaces. In those machines the setting can be made permanent by adding wireless-power off under the wlan0 definition. In newer machines you may be able to disable it by configuring the kernel module in /etc/modprobe.d/. Note that there are several different Realtek wireless drivers that your system may use: 8192cu, rtl8192cu, rtl8xxxu. You can alternatively type crontab -e and add the following line, making the command to be called at reboot:

@reboot sudo iw wlan0 set power_save off

Raspberry Pi 4 shouldn't have the same problem with power management, but there's another issue with dhcpcd that recent Pis use for configuring network interfaces. If you can connect a keyboard and a monitor, check whether dhcpcd is running (systemctl status dhcpcd). It may happend that dhcpcd is killed wtih SIGSEGV when running Docker containers that define virtual networks. In this case you should see the following message when you type grep dhcpcd /var/log/daemon.log:

systemd[1]: dhcpcd.service: Main process exited, code=killed, status=11/SEGV

The solution is to disable dhcpcd for virtual networks. Add the following line to /etc/dhcpcd.conf:

denyinterfaces veth*
Seppo Enarvi
  • 101
  • 1