added bash script to query sensebox

This commit is contained in:
ikselven 2017-11-19 18:56:03 +01:00
parent b2494ffe43
commit 150508b901
3 changed files with 33 additions and 1 deletions

View file

@ -1 +0,0 @@
# sensebox-query

16
README.org Normal file
View file

@ -0,0 +1,16 @@
* sensebox-query
A little Bash script for querying the Sensebox installed at Krautspace.
There are still some things to do, feel free to contribute code to solve
these issues.
*TODO:*
- make output to shell prettier
- use conditional coloring, e.g. cold -> blue, warm -> red
- use ASCII art
- format date
- deal with errors
- curl might not be installed
- curl might fail (e.g. no connection)
- grep might not find anything

17
sensebox-query Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
declare -r URL="https://api.opensensemap.org/boxes/59d7de4c66f66a0010797868/sensors"
declare -r TMPFILE="/tmp/sense-data"
curl --silent "$URL" | tr '{[,' "\n" > "$TMPFILE"
RAW_VALUES="$(grep -e "title" -e "unit" -e "value" -e "createdAt" "$TMPFILE" | cut -d'"' -f4)"
IFS=$'\n' RAW_VALUES=(${RAW_VALUES})
declare -a VALUES
for i in {1..5}; do
raw_index=$(( $i * 4 - 4 ))
VALUES[$i]="${RAW_VALUES[$raw_index]}:\t${RAW_VALUES[$raw_index + 2]} ${RAW_VALUES[$raw_index + 1]}\t(as of: ${RAW_VALUES[$raw_index + 3]})"
echo -e "${VALUES[$i]}"
done