Skip to content

Instantly share code, notes, and snippets.

@xzeldon
Last active May 24, 2021 21:54
Show Gist options
  • Save xzeldon/c2ca353d3e852ae89214c12ee511eb47 to your computer and use it in GitHub Desktop.
Save xzeldon/c2ca353d3e852ae89214c12ee511eb47 to your computer and use it in GitHub Desktop.
Raspberry Pi 4 CPU temperature monitoring (Ubuntu Server LTS 20.04)
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
FILE *fp;
while(1)
{
int temp = 0;
fp = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
fscanf(fp, "%d", &temp);
printf(">> CPU Temp: %.2f°C\n", temp / 1000.0);
fclose(fp);
sleep(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment