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:
@@ -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
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user