8

I am using my raspberry pi as a headless server. The problem is that after a couple of hours of inactivity it seems to enter a power suspend state where it disappears from the web and refuses ssh connections. After having prodded it via ssh it comes back after a couple of minuttes and uptime informs that it has been alive all the while. This makes me think it is some kind of power management scheme that is in effect but I have read other places that the pi is not able to suspend.

Does anyone have an idea what is wrong?


Update:

After having spent a great deal of time trying to figure this out it seems a number smaller issues have helped:

  1. Configure postfix to not use ipv6.
  2. Use fail2ban to blacklist ssh login attempts.
  3. Update firmware on router.

All three items seems to have had a positive effect on the pi's uptime. It is now reasonably stable and I have not the login-problem for about three weeks.

Kenneth
  • 721
  • 1
  • 4
  • 11
  • Which OS are you using? – xxmbabanexx Apr 11 '13 at 13:44
  • even I face the occasional ssh failure when using my pi headless which a few retries resolve almost all the time.I use shellinabox to login my shell which seems faster for some reason I don't know.I am not sure about the security when using shellinabox but I access my pi mostly from within the LAN. – SteveIrwin Apr 11 '13 at 18:48
  • I am on a standard Raspbian setup (the pre-installed sd-card) with all the graphical stuff removed. – Kenneth Apr 11 '13 at 18:58

2 Answers2

14

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,056
  • 7
  • 12
  • I am not using wlan. It is plugged directly into the router. – Kenneth Jun 10 '13 at 12:42
  • Hmm, the only other thing is to recommend using a good quality usb cable to power the pi. (shorter is better too) I had issues with my units 'disappearing' which stopped when I used a decent cable instead of one of my handful of cheapies. The pi is _very_ sensitive to voltage dips. I imagine if you had a cheap usb cable and a 6V 1+A p/s you'd be fine, but the standard 5V 1+A p/s's voltage dips below pi's threshold due to I2R losses in the usb cable. – lornix Jun 13 '13 at 16:11
  • 1
    1. You only need `rtw_power_mgnt=0` 2. You can verify it's taken effect with `cat /sys/module/8192cu/parameters/rtw_power_mgnt`, which should return 0. – Air Sep 06 '15 at 00:41
5

The raspberry pi hardware has no power management capability. Period. End of story. It does not have a sleep or suspend mode. It cannot not even be turned off. There's either power (plugged in), or there isn't (not plugged in).

When you shutdown the system, the software stops, meaning there is now no way to get it to do anything again. However, the "power state" of the hardware is still the same (because it only has one state, on).1

So whatever your problem is, that is not it. You may want to look at your logs to see if anything else has been going on during the network downtime -- eg, (I'm speculating), if you have stuff attached to the usb ports that is near the limits of the pi's 150 mA output, that thing may intermittently fail, and if it's a wifi dongle, the system will then have to wait until the interface reappears. You'd see lots of evidence that in /var/log/syslog or /var/log/messages.

If it's any consolation, I use the pi headless on a WLAN and don't turn it off very often, and it's been pretty flawless. I use this methodology to ensure the connection stays up; peeking at the current log, it's had to reconnect itself only twice in the past 48 hours. However, I make pretty light use of it too, maybe occasionally there is a big download, etc., but not constant traffic (the more it's accessed the more opportunities there are for something to fail, so I can't say how reliable it would be serving a cafe full of people all day). Also, I have it on a 3.8A hub and the only thing plugged directly into the pi's usb is a "nano"-size wifi dongle.


  1. Not 100% true, since all models can have the SoC or significant parts thereof powered off, in which case the "power state" of the device could be said to have changed. This is what happens when the OS is shutdown properly (eg. via halt -p). The only way to power that stuff back up, though, is to cycle the main power to the board or reset the SOC (or PMIC for later models).
Milliways
  • 54,718
  • 26
  • 92
  • 182
goldilocks
  • 56,430
  • 17
  • 109
  • 217
  • Ok, power should not be a problem. I am using a 1A power supply and the only thing plugged into the pi is a usb hard-drive which runs off its own power supply. I am connecting directly to the router using the LAN on the pi, so no dongle either. The only thing in syslog that's not supposed to be there is a warning about IPv6 which should be disabled. Nothing about power. I think your scripting approach seems like a good way to go. I will attempt to try that tomorrow. – Kenneth Apr 11 '13 at 18:58
  • I have edited my question to describe what I have found. Since I have not found a single definitive solution to the problem I will mark your answer as being correct as it really put me on the path to troubleshoot this. Thanks for your help. – Kenneth Jun 10 '13 at 12:53
  • Wrt "... does not have a sleep or suspend mode": I think that's a true statement, but what do you call [this](https://raspberrypi.stackexchange.com/questions/114422/what-is-the-minimum-power-required-for-an-rpi-4-in-halt-or-shutdown)? – Seamus Jan 09 '21 at 22:30
  • Yeah, all models should do that (did not know it was complexified on the 4). It doesn't really make any difference to the issue here, but I've added a caveat footnote about it. – goldilocks Jan 10 '21 at 15:53