How to use Linux command or Python code get Raspberry PI's Temperature All In One

发布时间 2023-05-08 13:39:56作者: xgqfrms

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

image

#!/usr/bin/env python3
# coding: utf8

__author__ = 'xgqfrms'
__editor__ = 'vscode'
__version__ = '1.0.1'
__copyright__ = """
  Copyright (c) 2012-2050, xgqfrms; mailto:xgqfrms@xgqfrms.xyz
"""


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;"> (? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!</div>



## refs

https://www.cnblogs.com/xgqfrms/p/17380248.html#5174870

> 如何获取`树莓派`的`系统信息`

https://www.cnblogs.com/xgqfrms/p/17303351.html


***

<div>
  <a href="https://info.flagcounter.com/QIXi">
    <img src="https://s11.flagcounter.com/count2/QIXi/bg_000000/txt_00FF00/border_FF00FF/columns_3/maxflags_12/viewers_0/labels_1/pageviews_1/flags_0/percent_1/" alt="Flag Counter" border="0">
  </a>
</div>


***

<blockquote style="display: flex; flex-flow: column; align-items: center; justify-content: center; text-align: center; border: none;">
  <h3><strong><span style="font-size: 16pt; color: #00ff00;">©xgqfrms 2012-<span data-uid="copyright-aside">2021</span></strong></span</h3>
  <p><span style="font-size: 18pt; color: #00ff00;"><strong>www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!</strong></span></p>
  <p><span style="font-size: 18pt; color: #00ff00;"><strong>原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!</strong></span></p>
</blockquote>

***