How to Monitor the CPU Temperature of Raspberry PI using Python

  • 时间:2020-09-09 13:16:32
  • 分类:网络文摘
  • 阅读:77 次

Raspberry PI does not have any fans – although you can either install cooling chips or CPU fans.

raspberry-pi-4b- How to Monitor the CPU Temperature of Raspberry PI using Python Script? python Raspberry PI

CPU Fan for Raspberry PI 4b

It would be great to monitor the temperature in case it gets too hot. The working temperature is less than 80 degree for raspberry PI. With a CPU fan, I managed to keep the CPU fan of the Raspberry PI cool with less than 30 degree.

Here is a python script that allows you to print the temperature of the CPU for raspberry PI:

1
2
3
4
5
6
7
8
9
10
import os
import time
 
def temperature_of_raspberry_pi():
    cpu_temp = os.popen("vcgencmd measure_temp").readline()
    return cpu_temp.replace("temp=", "")
 
while True:
    print(temperature_of_raspberry_pi())
    time.sleep(1)
import os
import time

def temperature_of_raspberry_pi():
    cpu_temp = os.popen("vcgencmd measure_temp").readline()
    return cpu_temp.replace("temp=", "")

while True:
    print(temperature_of_raspberry_pi())
    time.sleep(1)
python3-script-monitor-temperature How to Monitor the CPU Temperature of Raspberry PI using Python Script? python Raspberry PI

python3-script-monitor-temperature

The python script reports the temperature every second. You can run this in background and add some actions if temperature gets too high e.g. sending a email notification.

temperature-on-raspberry-pi How to Monitor the CPU Temperature of Raspberry PI using Python Script? python Raspberry PI

temperature-on-raspberry-pi

1
2
if temperature_of_raspberry_pi > 80:
    print("CPU Temperature too high!")
if temperature_of_raspberry_pi > 80:
    print("CPU Temperature too high!")

Here is a PHP script to measure the temperature on Raspberry PI: Use PHP Script to Monitor Temperature and Uptime for Raspberry PI in the Browser

–EOF (The Ultimate Computing & Technology Blog) —

推荐阅读:
钉扣子作文100字  谏院题名记原文及翻译  虞师晋师灭夏阳原文及翻译  郑伯克段于鄢原文及翻译  吴子使札来聘原文及翻译  宋人及楚人平原文及翻译  诗词名句鉴赏:公无渡河,公竟渡河。堕河而死,当奈公何!  诗词名句鉴赏:枯鱼过河泣,何时悔复及?  诗词名句鉴赏:文籍虽满腹,不如一囊钱。  勾践灭吴原文及翻译 
评论列表
添加评论