Skip to content

Instantly share code, notes, and snippets.

@x2q
Created October 11, 2012 14:39
Show Gist options
  • Save x2q/3872852 to your computer and use it in GitHub Desktop.
Save x2q/3872852 to your computer and use it in GitHub Desktop.
First attempt to fetch data from a SPIII solar controller and My Current Cost and post the data to emoncms.org
#!/bin/bash
# Crontab
# # m h dom mon dow command
# */1 * * * * /home/raspberrypi/SPIII-Current-Cost.sh
function update {
data=`curl -s --request GET --header "X-ApiKey: <api-key>" \
http://api.cosm.com/v2/feeds/<feed-id>.csv | awk -F "\"*,\"*" '{print "el-"$1":"$3}' | tr '\n' ','`
url="http://emoncms.org/api/post?apikey=<api-key>&json={$data}"
curl $url > /dev/null 2>&1
data=`curl -s -u admin: http://192.168.1.99/1 \
| lynx -stdin -dump \
| sed 's/\///g' \
| sed 's/Gennemstr.mning/gennemstromning/g' \
| sed -n '4,12p' \
| tr "[:upper:]" "[:lower:]" \
| awk '{printf "sol-"$1":"$2","}'`
url="http://emoncms.org/api/post?apikey=<api-key>&json={$data}"
curl $url > /dev/null 2>&1
sleep 1;
data=`curl -s -u admin: http://192.168.1.99/6 \
| lynx -stdin -dump \
| sed 's/kkal/ kkal/g' \
| sed 's/Total/total-kcal/g' \
| sed -n '7,7p' \
| tr "[:upper:]" "[:lower:]" \
| awk '{printf "sol-"$1":"$2",sol-total-kwh:"$2*0.00116222222}'`
url="http://emoncms.org/api/post?apikey=<api-key>&json={$data}"
curl $url > /dev/null 2>&1
sleep 1;
old=`cat /tmp/watth.data`
current=`curl -s -u admin: http://192.168.1.99/6 \
| lynx -stdin -dump \
| sed 's/kkal/ kkal/g' \
| sed 's/Total/total-kcal/g' \
| sed -n '7,7p' \
| tr "[:upper:]" "[:lower:]" \
| awk '{printf "%i", $2*1.163}'`
echo $old
echo $current
let "watt=($current-$old)"
echo $watt
echo "$current" > /tmp/watth.data
url="http://emoncms.org/api/post?apikey=<api-key>&json={sol-watt:$watt}"
curl $url > /dev/null 2>&1
sleep 1;
data=`curl -s -u admin: http://192.168.1.99/2 \
| lynx -stdin -dump -display_charset=UTF-8 \
| sed 's/Elektrisk varme/Elektrisk-varme/g' \
| sed 's/Aktuelt system/Aktuelt-system/g' \
| sed 's/stoppet/0/g' \
| sed 's/k.*rer$/1/g' \
| sed 's/N\.C\./0/g' \
| sed 's/N\.O\./1/g' \
| sed 's/\///g' \
| sed -n '4,10p' \
| tr "[:upper:]" "[:lower:]" \
| awk '{printf "sol-"$1":"$2","}'`
url="http://emoncms.org/api/post?apikey=<api-key>&json={$data}"
curl $url > /dev/null 2>&1
}
update
sleep 30;
update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment