嵌入式系统|编程实现实时采集嵌入式开发板温度

【嵌入式系统|编程实现实时采集嵌入式开发板温度】在开发板测试的过程中,我们会经常采集他的实时温度用于监视开发板的实际状态。下面是代码实现

#include #include #include int main(int arc, char *argv[]) { FILE *fp = NULL; unsigned int temperature = 0; fp = fopen ("/sys/devices/virtual/thermal/thermal_zone0/temp", "r"); if (fp < 0) { printf("fopen error!\n"); exit(1); } while(1) { fscanf(fp, "%d", &temperature); printf("cpu temperature: %d.%d\n", temperature/1000, temperature%1000/100); sleep(1); } fclose(fp); return 0; }

执行过程如下:
root@imx6ulevk:~# ./temperature
cpu temperature: 54.4
cpu temperature: 54.4
cpu temperature: 54.4
cpu temperature: 54.4
cpu temperature: 54.4
cpu temperature: 54.4
cpu temperature: 54.4
cpu temperature: 54.4
cpu temperature: 54.4
我们会逐步研究开发板在试验中的过程,温度仅仅是一小部分。
编写不易,如果对您有帮助,点个赞再走呗。

    推荐阅读