Python RPi温度监测和超温探测

Python RPi温度监测和超温探测,python,raspberry-pi4,Python,Raspberry Pi4,我对用python编码非常熟悉,我正在努力监视我创建的CSV文件,以监视温度是否大于110华氏度。我最初打算插入一个grep命令来搜索温度阈值以上的任何内容,但我知道python有一些很好的内置工具。我知道如何对文本进行标准搜索,但不知道如何检查grep中的表达式。输出文件如下所示 2020-10-28 00:37:50, 81.0, 87.3, 88.9, 98.8, 2020-10-28 00:42:54, 81.2, 87.5, 88.9, 98.8, 2020-10-28 00:4

我对用python编码非常熟悉,我正在努力监视我创建的CSV文件,以监视温度是否大于110华氏度。我最初打算插入一个grep命令来搜索温度阈值以上的任何内容,但我知道python有一些很好的内置工具。我知道如何对文本进行标准搜索,但不知道如何检查grep中的表达式。输出文件如下所示

2020-10-28 00:37:50, 81.0, 87.3, 88.9, 98.8,

2020-10-28 00:42:54, 81.2, 87.5, 88.9, 98.8, 

2020-10-28 00:47:57, 81.2, 87.3, 88.9, 98.8, 

2020-10-28 00:53:01, 81.3, 87.5, 88.9, 98.9,
 
2020-10-28 00:58:05, 81.5, 87.5, 88.9, 119.5, 
import time
from time import strftime

sensorids = ["28-011927926f5b", "28-0119279b55ce", "28-01192792bf96", "28-0119278c23d7"]


def read_temp_raw():
    f = open(device_file, "r")
    lines = f.readlines()
    f.close()
    return lines

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != "YES":
    time.sleep(0.2)
    lines = read_temp_raw()
    equals_pos = lines[1].find("t=")
    if equals_pos != -1:
    temp_string = lines[1][equals_pos+2:]
    temp_c = float(temp_string) / 1000.0
    temp_f = temp_c * 9.0 / 5.0 + 32.0
    return temp_f
# Unhash if celcius is desired and # temp_f
# return temp_c
    
while True:
    data =""
    result = ""
    for sensor in range(len(sensorids)):
    device_file = "/sys/bus/w1/devices/"+ sensorids[sensor] +"/w1_slave"
    temperature = (read_temp())
    dtemp = "%.1f" % temperature
    result = result + str(dtemp) + ", "

    result = result + "\n"

with open("/home/pi/data.csv", "a") as file:
    file.write("{0}, {1}".format(strftime("%Y-%m-%d %H:%M:%S"),result))
# if sensors write to file too often increase this time
    time.sleep (300)