查看树莓派温度

一个命令搞定:

cat /sys/class/thermal/thermal_zone0/temp

输出的结果除以1000即为当前环境温度(单位为摄氏度)。
另附一个检测CPU温度,过高自动关机的C++程序:

#include <iostream>
#include <fstream>

using namespace std;

int main(void)
{
	ifstream file("/sys/class/thermal/thermal_zone0/temp", ios::in);
	int temp = 0;
	file >> temp;
	file.close();
	if (temp > 65000)
	{
		system("`date` > /root/shutdown_time.log");
		system("shutdown now");
	}
	else
	{
		cout << temp << endl;
	}
	return 0;
}

原文地址:https://www.cnblogs.com/mrfangd/p/13766927.html