-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
811 additions
and
297 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
1.2.0 | ||
2013-05-01 | ||
1.3.0 | ||
2013-05-10 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
############################################################################## | ||
### @author Knut Kohl <[email protected]> | ||
### @copyright 2012-2013 Knut Kohl | ||
### @license GNU General Public License http://www.gnu.org/licenses/gpl.txt | ||
### @version $Id$ | ||
############################################################################## | ||
|
||
############################################################################## | ||
### Common settings | ||
############################################################################## | ||
|
||
############################################################################## | ||
### Cosm Api URL | ||
### required | ||
############################################################################## | ||
APIURL "http://api.cosm.com/v2/feeds" | ||
|
||
############################################################################## | ||
### Cosm ApiKey, must have the "create" permission | ||
### required | ||
############################################################################## | ||
APIKEY "" | ||
|
||
############################################################################## | ||
### Cosm feed Id | ||
### required | ||
############################################################################## | ||
FEED "" | ||
|
||
############################################################################## | ||
### Update interval, same as in crontab! | ||
### required | ||
############################################################################## | ||
INTERVAL | ||
|
||
############################################################################## | ||
### Per stream settings | ||
############################################################################## | ||
|
||
############################################################################## | ||
### Count of following GUIDs to read | ||
############################################################################## | ||
GUID_N 0 | ||
|
||
############################################################################## | ||
### Reapeat the follwing settings for each channel to read. | ||
### Give all belonging parameters same _<#> | ||
############################################################################## | ||
|
||
### copy >>> | ||
|
||
############################################################################## | ||
### PVLng sensor GUID | ||
### required | ||
############################################################################## | ||
GUID_1 "" | ||
|
||
############################################################################## | ||
### Cosm stream Id | ||
### required | ||
############################################################################## | ||
STREAM_1 "" | ||
|
||
############################################################################## | ||
### Format to push the channel value to Cosm | ||
### Remember, PVLng responses very detailed agerage data, | ||
### so it can make sense to set it to %.1f for example | ||
### Format is used for printf | ||
### optional, defaults to %s | ||
############################################################################## | ||
FORMAT_1 "" | ||
|
||
### <<< copy |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
#!/bin/sh | ||
############################################################################## | ||
### @author Knut Kohl <[email protected]> | ||
### @copyright 2012-2013 Knut Kohl | ||
### @license GNU General Public License http://www.gnu.org/licenses/gpl.txt | ||
### @version $Id$ | ||
############################################################################## | ||
|
||
############################################################################## | ||
### Init | ||
############################################################################## | ||
pwd=$(dirname $0) | ||
APIURL= | ||
APIKEY= | ||
FEED= | ||
GUID_N=0 | ||
|
||
. $pwd/../PVLng.conf | ||
. $pwd/../PVLng.functions | ||
|
||
CACHED=false | ||
|
||
while getopts "tvxh" OPTION; do | ||
case "$OPTION" in | ||
t) TEST=y; VERBOSE=$(expr $VERBOSE + 1) ;; | ||
v) VERBOSE=$(expr $VERBOSE + 1) ;; | ||
x) TRACE=y ;; | ||
h) usage; exit ;; | ||
?) usage; exit 1 ;; | ||
esac | ||
done | ||
|
||
shift $((OPTIND-1)) | ||
|
||
read_config "$1" | ||
|
||
############################################################################## | ||
### Check config data | ||
############################################################################## | ||
test "$APIURL" || error_exit "Cosm API URL is required (APIURL)!" | ||
test "$APIKEY" || error_exit "Cosm ApiKey is required (APIKEY)!" | ||
|
||
test "$FEED" || error_exit "Feed Id must be set (FEED)!" | ||
FEED=$(int "$FEED") | ||
test $FEED -gt 0 || error_exit "Feed Id must > 0 (FEED)!" | ||
|
||
test "$INTERVAL" || error_exit "Update interval must be set (INTERVAL)!" | ||
INTERVAL=$(int "$INTERVAL") | ||
test $INTERVAL -gt 0 || error_exit "Update interval must > 0 (INTERVAL)!" | ||
|
||
GUID_N=$(int "$GUID_N") | ||
test $GUID_N -gt 0 || error_exit "No sections defined (GUID_N)" | ||
|
||
############################################################################## | ||
### Start | ||
############################################################################## | ||
test "$TRACE" && set -x | ||
|
||
curl=$(curl_cmd) | ||
|
||
LC_NUMERIC=en_US | ||
|
||
i=0 | ||
|
||
while test $i -lt $GUID_N; do | ||
|
||
i=$(expr $i + 1) | ||
|
||
log 1 "--- $i ---" | ||
|
||
eval GUID=\$GUID_$i | ||
log 2 "GUID : $GUID" | ||
test "$GUID" || error_exit "Sensor GUID is required (GUID_$i)" | ||
|
||
eval STREAM=\$STREAM_$i | ||
log 2 "Stream : $STREAM" | ||
test "$STREAM" || error_exit "Cosm datastream Id is required (STREAM_$i)" | ||
|
||
eval FORMAT=\$FORMAT_$i | ||
log 2 "Format : $FORMAT" | ||
|
||
### read value | ||
url="$PVLngURL1/$GUID.tsv?period=${INTERVAL}minutes" | ||
log 2 "Get-URL : $url" | ||
|
||
### skip attributes row, get last row | ||
row=$($curl $url | tail -n+2 | tail -n1) | ||
|
||
### Just after 0:00 no data for today yet | ||
test "$row" || continue | ||
|
||
### set timestamp and data to $1 and $2 | ||
set $row | ||
timestamp=$1 | ||
|
||
if test "$FORMAT"; then | ||
value=$(printf "$FORMAT" "$2") | ||
else | ||
value=$2 | ||
fi | ||
|
||
age=$(echo "scale=0;($(date +%s)-$timestamp)/60" | bc -l) | ||
log 2 "Last : $(date -d @$timestamp)" | ||
log 2 "Age : $age min." | ||
|
||
### test for valid timestamp | ||
### last readed timestamp must be greater or equal $valid | ||
if test $age -gt $INTERVAL; then | ||
log 1 "Skip timestamp outside update interval." | ||
continue | ||
fi | ||
|
||
log 1 "Value : $value" | ||
|
||
URL="${APIURL}/${FEED}/datastreams/${STREAM}.csv" | ||
log 1 "Feed-URL : $URL" | ||
|
||
test "$TEST" && continue | ||
|
||
### Send | ||
rc=$($curl --request PUT \ | ||
--header "X-ApiKey: $APIKEY" \ | ||
--write-out %{http_code} \ | ||
--output $TMPFILE \ | ||
--data-binary "$value" \ | ||
$URL) | ||
|
||
### Check result, ONLY 200 is ok | ||
if test $rc -eq 200; then | ||
### Ok, data added | ||
log 1 "Ok" | ||
else | ||
### log error | ||
save_log "Cosm" "Failed: $(cat $TMPFILE)" | ||
fi | ||
|
||
done | ||
|
||
set +x | ||
|
||
exit | ||
|
||
############################################################################## | ||
# USAGE >> | ||
|
||
Push channel data to datastreams on Cosm.com | ||
|
||
Usage: $scriptname [options] config_file | ||
|
||
Options: | ||
|
||
-t Test mode, don't save to PVLng | ||
Sets verbosity to info level | ||
-v Set verbosity level to info level | ||
-vv Set verbosity level to debug level | ||
-h Show this help | ||
Requires a configuation file $pwd/cosm.conf | ||
See $pwd/cosm.conf.dist for details. | ||
# << USAGE |
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
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
Oops, something went wrong.