#!/bin/bash

# on openwrt change above to #!/bin/ash

hash=<put hash entry here>
token=<put token entry here>
path=<put path entry here>

# just some demo data to prove the thing can actually post to google

start_time='2010-11-08T00:30:00.000'
end_time='2010-11-08T01:30:00.000'
kwh=2.0


#  XML content used to insert a new measurement

result="<?xml version='1.0' encoding='UTF-8'?> \
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:meter='http://schemas.google.com/meter/2008'> \
<meter:startTime meter:uncertainty='1.0'> $start_time </meter:startTime> \
<meter:endTime meter:uncertainty='1.0'> $end_time </meter:endTime> \
<meter:quantity meter:uncertainty='0.001' meter:unit='kW h'>  $kwh </meter:quantity> \
</entry>"



urlreq='https://www.google.com/powermeter/feeds'$path'.d1/durMeasurement'

# may need to add --capath <path to directory containing certificate .pem files>
# to the curl command below if your embedded device isnt configured with default certificates

curl --data-binary "$result"  --request POST --header "Content-Type: application/atom+xml" --header "Authorization: AuthSub token=$token" "$urlreq" 
i

