Created
March 27, 2018 20:09
-
-
Save jplitza/27b5b7c1c4b9aaa181a8265c6c353228 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
#!/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