# # Ritorna lo stato delle condizioni meteo interrogando il servizio online # # $i identificativo gpio del sensore di pioggia # # return output: 0 - errore durante il recupero delle condizioni meteo # >0 - rilevato pioggia, timestamp del rilevamento # <0 - rilevato nessuna pioggia, timestamp del rilevamento function drv_openweathermap_rain_online_get { # http://www.wunderground.com/weather/api/d/docs?d=resources/phrase-glossary&MR=1 $CURL "http://api.openweathermap.org/data/2.5/weather?$OPENWEATHERMAP_LOCATION&units=metric&appid=$OPENWEATHERMAP_KEY" > $TMP_PATH/check_rain_online.openweathermap.json local weather=`cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -M ".weather[0].main"` local wind_deg=$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".wind.deg") local wind_speed=$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".wind.speed") if [ "$wind_speed" == "null" ]; then #wind_speed=$($JQ -n $wind_speed*3600/1000) wind_speed=0 fi local weather="$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".weather[0].description")" local ico=$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".weather[0].icon") weather=$(drv_openweathermap_get_wather "$weather") ico=$(drv_openweathermap_get_ico "$ico") local current_observation=$(cat < "$STATUS_DIR/last_weather_online" local local_epoch=`cat $STATUS_DIR/last_weather_online | $JQ -M -r ".local_epoch"` if [[ "$weather" == *"Rain"* ]] || [[ "$weather" == *"Snow"* ]] || [[ "$weather" == *"Hail"* ]] || [[ "$weather" == *"Ice"* ]] || [[ "$weather" == *"Thunderstorm"* ]] || [[ "$weather" == *"Drizzle"* ]]; then echo $local_epoch else echo "-$local_epoch" fi fi }