Skip to content

Instantly share code, notes, and snippets.

@autch
Created February 21, 2019 06:58
Show Gist options
  • Save autch/2e874fa9299ff4111debf13ce4f55e92 to your computer and use it in GitHub Desktop.
Save autch/2e874fa9299ff4111debf13ce4f55e92 to your computer and use it in GitHub Desktop.
gcc -g -Wall -o raspi_temp raspi_temp.c && sudo cp raspi_temp /etc/munin/plugins/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TEMP_PATH "/sys/class/thermal/thermal_zone0/temp"
#define BUFFER_SIZE (1024)
int main(int ac, char **av)
{
if (ac == 2)
{
if (strcmp(av[1], "config") == 0)
{
printf("graph_title Temperature of BCM283x SoC\n");
printf("graph_vlabel temperature in Celcius\n");
printf("graph_args -l %d\n", 0);
printf("graph_scale no\n");
printf("graph_category sensors\n");
printf("vcgencmd_temp.label vcgencmd_temp\n");
printf("vcgencmd_temp.critical %4.2f\n", 85.0);
printf("vcgencmd_temp.warning %4.2f\n", 80.0);
return 0;
}
if (strcmp(av[1], "autoconf") == 0)
{
printf("no\n");
return 0;
}
}
FILE *fp = fopen(TEMP_PATH, "rb");
if (!fp)
{
fprintf(stderr, "Cannot open %s: %s\n", TEMP_PATH, strerror(errno));
return 1;
}
char line[BUFFER_SIZE];
fgets(line, sizeof line, fp);
double f = strtod(line, NULL);
printf("vcgencmd_temp.value %5.4f\n", f / 1000.0);
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment