Last active
August 4, 2016 08:25
-
-
Save rk295/0fb7d9c96b9b4ddabada081d334183ea to your computer and use it in GitHub Desktop.
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
# Loop forever - Ctrl-C to stop. | |
while(true);do | |
# Cat the device - assuming only one 28-XXXX (temp sensor) device | |
# pipe that to grep for the data line (there are two lines, only | |
# one is interesting). Use awk to split out the rubbish, leaving | |
# just the temp value | |
temp_raw=$(cat /sys/bus/w1/devices/28-*/w1_slave | \ | |
grep t= | \ | |
awk -F= '{print $2}') | |
# Use bc (apt-get install bc) to divide the raw number by 1000 | |
# Bash variable arithmetic would also work, but you would be | |
# limited to just an INT, and I wanted the 3 decimal places that | |
# the sensor provides. | |
temp_C=$(echo "scale=3; $temp_raw/1000" | bc) | |
# simply echo out the temp in degrees C | |
echo $temp_C | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment