Implementato controllo meteo su servizio online tramite driver, implementato driver per interfacciarsi con le api di openweathermap e wunderground
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
# 0.5.8 - xx/07/2018
|
||||
- Added "openweathermap" driver for impement check weather condition from openweatermap api
|
||||
|
||||
# 0.5.7 - 01/06/2018
|
||||
- Added "sonoff_tasmota_http" driver for interfacin with Sonoff module with Tasmota firmware over http protocol
|
||||
|
||||
|
||||
@@ -107,9 +107,19 @@ EV5_GPIO=23 # Physical 16 - wPi 4
|
||||
EV6_ALIAS="6" #
|
||||
EV6_GPIO=24 # Physical 18 - wPi 5
|
||||
|
||||
# Definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
|
||||
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground
|
||||
WEATHER_SERVICE="openweathermap"
|
||||
|
||||
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
OPENWEATHERMAP_KEY=""
|
||||
OPENWEATHERMAP_LOCATION="q=Pieve%20a%20Nievole,it" # https://openweathermap.org/current
|
||||
OPENWEATHERMAP_TZ="Europe/Rome" # Time zone
|
||||
|
||||
# Parametri di wunderground, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
WUNDERGROUND_KEY=""
|
||||
WUNDERGROUND_LOCATION="IY/Monsummano" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||
WUNDERGROUND_LOCATION="IT/Pieve%20a%20Nievole" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||
|
||||
|
||||
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
||||
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||
|
||||
@@ -100,11 +100,19 @@ EV4_ALIAS="Giardino_Posteriore_GPIO" #
|
||||
EV4_GPIO="18"
|
||||
|
||||
|
||||
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground
|
||||
WEATHER_SERVICE="openweathermap"
|
||||
|
||||
# Definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
OPENWEATHERMAP_KEY=""
|
||||
OPENWEATHERMAP_LOCATION="q=Pieve%20a%20Nievole,it" # https://openweathermap.org/current
|
||||
OPENWEATHERMAP_TZ="Europe/Rome" # Time zone
|
||||
|
||||
# Parametri di wunderground, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
WUNDERGROUND_KEY=""
|
||||
WUNDERGROUND_LOCATION="IT/Pieve%20a%20Nievole" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||
|
||||
|
||||
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
||||
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||
NOT_IRRIGATE_IF_RAIN_ONLINE=86400
|
||||
|
||||
@@ -102,10 +102,19 @@ EV4_ALIAS="Giardino_Anteriore"
|
||||
EV4_GPIO="drv:sonoff_tasmota_http:SONOFF2:Power1"
|
||||
|
||||
|
||||
# Definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground
|
||||
WEATHER_SERVICE="openweathermap"
|
||||
|
||||
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
OPENWEATHERMAP_KEY=""
|
||||
OPENWEATHERMAP_LOCATION="q=Pieve%20a%20Nievole,it" # https://openweathermap.org/current
|
||||
OPENWEATHERMAP_TZ="Europe/Rome" # Time zone
|
||||
|
||||
# Parametri di wunderground, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
WUNDERGROUND_KEY=""
|
||||
WUNDERGROUND_LOCATION="IT/Pieve%20a%20Nievole" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||
|
||||
|
||||
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
||||
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||
NOT_IRRIGATE_IF_RAIN_ONLINE=86400
|
||||
|
||||
@@ -472,9 +472,18 @@ EV128_ALIAS="Zona_128" #
|
||||
EV128_GPIO="drv:spb16ch:128"
|
||||
|
||||
|
||||
# Definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground
|
||||
WEATHER_SERVICE="openweathermap"
|
||||
|
||||
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
OPENWEATHERMAP_KEY=""
|
||||
OPENWEATHERMAP_LOCATION="q=Pieve%20a%20Nievole,it" # https://openweathermap.org/current
|
||||
OPENWEATHERMAP_TZ="Europe/Rome" # Time zone
|
||||
|
||||
# Parametri di wunderground, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
WUNDERGROUND_KEY=""
|
||||
WUNDERGROUND_LOCATION="IY/Monsummano" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||
WUNDERGROUND_LOCATION="IT/Pieve%20a%20Nievole" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||
|
||||
|
||||
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
||||
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||
|
||||
13
drv/openweathermap/README.md
Normal file
13
drv/openweathermap/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Driver for check wather condition with openweathermap online service
|
||||
|
||||
# Example of configuration in piGarden.conf
|
||||
|
||||
```bash
|
||||
WEATHER_SERVICE="openweathermap"
|
||||
|
||||
OPENWEATHERMAP_KEY="d4d22ea805788420267971135563b4cc" # Set with your api key of openweathermap
|
||||
OPENWEATHERMAP_LOCATION="q=Pieve%20a%20Nievole,it" # Set with location identify, see https://openweathermap.org/current
|
||||
OPENWEATHERMAP_TZ="Europe/Rome" # Set with your time zone
|
||||
```
|
||||
|
||||
|
||||
123
drv/openweathermap/common.include.sh
Normal file
123
drv/openweathermap/common.include.sh
Normal file
@@ -0,0 +1,123 @@
|
||||
#
|
||||
# Funzioni comuni utilizzate dal driver
|
||||
#
|
||||
|
||||
#
|
||||
# Recupera la descrizione della condizione meteo
|
||||
#
|
||||
# $1 condizione meteo recuperata dalle api
|
||||
#
|
||||
function drv_openweathermap_get_wather {
|
||||
|
||||
declare -A w
|
||||
|
||||
w["thunderstorm with light rain"]="Thunderstorms and Rain"
|
||||
w["thunderstorm with rain"]="Thunderstorms and Rain"
|
||||
w["thunderstorm with heavy rain"]="Thunderstorms and Rain"
|
||||
w["light thunderstorm"]="Thunderstorm"
|
||||
w["thunderstorm"]="Thunderstorm"
|
||||
w["heavy thunderstorm"]="Thunderstorm"
|
||||
w["ragged thunderstorm"]="Thunderstorm"
|
||||
w["thunderstorm with light drizzle"]="Thunderstorms and Rain"
|
||||
w["thunderstorm with drizzle"]="Thunderstorms and Rain"
|
||||
w["thunderstorm with heavy drizzle"]="Thunderstorms and Rain"
|
||||
|
||||
w["light intensity drizzle"]="Drizzle"
|
||||
w["drizzle"]="Drizzle"
|
||||
w["heavy intensity drizzle"]="Drizzle"
|
||||
w["light intensity drizzle rain"]="Drizzle"
|
||||
w["drizzle rain"]="Drizzle"
|
||||
w["heavy intensity drizzle rain"]="Drizzle"
|
||||
w["shower rain and drizzle"]="Drizzle"
|
||||
w["heavy shower rain and drizzle"]="Drizzle"
|
||||
w["shower drizzle"]="Drizzle"
|
||||
|
||||
w["light rain"]="Rain Mist"
|
||||
w["moderate rain"]="Rain"
|
||||
w["heavy intensity rain"]="Rain"
|
||||
w["very heavy rain"]="Rain"
|
||||
w["extreme rain"]="Rain"
|
||||
w["freezing rain"]="Freezing Rain"
|
||||
w["light intensity shower rain"]="Rain"
|
||||
w["shower rain"]="Rain"
|
||||
w["heavy intensity shower rain"]="Rain"
|
||||
w["ragged shower rain"]="Rain"
|
||||
|
||||
w["light snow"]="Snow"
|
||||
w["snow"]="Snow"
|
||||
w["heavy snow"]=""
|
||||
w["sleet"]="Snow Grains"
|
||||
w["shower sleet"]="Snow Grains"
|
||||
w["light rain and snow"]="Snow"
|
||||
w["rain and snow"]="Snow"
|
||||
w["light shower snow"]="Snow"
|
||||
w["shower snow"]="Snow"
|
||||
w["heavy shower snow"]="Snow"
|
||||
|
||||
w["mist"]="Mist"
|
||||
w["smoke"]="Smoke"
|
||||
w["haze"]="Haze"
|
||||
w["sand, dust whirls"]="Dust Whirls"
|
||||
w["fog"]="Fog"
|
||||
w["sand"]="Sand"
|
||||
w["dust"]="Widespread Dust"
|
||||
w["volcanic ash"]="Volcanic Ash"
|
||||
w["squalls"]="Squalls"
|
||||
w["tornado"]="Tornado"
|
||||
|
||||
w["clear sky"]="Clear"
|
||||
|
||||
w["few clouds"]="Partly Cloudy"
|
||||
w["scattered clouds"]="Scattered Clouds"
|
||||
w["broken clouds"]="Partly Cloudy"
|
||||
w["overcast clouds"]="Mostly Cloudy"
|
||||
|
||||
local weather=${w[$1]}
|
||||
|
||||
if [ -z "$weather" ]; then
|
||||
weather="$1"
|
||||
fi
|
||||
|
||||
echo $weather
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
# Recupera la l'icona rappresentativa delle condizione meteo
|
||||
#
|
||||
# $1 nome dell'icona recuperato delle api weather.icon
|
||||
#
|
||||
function drv_openweathermap_get_ico {
|
||||
|
||||
declare -A w
|
||||
|
||||
w["01d"]="http://icons.wxug.com/i/c/k/clear.gif"
|
||||
w["01n"]="http://icons.wxug.com/i/c/k/nt_clear.gif"
|
||||
w["02d"]="http://icons.wxug.com/i/c/k/partlycloudy.gif"
|
||||
w["02n"]="http://icons.wxug.com/i/c/k/nt_partlycloudy.gif"
|
||||
w["03d"]="http://icons.wxug.com/i/c/k/cloudy.gif"
|
||||
w["03n"]="http://icons.wxug.com/i/c/k/nt_cloudy.gif"
|
||||
w["04d"]="http://icons.wxug.com/i/c/k/cloudy.gif"
|
||||
w["04n"]="http://icons.wxug.com/i/c/k/nt_cloudy.gif"
|
||||
w["09d"]="http://icons.wxug.com/i/c/k/sleet.gif"
|
||||
w["09n"]="http://icons.wxug.com/i/c/k/nt_sleet.gif"
|
||||
w["10d"]="http://icons.wxug.com/i/c/k/rain.gif"
|
||||
w["10n"]="http://icons.wxug.com/i/c/k/nt_rain.gif"
|
||||
w["11d"]="http://icons.wxug.com/i/c/k/tstorms.gif"
|
||||
w["11n"]="http://icons.wxug.com/i/c/k/nt_tstorms.gif"
|
||||
w["13d"]="http://icons.wxug.com/i/c/k/snow.gif"
|
||||
w["13n"]="http://icons.wxug.com/i/c/k/nt_snow.gif"
|
||||
w["50d"]="http://icons.wxug.com/i/c/k/fog.gif"
|
||||
w["50n"]="http://icons.wxug.com/i/c/k/nt_fog.gif"
|
||||
|
||||
local ico=${w[$1]}
|
||||
|
||||
if [ -z "$ico" ]; then
|
||||
ico="$1"
|
||||
fi
|
||||
|
||||
echo $ico
|
||||
|
||||
}
|
||||
|
||||
|
||||
74
drv/openweathermap/rainonline.include.sh
Normal file
74
drv/openweathermap/rainonline.include.sh
Normal file
@@ -0,0 +1,74 @@
|
||||
#
|
||||
# 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 <<EOF
|
||||
{
|
||||
"display_location": {
|
||||
"city": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".name")"
|
||||
},
|
||||
"observation_epoch": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".dt")",
|
||||
"local_epoch": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".dt")",
|
||||
"local_tz_long": "$OPENWEATHERMAP_TZ",
|
||||
"weather": "$weather",
|
||||
"temp_c": $(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".main.temp"),
|
||||
"relative_humidity": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".main.humidity")%",
|
||||
"wind_dir": "$(deg2dir $wind_deg)",
|
||||
"wind_degrees": $wind_deg,
|
||||
"wind_kph": $wind_speed,
|
||||
"wind_gust_kph": "--",
|
||||
"pressure_mb": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".main.pressure")",
|
||||
"dewpoint_c": "--",
|
||||
"feelslike_c": "--",
|
||||
"icon_url": "$ico"
|
||||
}
|
||||
EOF
|
||||
)
|
||||
# "icon_url": "http://openweathermap.org/img/w/$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".weather[0].icon").png"
|
||||
|
||||
#local current_observation=`cat $TMP_PATH/check_rain_online.json | $JQ -M ".current_observation"`
|
||||
|
||||
if [ "$weather" = "null" ]; then
|
||||
echo "0"
|
||||
else
|
||||
echo "$current_observation" > "$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
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,12 @@
|
||||
# Fake driver for sample and testing
|
||||
# Driver for check wather condition with wunderground online service
|
||||
|
||||
# Example of configuration in piGarden.conf
|
||||
|
||||
```bash
|
||||
WEATHER_SERVICE="wunderground"
|
||||
|
||||
WUNDERGROUND_KEY="" # Set with your api key of wunderground
|
||||
WUNDERGROUND_LOCATION="IY/Monsummano" # Set with your location indentify, see http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||
```
|
||||
|
||||
|
||||
|
||||
90
piGarden.sh
90
piGarden.sh
@@ -782,6 +782,94 @@ function exec_reboot {
|
||||
trigger_event "exec_reboot_after"
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Converte da gradi a direzione
|
||||
#
|
||||
# $1 gradi
|
||||
#
|
||||
function deg2dir {
|
||||
local deg=$(echo $1 | $SED 's/\..*$//')
|
||||
local dir=""
|
||||
|
||||
if [ "$deg" == "null" ]; then
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
|
||||
# N 348.75 - 11.25
|
||||
if [ $deg -le 11 ]; then
|
||||
dir="North"
|
||||
|
||||
# NNE 11.25 - 33.75
|
||||
elif [ $deg -le 33 ]; then
|
||||
dir="NNE"
|
||||
|
||||
# NE 33.75 - 56.25
|
||||
elif [ $deg -le 56 ]; then
|
||||
dir="NE"
|
||||
|
||||
# ENE 56.25 - 78.75
|
||||
elif [ $deg -le 78 ]; then
|
||||
dir="ENE"
|
||||
|
||||
# E 78.75 - 101.25
|
||||
elif [ $deg -le 101 ]; then
|
||||
dir="East"
|
||||
|
||||
# ESE 101.25 - 123.75
|
||||
elif [ $deg -le 123 ]; then
|
||||
dir="ESE"
|
||||
|
||||
# SE 123.75 - 146.25
|
||||
elif [ $deg -le 146 ]; then
|
||||
dir="SE"
|
||||
|
||||
# SSE 146.25 - 168.75
|
||||
elif [ $deg -le 168 ]; then
|
||||
dir="SSE"
|
||||
|
||||
# S 168.75 - 191.25
|
||||
elif [ $deg -le 191 ]; then
|
||||
dir="South"
|
||||
|
||||
# SSW 191.25 - 213.75
|
||||
elif [ $deg -le 213 ]; then
|
||||
dir="SSW"
|
||||
|
||||
# SW 213.75 - 236.25
|
||||
elif [ $deg -le 236 ]; then
|
||||
dir="SW"
|
||||
|
||||
# WSW 236.25 - 258.75
|
||||
elif [ $deg -le 258 ]; then
|
||||
dir="WSW"
|
||||
|
||||
# W 258.75 - 281.25
|
||||
elif [ $deg -le 281 ]; then
|
||||
dir="West"
|
||||
|
||||
# WNW 281.25 - 303.75
|
||||
elif [ $deg -le 303 ]; then
|
||||
dir="WNW"
|
||||
|
||||
# NW 303.75 - 326.25
|
||||
elif [ $deg -le 326 ]; then
|
||||
dir="NW"
|
||||
|
||||
# NNW 326.25 - 348.75
|
||||
elif [ $deg -le 348 ]; then
|
||||
dir="NNW"
|
||||
|
||||
# N 348.75 - 11.25
|
||||
else
|
||||
dir="North"
|
||||
fi
|
||||
|
||||
echo $dir
|
||||
|
||||
}
|
||||
|
||||
function debug1 {
|
||||
. "$DIR_SCRIPT/debug/debug1.sh"
|
||||
}
|
||||
@@ -792,7 +880,7 @@ function debug2 {
|
||||
|
||||
VERSION=0
|
||||
SUB_VERSION=5
|
||||
RELEASE_VERSION=7
|
||||
RELEASE_VERSION=8
|
||||
|
||||
DIR_SCRIPT=`dirname $0`
|
||||
NAME_SCRIPT=${0##*/}
|
||||
|
||||
Reference in New Issue
Block a user