How to use Linux command or Python code get Raspberry PI's Temperature All In One
如何使用 Linux 命令或 Python 代码获取 Raspberry PI 的温度
raspberry pi check the temperature
import gpiozero as gz
# read the temperature into a variable:
cpu_temp = gz.CPUTemperature().temperature
# round the value to one decimal place
# cpu_temp = round(cpu_temp, 1) ❌ bug
print("temp =", cpu_temp)
temp=$(('cat /sys/class/thermal/thermal_zone0/temp'/1000))
echo $temp
https://gpiozero.readthedocs.io/en/stable/api_internal.html?highlight=cpu#cputemperature
vcgencmd
$ vcgencmd measure_temp
temp=47.2'C
$ vcgencmd measure_temp | egrep -o '[0-9]*\.[0-9]*'
47.2
https://linuxhint.com/raspberry_pi_temperature_monitor/
$ watch -- 'vcgencmd measure_temp'
$ watch -c -b -d -n 1 -- 'vcgencmd measure_temp'
$ vcgencmd measure_temp | grep -o -E '[[:digit:]].*'
$ vcgencmd measure_temp | egrep -o '[[:digit:]].*'
cpu=$(</sys/class/thermal/thermal_zone0/temp)
echo "$((cpu/1000)) c"
https://www.cyberciti.biz/faq/linux-find-out-raspberry-pi-gpu-and-arm-cpu-temperature-command/
$ hostname -I | cut -d\' \' -f1 | head --bytes -1
import subprocess
# Shell scripts for system monitoring from here : https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
cmd = "hostname -I | cut -d\' \' -f1 | head --bytes -1"
IP = subprocess.check_output(cmd, shell = True )
cmd = "top -bn1 | grep load | awk '{printf \"CPU %.2f\", $(NF-2)}'"
CPU = subprocess.check_output(cmd, shell = True )
cmd = "free -m | awk 'NR==2{printf \"%.2f%%\", $3*100/$2 }'"
MemUsage = subprocess.check_output(cmd, shell = True )
cmd = "df -h | awk '$NF==\"/\"{printf \"HDD: %d/%dGB %s\", $3,$2,$5}'"
cmd = "df -h | awk '$NF==\"/\"{printf \"%s\", $5}'"
Disk = subprocess.check_output(cmd, shell = True )
cmd = "vcgencmd measure_temp | cut -d '=' -f 2 | head --bytes -1"
Temperature = subprocess.check_output(cmd, shell = True )
https://www.youtube.com/watch?v=94ZjxjmhBrY
https://github.com/jumejume1/raspberry-oled-monitor/blob/master/monitor.py
???
https://forums.raspberrypi.com/viewtopic.php?t=34994
# $ cd /proc && ls -alth
$ ls -alth /proc
$ cat /proc/cpuinfo
$ cat /proc/stat
$ cat /proc/devices
$ cat /proc/cmdline
demos
Temperature
#!/usr/bin/env python3
# coding: utf8
__author__ = 'xgqfrms'
__editor__ = 'vscode'
__version__ = '1.0.1'
__copyright__ = """
Copyright (c) 2012-2050, xgqfrms; mailto:[email protected]
"""
import gpiozero as gz
# read the temperature into a variable:
cpu_temp = gz.CPUTemperature().temperature
# round the value to one decimal place
# cpu_temp = round(cpu_temp, 1)
# round ❌
print("temp =", cpu_temp)
$ py3 ./temp.py
temp = 48.312
``
<!--
<details>
<summary>
</summary>
</details>
-->
## <div id="anti-crawler" style="color: red;"> (
标签:use,code,Temperature,temp,cmd,https,xgqfrms,com,cpu
From: https://www.cnblogs.com/xgqfrms/p/17381482.html