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.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
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.
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.........
joan wrote:Your script is the most likely cause of the problem.
Code: Select all
*/5 * * * * free -m >> /var/log/memory_logDougieLawson 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 addto track memory usage every five minutes.Code: Select all
*/5 * * * * free -m >> /var/log/memory_log
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 addto track memory usage every five minutes.Code: Select all
*/5 * * * * free -m >> /var/log/memory_log
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 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 \)
Code: Select all
sudo crontab -eCode: Select all
file = /full-path-of/your/data.txt
change = 1000Code: 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)
So now you need more granular logging. Look at the python logging module, write a custom log to /var/log/myprocess.log.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.
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")