iniziato implementazione gestione eventi
This commit is contained in:
@@ -2,11 +2,16 @@
|
||||
# Controlla se se piove tramite http://api.wunderground.com/
|
||||
#
|
||||
function check_rain_online {
|
||||
|
||||
trigger_event "check_rain_online_before" ""
|
||||
|
||||
# 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"`
|
||||
local current_state_rain_online=""
|
||||
local last_state_rain_online=`cat "$STATUS_DIR/last_state_rain_online" 2> /dev/null`
|
||||
#echo $weather
|
||||
#weather="[Light/Heavy] Drizzle"
|
||||
if [ "$weather" = "null" ]; then
|
||||
@@ -22,12 +27,17 @@ function check_rain_online {
|
||||
[[ "$weather" == *"Thunderstorm"* ]] ||
|
||||
[[ "$weather" == *"Drizzle"* ]];
|
||||
then
|
||||
#echo "ECCOMI!!!!!"
|
||||
current_state_rain_online='rain'
|
||||
echo $local_epoch > "$STATUS_DIR/last_rain_online"
|
||||
#return $local_epoch
|
||||
fi
|
||||
echo "$current_observation" > "$STATUS_DIR/last_weather_online"
|
||||
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"
|
||||
fi
|
||||
fi
|
||||
|
||||
trigger_event "check_rain_online_after" "$current_state_rain_online"
|
||||
}
|
||||
|
||||
#
|
||||
@@ -36,16 +46,24 @@ function check_rain_online {
|
||||
function check_rain_sensor {
|
||||
|
||||
if [ -n "$RAIN_GPIO" ]; then
|
||||
#local s=`$GPIO -g read $RAIN_GPIO`
|
||||
trigger_event "check_rain_sensor_before" ""
|
||||
local current_state_rain_sensor=""
|
||||
local last_state_rain_sensor=`cat "$STATUS_DIR/last_state_rain_sensor" 2> /dev/null`
|
||||
local s=`drv_rain_sensor_get $RAIN_GPIO`
|
||||
if [ "$s" = "$RAIN_GPIO_STATE" ]; then
|
||||
current_state_rain_sensor='rain'
|
||||
local local_epoch=`date +%s`
|
||||
echo $local_epoch > "$STATUS_DIR/last_rain_sensor"
|
||||
log_write "check_rain_sensor - now it's raining ($local_epoch)"
|
||||
return $local_epoch
|
||||
#return $local_epoch
|
||||
else
|
||||
log_write "check_rain_sensor - now is not raining"
|
||||
fi
|
||||
if [ "$current_state_rain_sensor" != "$last_state_rain_sensor" ]; then
|
||||
echo "$current_state_rain_sensor" > "$STATUS_DIR/last_state_rain_sensor"
|
||||
trigger_event "check_rain_sensor_change" "$current_state_rain_sensor"
|
||||
fi
|
||||
trigger_event "check_rain_sensor_after" "$current_state_rain_sensor"
|
||||
else
|
||||
log_write "Rain sensor not present"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user