3025 shaares
!/bin/bash
#
# (c) Frank Matthieß 2020
#
#
NAME=$(basename $0)
info() { echo "$*">&2; }
error() { info "ERROR: $*"; }
APIURL=https://api.opensensemap.org/boxes
TMPFILE=$(mktemp)
STIDFILE=$(mktemp)
trap 'rm -f ${TMPFILE} ${STIDFILE} ' INT EXIT
# At the map, click on an station icon and you get, for example, this url:
# https://opensensemap.org/explore/5b4d11485dc1ec001b5452c7
#
# Add the id tring at the end of the url with a proper name to the sensor id list
# Sensor id list
cat<<EOSTIDS>$STIDFILE
5c22ef44919bf8001a10acc7 Berlin Charlottenburg
5a9c2087bc2d4100191d6ff9 Stuttgart Unteraichen (A8)
5b4d11485dc1ec001b5452c7 München Fakultät Informatik
EOSTIDS
#
#
# Adjust the field length of the output
llen=0
while read stid location; do
l=$(wc -c <<< "$location")
if [ $llen -lt $l ]; then
llen=$l
fi
done < $STIDFILE
#
# .. and get the need values via opensensemap api
#
while read stid location; do
curl -sL ${APIURL}/${stid} > ${TMPFILE}
reallocation=$(jq .name < ${TMPFILE})
temperature=$(jq '.sensors[] | select(.title|test("Temperatur")) | .title, .lastMeasurement.value, .unit' < ${TMPFILE} | xargs )
humidity=$(jq '.sensors[] | select(.title|test("rel. Luftfeuchte")) | .title, .lastMeasurement.value, .unit' < ${TMPFILE} | xargs )
rawcoordinates=$(jq '.currentLocation.coordinates[]' < ${TMPFILE} | xargs )
coordinates=$(while read lon lat heigh; do echo "https://www.openstreetmap.org/?mlat=${lat}&mlon=${lon}#map=12/${lat}/$lon"; done <<< "${rawcoordinates}")
#
printf "%-${llen}s:\n\tStationsname : %s\n\t%s\n\t%s\n\tOpenstreetmap: %s\n" \
"${location}" \
"${reallocation//\"/}" \
"${temperature}" \
"${humidity}" \
"${coordinates}"
done < $STIDFILE
# vim:set ts=8 sts=8 sw=8 ft=sh ai tw=80: