-
-
Save RandomArray/f142e7f5284c4d3727fec6c30f84edc0 to your computer and use it in GitHub Desktop.
Log Raspberry Pi temperature to text file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp) | |
cpuTemp1=$(($cpuTemp0/1000)) | |
cpuTemp2=$(($cpuTemp0/100)) | |
cpuTempM=$(($cpuTemp2 % $cpuTemp1)) | |
#RPi4 has a different path to vcgencmd on bullseye | |
gpuTemp=$(/opt/vc/bin/vcgencmd measure_temp 2>/dev/null || /usr/bin/vcgencmd measure_temp 2>/dev/null) | |
# Function to write the temperature into the log | |
function writeToLog() { | |
# Path to log file | |
file="/home/pi/temp.log" | |
# Check if the file exists | |
if [ ! -f "$file" ] ; then | |
# if not create the file | |
touch "$file" | |
fi | |
echo "$1" >> "$file" | |
} | |
# Save the value with ISO 8601 timestamp | |
writeToLog "$(date --iso-8601=seconds) - CPU Temp: $cpuTemp1.$cpuTempM'C - GPU Temp: ${gpuTemp:5}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment