Skip to content

Instantly share code, notes, and snippets.

@jplitza
Created March 27, 2018 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jplitza/27b5b7c1c4b9aaa181a8265c6c353228 to your computer and use it in GitHub Desktop.
Save jplitza/27b5b7c1c4b9aaa181a8265c6c353228 to your computer and use it in GitHub Desktop.
#!/bin/sh
SERVER="$1"
INTERVAL=10
# read once and ignore result, as it is bogus at first
cat /sys/bus/w1/devices/*/w1_slave > /dev/null
while sleep "$INTERVAL"; do
for DEV in /sys/bus/w1/devices/*/w1_slave; do
DEVNAME="${DEV%/*}"
DEVNAME="${DEVNAME##*/}"
DEVNAME="$(hostname)-${DEVNAME}"
{
read LINE
if [ "${LINE% YES}" != "$LINE" ]; then
read LINE
TEMP="${LINE##* t=}"
if [ "$TEMP" != "$LINE" ]; then
TEMP="$(($TEMP / 1000)).$(($TEMP % 1000))"
if [ "$TEMP" != "0.0" ]; then
nc -u "$SERVER" 8089 -e \
echo "temperature,location=${DEVNAME} temperature=$TEMP"
fi
fi
fi
} < $DEV
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment