Skip to content

Instantly share code, notes, and snippets.

@rk295
Last active August 4, 2016 08:25
Show Gist options
  • Save rk295/0fb7d9c96b9b4ddabada081d334183ea to your computer and use it in GitHub Desktop.
Save rk295/0fb7d9c96b9b4ddabada081d334183ea to your computer and use it in GitHub Desktop.
# 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