Following up from my previous question
#!/usr/bin/env bash
[ -v METRICS_CHECK ] && set -x
API_URL="https://api.thingspeak.com/update"
UPS_PROPS=("LINEV" "LOADPCT" "TIMELEFT")
API_PARAMS=("api_key==XXXXXXXXXXXXXX")
for index in "${!UPS_PROPS[@]}"
do
value=$(/sbin/apcaccess -up "${UPS_PROPS[$index]}")
field=$((index + 1))
if [ "$field" -eq 2 ]
then
# bc required for floating point arithmetic
value=$(echo "$value * 6" | bc) # 600 Watt * load percent
fi
PARAM=$(printf "field%d==%s" "$field" "$value")
API_PARAMS+=("${PARAM}")
done
/usr/local/bin/http "$API_URL" ${API_PARAMS[@]}
Updates:
- Collects data for different metrics supported by
apcaccess
- Use a variable check for enabling debug mode
- Split parameters sent to API URL into a different array
- Move away from
curl
to usehttpie
- Custom computation for certain attributes
The shellcheck passes everything except the unquoted ${API_PARAMS[@]}
in the last line. I am not sure that httpie
would work if I quote that and pass it as a single argument.
Charts for viewing pleasure (last 600 minutes data from the time post was created):
Click the images to get live charts.