separato codice di gestione pioggia da script principale, variato numero di versione, rimosso commenti non necessari in testa ai file di inclusione
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Elimina una tipoliga di schedulazione dal crontab dell'utente
|
# Elimina una tipoliga di schedulazione dal crontab dell'utente
|
||||||
# $1 tipologia del crontab
|
# $1 tipologia del crontab
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#declare -A drv_avalible
|
|
||||||
declare -a list_drv
|
declare -a list_drv
|
||||||
|
|
||||||
function setup_drv {
|
function setup_drv {
|
||||||
|
|||||||
99
include/rain.include.sh
Normal file
99
include/rain.include.sh
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#
|
||||||
|
# Controlla se se piove tramite http://api.wunderground.com/
|
||||||
|
#
|
||||||
|
function check_rain_online {
|
||||||
|
# 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"`
|
||||||
|
#echo $weather
|
||||||
|
#weather="[Light/Heavy] Drizzle"
|
||||||
|
if [ "$weather" = "null" ]; then
|
||||||
|
log_write "check_rain_online - failed read online data"
|
||||||
|
else
|
||||||
|
log_write "check_rain_online - weather=$weather, local_epoch=$local_epoch"
|
||||||
|
#if [[ "$weather" == *"Clear"* ]]; then
|
||||||
|
#if [[ "$weather" == *"Rain"* ]]; then
|
||||||
|
if [[ "$weather" == *"Rain"* ]] ||
|
||||||
|
[[ "$weather" == *"Snow"* ]] ||
|
||||||
|
[[ "$weather" == *"Hail"* ]] ||
|
||||||
|
[[ "$weather" == *"Ice"* ]] ||
|
||||||
|
[[ "$weather" == *"Thunderstorm"* ]] ||
|
||||||
|
[[ "$weather" == *"Drizzle"* ]];
|
||||||
|
then
|
||||||
|
#echo "ECCOMI!!!!!"
|
||||||
|
echo $local_epoch > "$STATUS_DIR/last_rain_online"
|
||||||
|
return $local_epoch
|
||||||
|
fi
|
||||||
|
echo "$current_observation" > "$STATUS_DIR/last_weather_online"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Controlla se se piove tramite sensore
|
||||||
|
#
|
||||||
|
function check_rain_sensor {
|
||||||
|
|
||||||
|
if [ -n "$RAIN_GPIO" ]; then
|
||||||
|
#local s=`$GPIO -g read $RAIN_GPIO`
|
||||||
|
local s=`drv_rain_sensor_get $RAIN_GPIO`
|
||||||
|
if [ "$s" = "$RAIN_GPIO_STATE" ]; then
|
||||||
|
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
|
||||||
|
else
|
||||||
|
log_write "check_rain_sensor - now is not raining"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log_write "Rain sensor not present"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Chiude tutte le elettrovalvole se sta piovendo
|
||||||
|
# Eseguie il controllo in tempo reale sul sensore hardware e sui dati dell'ultima chiamata eseguita online
|
||||||
|
#
|
||||||
|
function close_all_for_rain {
|
||||||
|
|
||||||
|
local close_all=0
|
||||||
|
local now=`date +%s`
|
||||||
|
|
||||||
|
if [[ "$NOT_IRRIGATE_IF_RAIN_ONLINE" -gt 0 && -f $STATUS_DIR/last_rain_online ]]; then
|
||||||
|
local last_rain=`cat $STATUS_DIR/last_rain_online`
|
||||||
|
local dif=0
|
||||||
|
let "dif = now - last_rain"
|
||||||
|
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_ONLINE ]; then
|
||||||
|
close_all=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$NOT_IRRIGATE_IF_RAIN_SENSOR" -gt 0 && -f $STATUS_DIR/last_rain_sensor ]]; then
|
||||||
|
local last_rain=`cat $STATUS_DIR/last_rain_sensor`
|
||||||
|
local dif=0
|
||||||
|
let "dif = now - last_rain"
|
||||||
|
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_SENSOR ]; then
|
||||||
|
close_all=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$close_all" = "1" ]; then
|
||||||
|
for i in $(seq $EV_TOTAL)
|
||||||
|
do
|
||||||
|
local a=EV"$i"_ALIAS
|
||||||
|
local al=${!a}
|
||||||
|
ev_status $al
|
||||||
|
local state=$?
|
||||||
|
#echo "$al = $state"
|
||||||
|
if [ "$state" = "1" ]; then
|
||||||
|
ev_close $al
|
||||||
|
log_write "close_all_for_rain - Close solenoid '$al' for rain"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Avvia il socket server
|
# Avvia il socket server
|
||||||
#
|
#
|
||||||
|
|||||||
101
piGarden.sh
101
piGarden.sh
@@ -408,104 +408,6 @@ function ev_status {
|
|||||||
return $state
|
return $state
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
|
||||||
# Controlla se se piove tramite http://api.wunderground.com/
|
|
||||||
#
|
|
||||||
function check_rain_online {
|
|
||||||
# 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"`
|
|
||||||
#echo $weather
|
|
||||||
#weather="[Light/Heavy] Drizzle"
|
|
||||||
if [ "$weather" = "null" ]; then
|
|
||||||
log_write "check_rain_online - failed read online data"
|
|
||||||
else
|
|
||||||
log_write "check_rain_online - weather=$weather, local_epoch=$local_epoch"
|
|
||||||
#if [[ "$weather" == *"Clear"* ]]; then
|
|
||||||
#if [[ "$weather" == *"Rain"* ]]; then
|
|
||||||
if [[ "$weather" == *"Rain"* ]] ||
|
|
||||||
[[ "$weather" == *"Snow"* ]] ||
|
|
||||||
[[ "$weather" == *"Hail"* ]] ||
|
|
||||||
[[ "$weather" == *"Ice"* ]] ||
|
|
||||||
[[ "$weather" == *"Thunderstorm"* ]] ||
|
|
||||||
[[ "$weather" == *"Drizzle"* ]];
|
|
||||||
then
|
|
||||||
#echo "ECCOMI!!!!!"
|
|
||||||
echo $local_epoch > "$STATUS_DIR/last_rain_online"
|
|
||||||
return $local_epoch
|
|
||||||
fi
|
|
||||||
echo "$current_observation" > "$STATUS_DIR/last_weather_online"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Controlla se se piove tramite sensore
|
|
||||||
#
|
|
||||||
function check_rain_sensor {
|
|
||||||
|
|
||||||
if [ -n "$RAIN_GPIO" ]; then
|
|
||||||
#local s=`$GPIO -g read $RAIN_GPIO`
|
|
||||||
local s=`drv_rain_sensor_get $RAIN_GPIO`
|
|
||||||
if [ "$s" = "$RAIN_GPIO_STATE" ]; then
|
|
||||||
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
|
|
||||||
else
|
|
||||||
log_write "check_rain_sensor - now is not raining"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
log_write "Rain sensor not present"
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Chiude tutte le elettrovalvole se sta piovendo
|
|
||||||
# Eseguie il controllo in tempo reale sul sensore hardware e sui dati dell'ultima chiamata eseguita online
|
|
||||||
#
|
|
||||||
function close_all_for_rain {
|
|
||||||
|
|
||||||
local close_all=0
|
|
||||||
local now=`date +%s`
|
|
||||||
|
|
||||||
if [[ "$NOT_IRRIGATE_IF_RAIN_ONLINE" -gt 0 && -f $STATUS_DIR/last_rain_online ]]; then
|
|
||||||
local last_rain=`cat $STATUS_DIR/last_rain_online`
|
|
||||||
local dif=0
|
|
||||||
let "dif = now - last_rain"
|
|
||||||
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_ONLINE ]; then
|
|
||||||
close_all=1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$NOT_IRRIGATE_IF_RAIN_SENSOR" -gt 0 && -f $STATUS_DIR/last_rain_sensor ]]; then
|
|
||||||
local last_rain=`cat $STATUS_DIR/last_rain_sensor`
|
|
||||||
local dif=0
|
|
||||||
let "dif = now - last_rain"
|
|
||||||
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_SENSOR ]; then
|
|
||||||
close_all=1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$close_all" = "1" ]; then
|
|
||||||
for i in $(seq $EV_TOTAL)
|
|
||||||
do
|
|
||||||
local a=EV"$i"_ALIAS
|
|
||||||
local al=${!a}
|
|
||||||
ev_status $al
|
|
||||||
local state=$?
|
|
||||||
#echo "$al = $state"
|
|
||||||
if [ "$state" = "1" ]; then
|
|
||||||
ev_close $al
|
|
||||||
log_write "close_all_for_rain - Close solenoid '$al' for rain"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Chiude tutte le elettrovalvole
|
# Chiude tutte le elettrovalvole
|
||||||
# $1 indica se forzare la chiusura anche per le elettrovalvole con stato di inattività
|
# $1 indica se forzare la chiusura anche per le elettrovalvole con stato di inattività
|
||||||
@@ -817,7 +719,7 @@ function debug2 {
|
|||||||
|
|
||||||
VERSION=0
|
VERSION=0
|
||||||
SUB_VERSION=4
|
SUB_VERSION=4
|
||||||
RELEASE_VERSION=4
|
RELEASE_VERSION=5
|
||||||
|
|
||||||
DIR_SCRIPT=`dirname $0`
|
DIR_SCRIPT=`dirname $0`
|
||||||
NAME_SCRIPT=${0##*/}
|
NAME_SCRIPT=${0##*/}
|
||||||
@@ -842,6 +744,7 @@ fi
|
|||||||
. "$DIR_SCRIPT/include/drv.include.sh"
|
. "$DIR_SCRIPT/include/drv.include.sh"
|
||||||
. "$DIR_SCRIPT/include/cron.include.sh"
|
. "$DIR_SCRIPT/include/cron.include.sh"
|
||||||
. "$DIR_SCRIPT/include/socket.include.sh"
|
. "$DIR_SCRIPT/include/socket.include.sh"
|
||||||
|
. "$DIR_SCRIPT/include/rain.include.sh"
|
||||||
|
|
||||||
LAST_INFO_FILE="$STATUS_DIR/last_info"
|
LAST_INFO_FILE="$STATUS_DIR/last_info"
|
||||||
LAST_WARNING_FILE="$STATUS_DIR/last_worning"
|
LAST_WARNING_FILE="$STATUS_DIR/last_worning"
|
||||||
|
|||||||
Reference in New Issue
Block a user