Take the 2-minute tour ×
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.

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:

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?

share|improve this question
1  
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
add comment

3 Answers 3

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
add comment

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
add comment

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)

ser.open()

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")
fo.write(ln);
    fo.close()

    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
           f.close()
           # tail 4320 lines (1440 readings)

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


           # 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
                   fo.write(line)

           f.close()
           fo.close()

           # Ready to upload to web server

           try:

                 print("Uploading file to web server")


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

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

                 print("Network is up")

                 fl.write("Network OK")
                 fl.close()

                 ftp = FTP('pcranwell.com');

                 ftp.login('userid','password');

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

                 ftp.cwd('public_html/PB/data');
                 ftp.storbinary('STOR ' + 'Web.txt', open('out.txt', 'rb'));
                 ftp.close();



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

           finally:
                 print("Continue")
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
add comment

Your Answer

 
discard

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.