Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running my 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 Pi and come back a few hours later and SSH connections to the Pi will time out.

If I ping it I get the following:


Pinging with 32 bytes of data:
Reply from 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?

share|improve this question
On a raspberry, I have only a cronjob running a python script, and it too will die after a few hours up to 2 days. I cannot SSH it anymore, only a restart by cutting power will help. – k0pernikus Feb 24 '13 at 10:52
@k0pernikus interesting! I am trying now running it with with the scren attached, so far (4 hours and counting) and it hasn't failed. Are you using screen at all? – Andy Smith Feb 24 '13 at 12:51
what's in your /etc/network/interfaces? Anything scary in dmesg? How is RPI connected to the network? Via a router? What's in the router's logs? If you re-plug the ethernet cable to RPI, will it bring it back to the network? – abolotnov Feb 25 '13 at 16:00
@abolotnov I'm actually finding this now if I run the RPI with a monitor attached - it seems to take longer, but when I come back after 6 or so hours it will be unresponsive. dmesg seems clear. – Andy Smith Feb 26 '13 at 7:26

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.

share|improve this answer
This was on a wired network – Andy Smith Jun 10 '13 at 8:35
Unfortunately, I have the same problem with these features turned off. Wireless adapter still gets turned off after a number of hours of inaction. – StasM Jul 31 '13 at 7:31
I am curious as to whether they're actually turned off. The modprobe.d files much be named particularly (x.conf) and spelling counts (as always). Is your wireless adapter a 8192cu unit? perhaps you need a different module? – lornix Aug 1 '13 at 6:52
@lornix: What command did you use to print out the type of wireless receiver you are using? – David Norman Aug 14 '14 at 15:08
lsusb and lsusb -v are very helpful. Figuring out which module isn't always easy, There are ways to match up output of modinfo 8192cu to the vendor:product numbers in lsusb output. – lornix Aug 15 '14 at 1:36

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.

share|improve this answer

I have the same problem I have resorted to pinging my router and if no response, I reboot.

Here is my code. It's a process that reads from a Xbee radio, logs the data and every 10 minutes it Tails the log file and uploads it to my server.

I need to to run unattended 24/365.

The following code runs when the system is started and runs as Root.

For some reason, I think Python kills the network AND ttyUSB0.

The climate monitor runs 24/365 and broadcasts Temp / Humidity every minute.

#!   /usr/bin/python3.2
import os

import serial

import time

from ftplib import FTP

import string

import re

ser = serial.Serial('/dev/ttyUSB0',timeout=600)


print("Starting Climate Sensor Logger\n\r")

linectr = 0

while 1:

    data = ser.readline()

    if (len(data) == 0) :
           os.system('reboot -n')

    # remove embedded nulls
    data = data.translate(None, '\0\n\r')

    tm = time.strftime('%x %X %p')

    ln = tm + " " + data  + "\r\n"
print ln 

    fo = open("Web.txt","a")

    linectr += 1

    if linectr > 29:

           linectr = 0

           # open raw input file and count lines

           counter = 0
           counter2 = 0

           print("Processing Climate measurements")
           f = open("Web.txt")
           for line in f:
                   counter += 1
           # tail 4320 lines (1440 readings)

           f = open ("Web.txt")
           if counter > 4320:
                   counter -= 4320
                   for line in f:
                           counter2 += 1
                           if counter2 > counter:

           # write remainder of file to output with XML header

           fo = open ("out.txt","w")
           fo.write("<?xml version=""1.0"" encoding=""UTF-8)"" ?>\r")

           # clean up lines for Javascript

           for line in f:
                   line = line.replace("\0","")
                   line = line.replace("\n","")
                   line = line + "\r"

                   # write tail 4320 readings


           # Ready to upload to web server


                 print("Uploading file to web server")

                 fl = open("Upload.log","a")
                 ln = "\r\nAttempting Upload at :" + tm + " "
                 print("Ping Router")

                 ret = os.system("ping -c 3 -W 1000")
                 if ret != 0:
                     print "Network is down"
                     fl.write("Network down, Reboot")
                     os.system('reboot -n')

                 print("Network is up")

                 fl.write("Network OK")

                 ftp = FTP('pcranwell.com');


                 file = open('out.txt','rb');

                 ftp.storbinary('STOR ' + 'Web.txt', open('out.txt', 'rb'));

                 print("FTP transfer finished")
                 print("Transfer Failed")        

share|improve this answer
You might find this useful : raspberrypi.stackexchange.com/questions/4120/… – goldilocks Mar 20 '13 at 21:09
Is this a question or an answer? – Jivings Mar 21 '13 at 21:43

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.

To clarify matters, I've asked this question.

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.