I have a Python script on my Raspberry Pi 3 Model B (OS NOOBS) that when run, logs the temperature of the CPU into a .csv file every minute.
What I'd like to know is how can I, from a Python script open a terminal and output the temperature in the terminal rather than log it into the .csv file?
This is the code that I've written so far:
from gpiozero import CPUTemperature
from time import sleep, strftime, time
cpu = CPUTemperature()
def output_temp(temp):
with open("cpu_temp.csv", "a") as log:
log.write("{0}, {1}\n".format(strftime("%Y-%m-%d %H:&M:%S"),str(temp)))
while True:
temp = cpu.temperature
output_temp(temp)
sleep(60)
I'm planning on using what I'm asking for so when the temperature goes above 'x' degrees, the terminal will open, print the temperature there until it drops down below the 'x' mark again. However I'll figure that remaining part on my own as I'm a newbie whom is still learning. But I am stuck on the part where I want to open the terminal and print the variable there.
I'm using the software "Python 3 (IDLE)" to write and run this code. When it's completed I'll integrate it so it's automatically run on startup.
Any assistance would be greatly appreciated! Sincerely, Jocke