系列文章:
-
GitHub仓库:树莓派系统监控–CPU温度监控和内存使用监控
代码编写
树莓派的CPU温度是存放在一个文件里,使用如下命令查看CPU温度:
cat /sys/class/thermal/thermal_zone0/temp
输出的是五位的整数,除以1000就是CPU的温度了。
python代码如下:
def get_temperature():
try:
cpu_temp_file = open("/sys/class/thermal/thermal_zone0/temp")
cpu_temp = cpu_temp_file.read()
return cpu_temp
except Exception as e:
print(e)
finally:
cpu_temp_file.close()
然后我使用Python自带的sqlite数据库存储数据: