Skip to content

Instantly share code, notes, and snippets.

@fredrike
Last active December 22, 2015 15:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredrike/6492736 to your computer and use it in GitHub Desktop.
Save fredrike/6492736 to your computer and use it in GitHub Desktop.
#!/bin/bash
API_KEY=""
EMONCMS_API_KEY=""
FEED="https://api.xively.com/v2/feeds/ID"
OUT_URL="http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=IBLEKING8"
OUT="";
function temp_crc {
crc="NO"
while [ $crc = "NO" ]; do
sensor_output=$(cat /sys/bus/w1/devices/$1/w1_slave| cut -c 30-)
crc=$(echo $sensor_output | cut -c 7-10 )
done
echo $(echo $sensor_output | cut -c 11-| awk '{print $1/1000;}')
}
DEVICES=`cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves |grep ^28`
for DEVICE in $DEVICES; do
TEMP=$(temp_crc ${DEVICE})
OUT="$OUT $DEVICE,$TEMP"
done
# grab outside temp from nearby courtesy of weather underground
OUTSIDE=$(curl --silent --request GET $OUT_URL | grep "temp_c" | sed 's/.*>\(.*\)<.*/\1/')
OUT="$OUT OUTSIDE,$OUTSIDE"
#xively
/usr/bin/curl -s --request PUT --header "X-ApiKey: $API_KEY" -d "`echo $OUT|tr ' ' '\n'`" $FEED.csv
#emoncms
OUT=$(echo ${OUT} | tr ',' ':' |tr ' ' ',')
URL="http://emoncms.org/input/post.json?json=${OUT}&apikey=${EMONCMS_API_KEY}&node=31"
/usr/bin/curl -s "$URL" > /dev/null
#end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment