Danas
Posts: 12
Joined: Wed Mar 19, 2014 8:10 pm

RPi freezes in about a week. Please HELP

Mon Apr 06, 2015 4:43 pm

Hi All,

PROJECT:

I have Raspberry Pi B+ with the latest OS
I use it to control the temperature of my rooms
I have 9 1-wire temperature sensors connected
I am controlling 13 thermo valves of my heating contour with 8 channel relays
I have 3G dongle connected to my RPi
I have Apache server running

OPERATION:

Mainly I wrote a Python script to log the temperature from my room every 3 minutes. I archive the data and sent it to my email every day. If my heating is on I can set up a variable in Python script to close the contour of the specific room if the temperature rises to higher value than stated. I can connect to my Apache server. PHP script reads the last line of each temperature file so I can see the temperature of my rooms on my web browser.

PROBLEM:

My Raspberry freezes in approximately a week after last reset. It could be anything between 2 and 10 days, completely unpredictable. It doesn't even react to direct connections so the only option is to restart it. I tried to check the script but it is straight forward. I tried to leave my laptop to supply power for my Pi to avoid voltage jumps, but it didn't help.

Could you please advise me how to monitor and find the problem what causes RPi freeze?

Thank you in advance.

Danas

lingon
Posts: 128
Joined: Fri Aug 26, 2011 7:31 am

Re: RPi freezes in about a week. Please HELP

Mon Apr 06, 2015 6:30 pm

Do you have your Raspberry Pi in a case? Does the case have adequate perforations on the top to allow sufficient air to flow? The USB-Eternet chip has a lower temperature limit than the CPU, and it actually runs hotter then the CPU. I have seen lockups on my idling Raspis (overclocked) on a timescale of a week or two. If the case is the problem try first to remove the case lid to see if this improves stability. If that helps then you can drill more holes in the lid of your case.

MrEngman
Posts: 3946
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: RPi freezes in about a week. Please HELP

Mon Apr 06, 2015 6:37 pm

Danas wrote:PROBLEM:

My Raspberry freezes in approximately a week after last reset. It could be anything between 2 and 10 days, completely unpredictable. It doesn't even react to direct connections so the only option is to restart it. I tried to check the script but it is straight forward. I tried to leave my laptop to supply power for my Pi to avoid voltage jumps, but it didn't help.

Could you please advise me how to monitor and find the problem what causes RPi freeze?

Thank you in advance.

Danas
Try looking at the log files for any reports of problems. e.g. Does command dmesg show any problem. Various other log files are stored in directory /var/log directory.


MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

Danas
Posts: 12
Joined: Wed Mar 19, 2014 8:10 pm

Re: RPi freezes in about a week. Please HELP

Mon Apr 06, 2015 10:14 pm

Hi lingon,

Thank you for your reply. My RPi is without the case at the moment. The temperature in the room it sits in is around +17 C. Maybe USB dongle increases the temperature of USB-Ethernet chip, I don't know. I will try to investigate this.
lingon wrote:Do you have your Raspberry Pi in a case? Does the case have adequate perforations on the top to allow sufficient air to flow? The USB-Eternet chip has a lower temperature limit than the CPU, and it actually runs hotter then the CPU. I have seen lockups on my idling Raspis (overclocked) on a timescale of a week or two. If the case is the problem try first to remove the case lid to see if this improves stability. If that helps then you can drill more holes in the lid of your case.

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: RPi freezes in about a week. Please HELP

Mon Apr 06, 2015 10:14 pm

Is the pi actually 'freezing' or the network connection is dying ?

Not being able to connect to the Pi from a network connection is no indication that the Pi has given up the ghost. I'd write a shell script that writes to a file periodically from crontab or something, so the next time you get back into it, you can see if the Pi was still running when it stopped responding to web requests. Anything wireless, I'd suspect the wireless before the Pi.........
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

Danas
Posts: 12
Joined: Wed Mar 19, 2014 8:10 pm

Re: RPi freezes in about a week. Please HELP

Tue Apr 07, 2015 12:34 pm

I would say that RPi freezes vs network connection going down. My RPi controls my heating contours. Once the connection is down, whole RPi is down as my relays doesn't work anymore. I use 2 relay modules to switch between my 4 1-wire networks. That is happening every 3 minutes. When RPi freezes relays are not working anymore. The interesting thing is that all GPIO remains at the same state as before freezing. The ones were on stays on, the ones were off stays off...
pluggy wrote:Is the pi actually 'freezing' or the network connection is dying ?

Not being able to connect to the Pi from a network connection is no indication that the Pi has given up the ghost. I'd write a shell script that writes to a file periodically from crontab or something, so the next time you get back into it, you can see if the Pi was still running when it stopped responding to web requests. Anything wireless, I'd suspect the wireless before the Pi.........

User avatar
joan
Posts: 14668
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: RPi freezes in about a week. Please HELP

Tue Apr 07, 2015 1:22 pm

Your script is the most likely cause of the problem.

Danas
Posts: 12
Joined: Wed Mar 19, 2014 8:10 pm

Re: RPi freezes in about a week. Please HELP

Tue Apr 07, 2015 3:42 pm

Do you have any specific reason to state that?
Mainly it is straight forward read of 1-wire sensor, then store the data in text file.
If it would be my script how would it work without a problem for 10 days?
joan wrote:Your script is the most likely cause of the problem.

Danas
Posts: 12
Joined: Wed Mar 19, 2014 8:10 pm

Re: RPi freezes in about a week. Please HELP

Sun Apr 12, 2015 10:52 am

Thank you all but no one gave me any hint.

Good luck.

Danas

User avatar
DougieLawson
Posts: 37083
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: RPi freezes in about a week. Please HELP

Sun Apr 12, 2015 11:07 am

If it freezes start with the possible hardware causes. Change the power supply, change the microUSB cable.

If it still freezes look at /var/log at the /v*/l*/dmesg.1 file (when you've rebooted), at /v*/l*/syslog and at /v*/l*/messages

Add logging to your application, or simple print commands and run it with /home/pi/script 1> /var/log/script.log 2> /var/log/script.err or use the logging function so you can write messages to /v*/l*/syslog or /v*/l*/messages.

Track memory usage, is something leaking memory (does it steadily grow until it fails). Use sudo crontab -e and add

Code: Select all

*/5 *  *  *  *  free -m >> /var/log/memory_log
to track memory usage every five minutes.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Danas
Posts: 12
Joined: Wed Mar 19, 2014 8:10 pm

Re: RPi freezes in about a week. Please HELP

Sun Apr 12, 2015 6:20 pm

Thank you DougieLawson.

Yes, I have changed the micro USB cable and power supply before to find the problem but I got the same issue again.
I have 75% available space on my SD card and my script uses about 0.5% of processor according to top command.
DougieLawson wrote:If it freezes start with the possible hardware causes. Change the power supply, change the microUSB cable.

I will try all other hints you suggested.

Danas

If it still freezes look at /var/log at the /v*/l*/dmesg.1 file (when you've rebooted), at /v*/l*/syslog and at /v*/l*/messages

Add logging to your application, or simple print commands and run it with /home/pi/script 1> /var/log/script.log 2> /var/log/script.err or use the logging function so you can write messages to /v*/l*/syslog or /v*/l*/messages.

Track memory usage, is something leaking memory (does it steadily grow until it fails). Use sudo crontab -e and add

Code: Select all

*/5 *  *  *  *  free -m >> /var/log/memory_log
to track memory usage every five minutes.

aoakley
Posts: 66
Joined: Fri May 11, 2012 10:27 pm
Contact: Website

Re: RPi freezes in about a week. Please HELP

Mon Apr 13, 2015 12:35 pm

I am tracking a similar problem here, only on a Pi 2:

viewtopic.php?f=28&t=104212&p=736842#p736842

There are logs and screenshots on that thread.
Andrew Oakley - Cotswold Raspberry Jam, Gloucestershire - http://www.cotswoldjam.org

Danas
Posts: 12
Joined: Wed Mar 19, 2014 8:10 pm

Re: RPi freezes in about a week. Please HELP

Sat Apr 18, 2015 5:24 am

It happened again! I clearly see that it happened on 16th April at 04:17.
Here is a link to syslog.1, messages, dmesg.0 and dmseg files:
https://www.dropbox.com/sh/brayfygruwoy ... zKtYa?dl=0

I can see that it stopped working at 04:17 April 16th but I can't understand what caused that. Could you please check the syslog.1 and messages file and help me??
DougieLawson wrote:If it freezes start with the possible hardware causes. Change the power supply, change the microUSB cable.

If it still freezes look at /var/log at the /v*/l*/dmesg.1 file (when you've rebooted), at /v*/l*/syslog and at /v*/l*/messages

Add logging to your application, or simple print commands and run it with /home/pi/script 1> /var/log/script.log 2> /var/log/script.err or use the logging function so you can write messages to /v*/l*/syslog or /v*/l*/messages.

Track memory usage, is something leaking memory (does it steadily grow until it fails). Use sudo crontab -e and add

Code: Select all

*/5 *  *  *  *  free -m >> /var/log/memory_log
to track memory usage every five minutes.

User avatar
DougieLawson
Posts: 37083
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: RPi freezes in about a week. Please HELP

Sat Apr 18, 2015 8:45 am

There's nothing earth shattering in your logs, just lots of regular kernel messages from a few reboots.
What do you have in crontabs?

Take a look at
/var/spool/cron/crontabs
/etc/crontab
/etc/cron.d
/etc/cron.hourly
/etc/cron.weekly
/etc/cron.daily
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Danas
Posts: 12
Joined: Wed Mar 19, 2014 8:10 pm

Re: RPi freezes in about a week. Please HELP

Sat Apr 18, 2015 9:44 am

Thank you for the such a rapid reply.

I have only 2 lines in crontab:

@reboot sudo python /home/readT/readT0.py &
0 7 * * * sudo /home/readT/upload.sh >/dev/null 2>/dev/null

The first is to start my scrip at startup
And the second is archive my *.txt temperature logs and to send them to my email

/etc/crontab:
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

/etc/cron.d/php5:
# Look for and purge old sessions every 30 minutes
09,39 * * * * root [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime)

/etc/cron.hourly/fake-hwclock:
#!/bin/sh
#
# Simple cron script - save the current clock periodically in case of
# a power failure or other crash

if (command -v fake-hwclock >/dev/null 2>&1) ; then
fake-hwclock save
fi
(no idea what is this)

/etc/cron.weekly/man-db:
#!/bin/sh
#
# man-db cron weekly

set -e

iosched_idle=
# Don't try to change I/O priority in a vserver or OpenVZ.
if ! egrep -q '(envID|VxID):.*[1-9]' /proc/self/status && \
([ ! -d /proc/vz ] || [ -d /proc/bc ]); then
dpkg_version="$(dpkg-query -W -f '${Version}' dpkg 2>/dev/null)"
if dpkg --compare-versions "$dpkg_version" ge 1.15.0; then
iosched_idle='--iosched idle'
fi
fi

if ! [ -d /var/cache/man ]; then
# Recover from deletion, per FHS.
mkdir -p /var/cache/man
chown man:root /var/cache/man || true
chmod 2755 /var/cache/man
fi

# regenerate man database
if [ -x /usr/bin/mandb ]; then
# --pidfile /dev/null so it always starts; mandb isn't really a daemon,
# but we want to start it like one.
start-stop-daemon --start --pidfile /dev/null \
--startas /usr/bin/mandb --oknodo --chuid man \
$iosched_idle \
-- --quiet
fi

exit 0

I have never explored this part of CRONTAB, do you see anything suspicious?

Thanks
DougieLawson wrote:There's nothing earth shattering in your logs, just lots of regular kernel messages from a few reboots.
What do you have in crontabs?

Take a look at
/var/spool/cron/crontabs
/etc/crontab
/etc/cron.d
/etc/cron.hourly
/etc/cron.weekly
/etc/cron.daily

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: RPi freezes in about a week. Please HELP

Sat Apr 18, 2015 9:52 am

The 04:17 may be misleading, it may be simply be the last message logged and something later on may have caused the crash. That doesn't help much, I know \)

Danas
Posts: 12
Joined: Wed Mar 19, 2014 8:10 pm

Re: RPi freezes in about a week. Please HELP

Sat Apr 18, 2015 12:17 pm

My temperature sensors are logging the data to txt files every 3 minutes. The last record was around 04:17 as well...

This issue annoys me so much... If it wouldn't work at all you would try to find something and now it just stops randomly... I don't know what else to do...
fruit-uk wrote:The 04:17 may be misleading, it may be simply be the last message logged and something later on may have caused the crash. That doesn't help much, I know \)

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: RPi freezes in about a week. Please HELP

Sat Apr 18, 2015 1:46 pm

I can understand it being annoying. One of mine had a similar habit but righted itself, no idea what changed though.

Have you considered enabling watchdog? If you are writing to a file use that as a monitor and if no write within a certain time reboot.

User avatar
DougieLawson
Posts: 37083
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: RPi freezes in about a week. Please HELP

Sat Apr 18, 2015 3:01 pm

I think you need to monitor the system for a memory leak. If something leaks memory then it will eventually crash the system.

Running a watchdog may help discover what's causing it.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Danas
Posts: 12
Joined: Wed Mar 19, 2014 8:10 pm

Re: RPi freezes in about a week. Please HELP

Sun Apr 19, 2015 6:27 am

First of all thanks again for quick response!

@DougieLawson:
I set up a crontab to log my memory as you recomended --> */5 * * * * free -m >> /var/log/memory_log
Now every 5 minutes I receive this:
Delivery to the following recipient failed permanently:

[email protected]@gmail.com
...
...
...

I am sure it's related with my mail settings in RPi or name of the device. Could you please recommend me how to fix this one?
The other thing is that it doesn't log anything into memory_log file. I think this is related with the first issue...

@fruit-uk: Your idea to monitor writing into the file and reboot once failed sounds good. I have never used watchdog. Could you share any links or samples how to set it up?

The other thing is that once I was desperate I added a line in crontab to reboot my RPi every day. I assumed that it won't crash then. But it did... again... So it doesn't explain why it crashes after more than a week...

Once I sort the memory log out maybe I will find the problem or at least move forward to find what causes it.

Thank you both!!

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: RPi freezes in about a week. Please HELP

Sun Apr 19, 2015 7:28 am

Did you edit crontab using

Code: Select all

sudo crontab -e
You have two @ chars in that mail address so something is wrong somewhere.

There are many tutorials on setting up watchdog but this one http://harizanov.com/2013/08/putting-ra ... g-to-work/ shows the basic idea.
You then need to edit /etc/watchdog.conf
Don't enable the network bits (comment out if not already). Add an entry

Code: Select all

file = /full-path-of/your/data.txt
change  = 1000
The 1000 will trigger if file has not changed in 1000 seconds - adjust to suit.
You can monitor more than one file but remeber the file/change works in pairs.

If you need more examples search the net for raspberrypi watchdog

Danas
Posts: 12
Joined: Wed Mar 19, 2014 8:10 pm

Re: RPi freezes in about a week. Please HELP

Fri May 15, 2015 6:39 am

Hi All,

Latest update:

I tried to change the power supply.

Then I bought a new quality micro SD card and installed fresh latest OS.

Then I was suspecting the power supply of my system as RPi supplies 2 x 8 channel relays blocks as well as 10 temperature sensors and 3G dongle.
I bought a powered USB hub and connected everything to it but RPi itself. RPi had it's own 2A 5 V supply. And guess what... it froze again and again. It still works brilliantly for at least 3-4 days.

As recommended by Dougie Lawson I was logging memory for some time. It never dropped below 289M before it crashed so I don't think this causes the problem.

It still could be my script as commented by joan. However, can whole RPi freeze if it has a problem with python script? I would think that the script would stop but I would still be able to connect to RPi on SSH or at least directly with the cable. When RPi freezes it still feeds 8 channel relays but 3G dongle shows no life (normally green LED light is on when dongle is on or on and blinking when connected to network).

Last 2 ideas I have:

1) My script after working for a random period without any problem suddenly kills RPi. To check that I am logging every single action in my script now to see where it stops. RPi is still running for 3 days now so I don't have a result yet.

2) 3G dongle freeze the RPi. I will try to remove 3G dongle and just leave the script running without internet connection (I can't use WiFi now as my RPi sits in my new flat which is still not finished and I don't have an internet there at the moment)

I am adding my script to this post. If you have a will maybe you could have a look at it and comment if it could really cause RPi freeze?
Any other ideas?

Thank you!!

Code: Select all

#!/usr/bin/python
import os
import sys
import time
import datetime
import RPi.GPIO as GPIO

def readValue (name):
	fullPath = "/home/readT/Values/" + name + ".txt"
	if os.path.exists(fullPath):
		file = open(fullPath)
		value = file.read()
		file.close()
		number = float(value)
	else:
		number = "No Value"
	return number;

tManto = readValue("Manto") #t for temperature
tIgno = readValue("Igno")
tDarbo = readValue("Darbo")
tVaikuWC = readValue("VaikuWC")
tMiegamasis = readValue("Miegamasis")
tVonia = readValue("Vonia")
tValgomasis = readValue("Valgomasis")
tSvetaine = readValue("Svetaine")
tTulikas = readValue("Tulikas")
sHeating = readValue("Heating") #s for status

print "Manto      " + str(tManto)
print "Igno       " + str(tIgno)
print "Darbo      " + str(tDarbo)
print "Vaiku WC   " + str(tVaikuWC)
print "Miegamasis " + str(tMiegamasis)
print "Vonia      " + str(tVonia)
print "Valgomasis " + str(tValgomasis)
print "Svetaine   " + str(tSvetaine)
print "Tulikas    " + str(tTulikas)
print "Heating    " + str(sHeating) + "\n"

gap = 0.1
freq = 300

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

R1 = 26 #Apacios davikliu
R2 = 19 #Apacios davikliu
R3 = 16 #Virsaus davikliu

R9 = 12 #Manto
R6 = 21 #Igno
R4 = 8  #Vaiku WC
R5 = 20 #Darbo kambarys
R10 = 7 #Virsaus gyvatukas
R7 = 25 #1 atsarginis virsus
R8 = 24 #2 atsarginis virsus

R11 = 13 #Vonia
R12 = 6  #Spinta/Boilerine/Koridorius
R13 = 5  #Miegamasis
R14 = 11 #Valgomasis
R15 = 9  #Svetaine
R16 = 10 #Tulikas

GPIO.setup(R1, GPIO.OUT)
GPIO.setup(R2, GPIO.OUT)
GPIO.setup(R3, GPIO.OUT)
GPIO.setup(R4, GPIO.OUT)
GPIO.setup(R5, GPIO.OUT)
GPIO.setup(R6, GPIO.OUT)
GPIO.setup(R7, GPIO.OUT)
GPIO.setup(R8, GPIO.OUT)
GPIO.setup(R9, GPIO.OUT)
GPIO.setup(R10, GPIO.OUT)
GPIO.setup(R11, GPIO.OUT)
GPIO.setup(R12, GPIO.OUT)
GPIO.setup(R13, GPIO.OUT)
GPIO.setup(R14, GPIO.OUT)
GPIO.setup(R15, GPIO.OUT)
GPIO.setup(R16, GPIO.OUT)

off = GPIO.HIGH
on = GPIO.LOW

GPIO.output(R1, off)
GPIO.output(R2, off)
GPIO.output(R3, off)

def relayDefault (sHeating):
	if sHeating == 0:
		GPIO.output(R4, on) #Vaiku WC
		GPIO.output(R5, on) #Darbo
		GPIO.output(R6, on) #Igno
		GPIO.output(R7, on) #1
		GPIO.output(R8, on) #2
		GPIO.output(R9, on) #Manto
		GPIO.output(R10, on) #Virsaus gyvatukas
		GPIO.output(R11, on) #Vonia
		GPIO.output(R12, on) #Spinta/Boilerine/Koridorius
		GPIO.output(R13, on) #Miegamasis
		GPIO.output(R14, on) #Valgomasis
		GPIO.output(R15, on) #Svetaine
		GPIO.output(R16, on) #Tulikas
	else:
                GPIO.output(R4, off) #Vaiku WC
                GPIO.output(R5, off) #Darbo
                GPIO.output(R6, off) #Igno
                GPIO.output(R7, off) #1
                GPIO.output(R8, off) #2
                GPIO.output(R9, off) #Manto
                GPIO.output(R10, off) #Virsaus gyvatukas
                GPIO.output(R11, off) #Vonia
                GPIO.output(R12, off) #Spinta/Boilerine/Koridorius
                GPIO.output(R13, off) #Miegamasis
                GPIO.output(R14, off) #Valgomasis
                GPIO.output(R15, off) #Svetaine
                GPIO.output(R16, off) #Tulikas

	return;

rf = 15

sensor=[]
#R1=off R2=off R3=off
sensor.append("28-0000063de9fc") #Manto
sensor.append("28-0000063f4179") #Darbo kambarys
#R1=off R2=off R3=on
sensor.append("28-0000063eb104") #Igno kambarys
sensor.append("28-0000063fe4e2") #Virsaus WC
#R1=off R2=on R3=off
sensor.append("28-0000063ea61e") #Miegamasis
sensor.append("28-0000063ef64d") #Vonia
sensor.append("28-0000063fb68a") #Saliono WC
#R1=on R2=off R3=off
sensor.append("28-00000527aa2b") #Valgomasis
sensor.append("28-0000063ef558") #Koridorius
sensor.append("28-00042d7fe1ff") #Laukas
sensorsAll=len(sensor)

path = "/home/readT/Sensors/Sensor"
path1 = "/home/readT/Sensors/Sildymas"
ext = ".txt"

def wfile (value1, pth, tm, name1):
	if os.path.exists(pth + name1 + ext):
        	f = open((pth + name1 + ext), 'r+')
        	f.seek(-1, 2)
        	if f.read(1) == '\n\n':
                	f.seek(-2, 1)	
	else:
        	f = open((pth + name1 + ext), 'w')
        f.write(str(tm) + ' @ ' + value1 + '\n')
	f.close()
	return;

def action (status, temperature, TEMP, gap, R, name, tm):
        if status == 1:
		if temperature > (TEMP + gap):
                	GPIO.output(R, on)
	                print "   +++"
        	        wfile("0", path1, tm, name)
        	else:
			if temperature < (TEMP - gap):
                		GPIO.output(R, off)
                		print "   ---"
                		wfile("1", path1, tm, name)
			else:
				print "   OK"
	else:
		relayDefault(sHeating)
        return;

#sHeating = readValue("Heating")
relayDefault(sHeating)
time.sleep(rf)

while True:
	tManto = readValue("Manto")
	tIgno = readValue("Igno")
	tDarbo = readValue("Darbo")
	tVaikuWC = readValue("VaikuWC")
	tMiegamasis = readValue("Miegamasis")
	tVonia = readValue("Vonia")
	tValgomasis = readValue("Valgomasis")
	tSvetaine = readValue("Svetaine")
	tTulikas = readValue("Tulikas")
	sHeating = readValue("Heating")

	for i in range(0,sensorsAll):
		try:
			if os.path.exists("/sys/bus/w1/devices/" + sensor[i] + "/w1_slave"):
				tfile = open("/sys/bus/w1/devices/" + sensor[i] + "/w1_slave")
				text = tfile.read()
				tfile.close()
				check = text.split(" ")[11]
                		crccheck = check.split("\n")[0]
	                	if crccheck == "YES":
					secondline = text.split("\n")[1]
					temperaturedata = secondline.split(" ")[9]
					temperature = float(temperaturedata[2:])
					temperature = temperature/1000
		        		tm = datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S")
					if i == 0:
						print "Manto kambarys  %2.1f" %(temperature)
						action (sHeating, temperature, tManto, gap, R9,"Manto", tm)		
					if i == 1:
	                                        print "Darbo kambarys  %2.1f" %(temperature)
						action (sHeating, temperature, tDarbo, gap, R5,"Darbo", tm)
                	                if i == 2:
                        	                print "Igno kambarys   %2.1f" %(temperature)
                                	        action (sHeating, temperature, tIgno, gap, R6,"Igno", tm)
	                                if i == 3:
        	                                print "Vaiku WC        %2.1f" %(temperature)
						action (sHeating, temperature, tVaikuWC, gap, R4,"VaikuWC", tm)
                        	        if i == 4:
                                	        print "Miegamasis      %2.1f" %(temperature)
						action (sHeating, temperature, tMiegamasis, gap, R13,"Miegamasis", tm)
	                                if i == 5:
        	                                print "Vonia           %2.1f" %(temperature)
						action (sHeating, temperature, tVonia, gap, R11,"Vonia", tm)
                        	        if i == 6:
                                	        print "Tulikas         %2.1f" %(temperature)
						action (sHeating, temperature, tTulikas, gap, R16,"Tulikas", tm)
        	                        if i == 7:
                	                        print "Valgomasis      %2.1f" %(temperature)
						action (sHeating, temperature, tValgomasis, gap, R14,"Valgomasis", tm)
                                	if i == 8:
                                        	print "Svetaine        %2.1f" %(temperature)
						action (sHeating, temperature, tSvetaine, gap, R15,"Svetaine", tm)
	                                if i == 9:
                	                        print "Laukas          %2.1f" %(temperature)
					wfile (str(temperature), path, tm, str(i+1))
				else:
					print "Sensor%d = CRC Error" %(i+1)	
			else:
				print "Sensor%d = no read" %(i+1)
			if i == 1:
				GPIO.output(R3, on)
	                        time.sleep(rf)
			if i == 3:
				GPIO.output(R2, on)
                        	GPIO.output(R3, off)
	                        time.sleep(rf)
			if i == 6:
                	        GPIO.output(R1, on)
                        	GPIO.output(R2, off)
	                        time.sleep(rf)
			if i == 9:
                	        GPIO.output(R1, off)
                        	print "\n"
	 			time.sleep(rf)
		except:
			print "Error"
	time.sleep(freq)

User avatar
DougieLawson
Posts: 37083
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: RPi freezes in about a week. Please HELP

Fri May 15, 2015 10:53 am

Danas wrote: As recommended by Dougie Lawson I was logging memory for some time. It never dropped below 289M before it crashed so I don't think this causes the problem.
So now you need more granular logging. Look at the python logging module, write a custom log to /var/log/myprocess.log.

Code: Select all

import logging
logging.basicConfig("/var/log/myprocess.log",level=logging.DEBUG)

[... snip ... lots of stuff removed for clarity ...]

      logging.debug('Something interesting, worth logging happened: details of it here")
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

agox
Posts: 1
Joined: Fri May 15, 2015 1:56 pm

Re: RPi freezes in about a week. Please HELP

Fri May 15, 2015 2:20 pm

I have the same situation.

I have my RPi 2 configured with Owncloud. Nothing else, just an installation of raspian (without the software that I do not use like, Wolfram, script...) and Owncloud 8.0.3

I have a python script that checks the external IP every 10 minutes (via crontab) and send me an email if it changes.

I think I can discard the following:
Micro Sd card: Kingston class 10 (previously used on a Rpi B+ with no problem)
Power unit: From an old samsung (1 Amp). I used the charger from a Nexus 7 (1.5 Amp) and still the same issue.
WiFi connection: I do not think the problem is that I am not able to connect to the pi via Putty because the python script will restart the network or the pi, if it is not able to ping a list of web sites that I have configured.
Updating the system does not help.

It is not something that happened from the beginning. When I bought it it was working fine, then these crashes were happening randomly. Every 7-10 days to few hours. I can use it under heavy data transfer via WiFi perfectly.

The problem is driving me crazy because if the server is down I cannot synchronize my files, photos, contacts, calendar...

Do you have any idea??

Thanks in advance

vita_brevis
Posts: 1
Joined: Sun Jun 14, 2015 1:22 pm

Re: RPi freezes in about a week. Please HELP

Sun Jun 14, 2015 3:13 pm

I think the problem may lie with the cron job
09,39 * * * * root [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime)

Certainly this has been an ongoing issue with my pi server which was exhibiting very similar symptoms.

The problem is that the distributors of Debian (and hence Raspbian) in their mighty wisdom decided to change the default behaviour of php because of perceived security flaws. It's to do with the possiblity of one user being able to hijack another user's session, but suffice it to say that other distro's don't feel the necessity, and if you're running a private webserver there is no necessity at all.

The default behaviour of php is to delete out-of-date session files using php's garbage collector, but in Ubuntu, Debian and Raspbian it's done with this cron script (running as root) so that strict controls can be put on the accessibility of the /var/lib/php directory that the garbage collector needs access to. Unfortunately on the pi this script takes forever to run. By default the script is set to run every half hour and on the pi with its slow SD card r/w access you eventually end up with all the CPU time being taken up with running the lsof commands that the sessionclean part of the cron job sets off.

Unless you're running a public-facing webserver accessed by thousands of users per hour (and if you're doing that on a pi good luck with that :) ), there is no necessity to run the script so often; once a week would probably be enough. But I tried running the script once a day and 20 hours later it was still running and consuming 76% of CPU time (checked using 'top' and 'ps aux' commands). Of course YMMV, and it's still a vast improvement on the default. So I suggest setting it to run once a week as the "no muss no fuss" solution.

What I decided to do, as my webserver has no malicious users who might try to hijack another user's session, and not wanting my CPU to spend at least a whole day every week occupied with a nonsense, was to revert to the default php behaviour and use the garbage collector. So to do that, on the command line with root permissions, I typed:

crontab -e
then comment out the relevant line
nano /etc/php5/apache2/php.ini
in the [session] section you should change session.gc_probability = 0 to session.gc_probability = 1
chown :www-data /var/lib/php5
chmod g+r /var/lib/php5

The slight downside is that if php gets updated I'll probably have to re-edit the php.ini file. I think there's a local version I should have used instead. Anyone know where it is?

Cheers all.

Return to “Troubleshooting”