首页 > 系统相关 >How to use Linux command or Python code get Raspberry PI's Temperature All In One

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

时间:2023-05-08 13:44:31浏览次数:52  
标签:use code Temperature temp cmd https xgqfrms com cpu

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:[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

相关文章

  • Exploring the Use of Humanized Mouse Models in Drug Safety Evaluation
    Thepurposeofdrugdevelopmentistofindnewsafe,effectivedrugsofhighqualityandstabilitytocurediseasesandsavelives.Developinganewdrugisaverycomplexprocess,butitcanbedividedinto preclinicalresearch andclinicalstudiesofa......
  • VsCode设置插件安装目录
    VsCode设置插件安装目录如果是还没有安装插件,希望把新的插件安装到新目录,可以使用【命令行/快捷方式/资源管理器右键】的方式来打开vscode如果之前已经安装过插件,可以把C:\Users\xxxx\.vscode下的extensions目录拷贝到插件需要安装的路径下,再进行下面的操作命令行方式可以......
  • Codeforces Round 871 (Div. 4)
    A.LoveStory题意:给定n个长度为10的字符串,问其与codeforces字符串的对应下标字母不同的个数。分析:对于每个字符串从前往后依次和“codeforces”对应字符比较然后统计不同字母数即可code:#include<bits/stdc++.h>usingnamespacestd;intmain(){ std::ios::sync_wit......
  • leetcode 101 对称二叉树 Simple
    题目给你一个二叉树的根节点root,检查它是否轴对称。输入:root=[1,2,2,3,4,4,3]输出:true输入:root=[1,2,2,null,3,null,3]输出:false题解考察二叉树的遍历,使用广度优先BFS方法.BFS的关键在于使用队列,遍历树时,读到的节点先入队,再出队,出队时读取值,放入结......
  • LeetCode 473 火柴拼正方形
    LeetCode|473.火柴拼正方形你将得到一个整数数组matchsticks,其中matchsticks[i]是第i 个火柴棒的长度。你要用所有的火柴棍 拼成一个正方形。你不能折断任何一根火柴棒,但你可以把它们连在一起,而且每根火柴棒必须使用一次。如果你能使这个正方形,则返回true,否则返......
  • Install git from source code
    InstallGitfromSourceCodePrerequisiteCentOSyuminstallzlib-develyuminstallasciidocyuminstallxmltoDebianapt-getinstallzlib1g-devapt-getinstallasciidocapt-getinstallxmltoInstallYoucangetitviathekernel.orgsite,athttps://ww......
  • 数据仓库(Data Warehouse)
    数据仓库(DataWarehouse)和数据集市(DataMart)产品。包括数据转换、管理和存取等方面的预配置软件,通常还包括一些业务模型,如财务分析模型。......
  • java.io.FileNotFoundException: class path resource [bean.xml] cannot be opened b
    出现这个报错Exceptioninthread"main"org.springframework.beans.factory.BeanDefinitionStoreException:IOExceptionparsingXMLdocumentfromclasspathresource[bean.xml];nestedexceptionisjava.io.FileNotFoundException:classpathresource[bean.......
  • VSCode常用插件记录
    1.[Deprecated]BracketPairColorizer2 2.C/C++3.C/C++ClangCommandAdapter4.C/C++ExtensionPack5.C/C++Themes6.GitBlame7.GitGraph8.GitHistory9.GitLens—Gitsupercharged10.IntelliCode11.PartialDiff12.snippets13.LocalHistory14.change-c......
  • JavaScript fromCharCode() 方法
    fromCharCode()方法返回指定的Unicode编码对应的字符。语法格式:String.fromCharCode(n1,n2,...)参数:n1,n1,..表示指定的Unicode编码。示例:(1)返回指定Unicode编码的字符:<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8">&......