- Joined
- May 3, 2020
- Messages
- 62
- Reaction score
- 60
My Raspberry Pi is in a case with a lot of peripheral equipment; therefore the temperature rises more than usual, although not critically. From time to time I checked the temperature of the processor via the console using SSH ("vcgencmd measure_temp").
In the long run, this was too annoying for me. So I wrote a Python script that reads the processor temperature and writes it to a text file.
I read this text file with Reef-Pi via a driver 'file-analog', display it on the desktop and control a small fan for cooling. For the script, I adapted another script for reading out sensors.
Here is the script for anyone who is interested:
Suggestions for improvement are welcome.
In the long run, this was too annoying for me. So I wrote a Python script that reads the processor temperature and writes it to a text file.
I read this text file with Reef-Pi via a driver 'file-analog', display it on the desktop and control a small fan for cooling. For the script, I adapted another script for reading out sensors.
Here is the script for anyone who is interested:
Python:
import os
#Create directories and define output files
rootDir = "/dev/shm"
WorkDrir = "/ReeFHardwareComs/temp-proc"
path = rootDir + WorkDrir
access_rights = 0o777
F_TP_name = "temp-proc"
if not os.path.isdir(path):
try:
os.makedirs(path, access_rights)
except OSError:
print ("Creation of the directory %s failed" % path)
else:
print ("Successfully created the directory %s " % path)
# Temperatur des Prozessors auslesen und auf Konsole ausgeben
temp = os.popen("vcgencmd measure_temp").readline()
temp = temp.replace("temp=", "")
temp = temp.replace("'C\n", "")
print(temp)
# Ausgabe in ein File
f = open(path + '/' + F_TP_name, 'w')
f.write(temp)
f.close()
os.chmod(path + '/' + F_TP_name, access_rights)
# File auslesen
f = open(path + '/' + F_TP_name, 'r')
daten = f.read()
print(daten)
f.close()
Suggestions for improvement are welcome.