Measuring the processor temperature

Litserv

Community Member
View Badges
Joined
May 3, 2020
Messages
62
Reaction score
60
Rating - 0%
0   0   0
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:

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.
 

Sral

Valuable Member
View Badges
Joined
May 2, 2022
Messages
1,006
Reaction score
978
Location
Germany
Rating - 0%
0   0   0
I think for some users it might be very useful to have a full install:
Basically something takes copies the files and starts the service for the people with less IT-affinity.

You might try adapting the install script that @robsworld78 made for his flowmeter program, I used that as a basis for my air_quality monitor program and service for the SCD30
 
OP
OP
L

Litserv

Community Member
View Badges
Joined
May 3, 2020
Messages
62
Reaction score
60
Rating - 0%
0   0   0
I think for some users it might be very useful to have a full install:
Basically something takes copies the files and starts the service for the people with less IT-affinity.

You might try adapting the install script that @robsworld78 made for his flowmeter program, I used that as a basis for my air_quality monitor program and service for the SCD30

Good idea, thanks for the hint. I'll see whether I can adopt the script or not. For the time being, I wait for a solution of the localization issue in Reef-Pi... ;-)
 

HAVE YOU EVER KEPT A RARE/UNCOMMON FISH, CORAL, OR INVERT? SHOW IT OFF IN THE THREAD!

  • Yes!

    Votes: 32 45.7%
  • Not yet, but I have one that I want to buy in mind!

    Votes: 9 12.9%
  • No.

    Votes: 26 37.1%
  • Other (please explain).

    Votes: 3 4.3%
Back
Top