Implementato driver subsistem per il controllo delle condizioni meteo tramite servizio online. Implementato driver 'wunderground' per il controllo meteo tramite il servizio wunderground
This commit is contained in:
13
drv/sample/rainonline.include.sh
Normal file
13
drv/sample/rainonline.include.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
#
|
||||
# Ritorna lo stato delle condizioni meteo interrogando il servizio online
|
||||
#
|
||||
# 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_sample_rain_online_get {
|
||||
|
||||
local FOO="bar"
|
||||
|
||||
}
|
||||
|
||||
|
||||
2
drv/wunderground/README.md
Normal file
2
drv/wunderground/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# Fake driver for sample and testing
|
||||
|
||||
12
drv/wunderground/common.include.sh
Normal file
12
drv/wunderground/common.include.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#
|
||||
# Funzioni comuni utilizzate dal driver
|
||||
#
|
||||
|
||||
#
|
||||
# Funzione di esempio
|
||||
#
|
||||
function sample_foo {
|
||||
|
||||
echo "bar"
|
||||
|
||||
}
|
||||
36
drv/wunderground/rainonline.include.sh
Normal file
36
drv/wunderground/rainonline.include.sh
Normal file
@@ -0,0 +1,36 @@
|
||||
#
|
||||
# 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_wunderground_rain_online_get {
|
||||
|
||||
# http://www.wunderground.com/weather/api/d/docs?d=resources/phrase-glossary&MR=1
|
||||
$CURL http://api.wunderground.com/api/$WUNDERGROUND_KEY/conditions/q/$WUNDERGROUND_LOCATION.json > $TMP_PATH/check_rain_online.json
|
||||
local weather=`cat $TMP_PATH/check_rain_online.json | $JQ -M ".current_observation.weather"`
|
||||
local current_observation=`cat $TMP_PATH/check_rain_online.json | $JQ -M ".current_observation"`
|
||||
local local_epoch=`cat $TMP_PATH/check_rain_online.json | $JQ -M -r ".current_observation.local_epoch"`
|
||||
|
||||
if [ "$weather" = "null" ]; then
|
||||
echo "0"
|
||||
else
|
||||
if [[ "$weather" == *"Rain"* ]] ||
|
||||
[[ "$weather" == *"Snow"* ]] ||
|
||||
[[ "$weather" == *"Hail"* ]] ||
|
||||
[[ "$weather" == *"Ice"* ]] ||
|
||||
[[ "$weather" == *"Thunderstorm"* ]] ||
|
||||
[[ "$weather" == *"Drizzle"* ]];
|
||||
then
|
||||
echo $local_epoch
|
||||
else
|
||||
echo "-$local_epoch"
|
||||
fi
|
||||
echo "$current_observation" > "$STATUS_DIR/last_weather_online"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ function setup_drv {
|
||||
done
|
||||
|
||||
# Inizializza i driver per gli altri gpio
|
||||
for gpio in "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2" "$RAIN_GPIO"
|
||||
for gpio in "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2" "$RAIN_GPIO" "$WEATHER_SERVICE"
|
||||
do
|
||||
if [[ "$gpio" == drv:* ]]; then
|
||||
local drv=`echo $gpio | $CUT -d':' -f2,2`
|
||||
@@ -32,7 +32,7 @@ function setup_drv {
|
||||
local file_drv
|
||||
for drv in "${list_drv[@]}"
|
||||
do
|
||||
for callback in config common init rele supply rainsensor setup
|
||||
for callback in config common init rele supply rainsensor rainonline setup
|
||||
do
|
||||
file_drv="$DIR_SCRIPT/drv/$drv/$callback.include.sh"
|
||||
if [ -f "$file_drv" ]; then
|
||||
@@ -315,3 +315,30 @@ function drv_rain_sensor_get {
|
||||
echo "$vret"
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
# Legge lo stato le condizioni meteo dal servizio online
|
||||
#
|
||||
# $1 identificativo gpio sensore pioggia
|
||||
#
|
||||
function drv_rain_online_get {
|
||||
local idx="$1"
|
||||
local fnc=`get_driver_callback "rain_online_get" "$idx"`
|
||||
local vret=""
|
||||
|
||||
# Nessun driver definito, esegue la lettura del sensore tramite gpio del raspberry
|
||||
if [ -z "$fnc" ]; then
|
||||
log_write "Driver not found: $idx"
|
||||
message_write "warning" "Driver not found: $idx"
|
||||
# Il driver definito non è stato trovato
|
||||
elif [ "$fnc" == "drvnotfound" ]; then
|
||||
log_write "Driver not found: $idx"
|
||||
message_write "warning" "Driver not found: $idx"
|
||||
else
|
||||
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
|
||||
vret=`$fnc "$idx"`
|
||||
fi
|
||||
|
||||
echo "$vret"
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Controlla se se piove tramite http://api.wunderground.com/
|
||||
#
|
||||
function check_rain_online {
|
||||
function check_rain_online_old {
|
||||
|
||||
trigger_event "check_rain_online_before" ""
|
||||
|
||||
@@ -42,6 +42,55 @@ function check_rain_online {
|
||||
trigger_event "check_rain_online_after" "$current_state_rain_online" "$weather"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Controlla se se piove tramite http://api.wunderground.com/
|
||||
#
|
||||
function check_rain_online {
|
||||
|
||||
trigger_event "check_rain_online_before" ""
|
||||
|
||||
local local_epoch=`drv_rain_online_get $WEATHER_SERVICE`
|
||||
local current_state_rain_online=""
|
||||
local last_state_rain_online=`cat "$STATUS_DIR/last_state_rain_online" 2> /dev/null`
|
||||
local weather="null"
|
||||
|
||||
if [[ $local_epoch =~ ^-?[0-9]+$ ]]; then
|
||||
if [ $local_epoch -eq 0 ]; then
|
||||
log_write "check_rain_online - failed read online data"
|
||||
else
|
||||
if [ $local_epoch -gt 0 ]; then
|
||||
current_state_rain_online='rain'
|
||||
echo $local_epoch > "$STATUS_DIR/last_rain_online"
|
||||
else
|
||||
current_state_rain_online='norain'
|
||||
fi
|
||||
weather=$(cat "$STATUS_DIR/last_weather_online" | $JQ -M ".weather")
|
||||
|
||||
log_write "check_rain_online - weather=$weather, local_epoch=$local_epoch"
|
||||
if [ "$current_state_rain_online" != "$last_state_rain_online" ]; then
|
||||
echo "$current_state_rain_online" > "$STATUS_DIR/last_state_rain_online"
|
||||
trigger_event "check_rain_online_change" "$current_state_rain_online" "$weather"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
log_write "check_rain_online - failed read online data"
|
||||
fi
|
||||
|
||||
trigger_event "check_rain_online_after" "$current_state_rain_online" "$weather"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Controlla se se piove tramite sensore
|
||||
#
|
||||
|
||||
@@ -832,6 +832,11 @@ if [ -z "$EVENT_DIR" ]; then
|
||||
EVENT_DIR="$DIR_SCRIPT/events"
|
||||
fi
|
||||
|
||||
if [ -z $WEATHER_SERVICE ]; then
|
||||
WEATHER_SERVICE="drv:wunderground"
|
||||
else
|
||||
WEATHER_SERVICE="drv:$WEATHER_SERVICE"
|
||||
fi
|
||||
|
||||
# Elimina il file di lock se più vecchio di 11 secondi
|
||||
if [ -f "$LOCK_FILE" ]; then
|
||||
|
||||
Reference in New Issue
Block a user