Skip to content

Instantly share code, notes, and snippets.

@starbuck93
Created August 14, 2018 14:31
Show Gist options
  • Save starbuck93/4b594ee655eef9c7febf5b2550c8ade1 to your computer and use it in GitHub Desktop.
Save starbuck93/4b594ee655eef9c7febf5b2550c8ade1 to your computer and use it in GitHub Desktop.
Quick script to echo the CPU temperature in F and C of a Raspberry Pi Zero, in my case
<?php
$command = "cat /sys/class/thermal/thermal_zone0/temp";
$temp = exec($command);
$tempC1 = ((float) $temp)/1000;
$tempF1 = ($tempC1*(9.0 / 5.0)) + 32.0;
$str = '{"cpu_temperature_F":'.number_format($tempF1,2).',"cpu_temperature_C":'.number_format($tempC1,2).'}';
echo $str;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment