Yes, i know. Wanted to use a python script to mail me in case of overheating.
I found this script, but it uses vcgencmd and would be nice if it can be adapted for vero 4k.
Yes, I thought high 75 degrees and critical over 95.
The unit was doing over 95 until I registered it and removed the screensaver.
Now it is idling at 52 degrees.
I just wanted to add an additional layer of security so I don’t start a fire inadvertently.
Unfortunately I am a stranger to python and cannot figure out how to adapt this script for vero.
A helping hand would be appreciated.
Thanks dillthedog! Seems to work, as I tried it with the first part of the script in a command prompt:
# coding=utf-8
import os
import smtplib
from email.mime.text import MIMEText
critical = False
high = 70
too_high = 89
# At First we have to get the current CPU-Temperature with this defined function
def getCPUtemperature():
res = os.popen('cat /sys/class/thermal/thermal_zone0/temp').readline()
return(res.replace("temp=","").replace("'C\n",""))
# Now we convert our value into a float number
temp = float(getCPUtemperature())
print temp/1000
It spits out the temperature.
Now I have to debug the sendmail part as it doesn’t work for some reason.
I have adapted the script and below is the working version if someone would like to use it.
# coding=utf-8
import os
import smtplib
from email.mime.text import MIMEText
critical = False
high = 70
too_high = 89
# At First we have to get the current CPU-Temperature with this defined function
def getCPUtemperature():
res = os.popen('cat /sys/class/thermal/thermal_zone0/temp').readline()
return(res.replace("temp=","").replace("'C\n",""))
# Now we convert our value into a float number
temp = float(getCPUtemperature())/1000
# Check if the temperature is above 70°C
if (temp > high):
if temp > too_high:
critical = True
subject = "Critical warning! The temperature is: {,} shutting down!!".format(temp)
body = "Critical warning! The actual temperature is: {} \n\n Shutting down the pi!".format(temp)
else:
subject = "Warning! The temperature is: {} ".format(temp)
body = "Warning! The actual temperature is: {} ".format(temp)
# Enter your smtp Server-Connection
server = smtplib.SMTP('smtp.gmail.com', 25) # if your using gmail: smtp.gmail.com
server.ehlo()
server.starttls()
server.ehlo
# Login
server.login("yourmail@gmail.com", "yourpass")
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = "Root@whateva.com"
msg['To'] = "receivingmail@gmail.com"
# Finally send the mail
server.sendmail("receivingmail@gmail.com", "receivingmail@gmail.com", msg.as_string())
server.quit()
# Critical, shut down the pi
if critical:
os.popen('sudo halt')
# Don't print anything otherwise.
# Cron will send you an email for any command that returns "any" output (so you would get another email)
# else:
# print "Everything is working fine!"
Now, I have no python knowledge, so I suppose inefficient techniques and useless parts might be present, but the script works, measures temperature and sends mails / stops the unit above the given thresholds.
A cron job to run it each N minutes is a way to use it once in place.