Aggunto eventi cron_add_before, cron_add_after, cron_del_before, cron_del_after, ev_open_in_before, ev_open_in_after, exec_poweroff_before, exec_poweroff_after, exec_reboot_before, exec_reboot_after ed eseguito bugfix vari

This commit is contained in:
lejubila
2017-11-19 23:24:48 +01:00
parent 8d4849db75
commit 22ec16cc9d
17 changed files with 161 additions and 26 deletions

View File

@@ -1,3 +1,11 @@
# 0.5.3 - 19/11/2017
- Fix send parameter on event init_before and init_after
- Added WEATHER argument in check_rain_sensor_after and check_rain_sensor_change event
- Added events cron_add_before, cron_add_after, cron_del_before, cron_del_after, ev_open_in_before, ev_open_in_after, exec_poweroff_before, exec_poweroff_after, exec_reboot_before, exec_reboot_after
- Added to sendmail.sh argument passed form check_rain_sensor_after and check_rain_sensor_change event
- Added to sendmail.sh new events
- Fix wrong state on event script sendmail.sh
# 0.5.2 - 01/11/2017
- Fix problem inconsistent return value in drv_rain_sensor_get
- Fix get parameter in event script sendmail.sh

View File

@@ -4,7 +4,7 @@ Bash script to manage an irrigation system built with a Raspberry Pi
## Official documentation
Documentation of piGarden and build system irrigation with Raspberry Pi can be found on the [www.lejubila.net/tag/pigarden/](http://www.lejubila.net/tag/pigarden/)
Documentation of piGarden and build system irrigation with Raspberry Pi can be found on the [www.lejubila.net/pigarden/](http://www.lejubila.net/pigarden/)
## License
@@ -66,5 +66,3 @@ sudo cp piGarden/conf/piGarden.conf.example /etc/piGarden.conf
Customize the configuration file.
For more information see
[www.lejubila.net/2015/12/impianto-di-irrigazione-con-raspberry-pi-pigarden-lo-script-di-gestione-quinta-parte/](https://www.lejubila.net/2015/12/impianto-di-irrigazione-con-raspberry-pi-pigarden-lo-script-di-gestione-quinta-parte/)
and
[www.lejubila.net/2017/04/pigarden-0-2-easter-egg/](https://www.lejubila.net/2017/04/pigarden-0-2-easter-egg/)

4
events/cron_add_after/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

4
events/cron_add_before/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

4
events/cron_del_after/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

4
events/cron_del_before/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

4
events/ev_open_in_after/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

4
events/ev_open_in_before/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

4
events/exec_poweroff_after/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

View File

@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

4
events/exec_reboot_after/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

4
events/exec_reboot_before/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

View File

@@ -24,7 +24,7 @@ EVENT="$1"
TO="mail@destination.com"
FROM="piGarden@your_domain.com"
SUBJECT="piGarden notification mail: event $EVENT"
SUBJECT="[piGarden notification mail] event $EVENT"
BODY=""
case "$EVENT" in
@@ -40,6 +40,25 @@ case "$EVENT" in
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nZONE: $ALIAS\nFORCED IRRIGATION: $FORCE\nTIME: $(/bin/date -d@$TIME)"
;;
"ev_open_in_before")
ALIAS="$2"
FORCE="$3"
MINUTE_START="$4"
MINUTE_STOP="$5"
TIME=$6
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nZONE: $ALIAS\nFORCED IRRIGATION: $FORCE\nMINUTE START: $MINUTE_START\nMINUTE STOP: $MINUTE_STOP\nTIME: $(/bin/date -d@$TIME)"
;;
"ev_open_in_after")
ALIAS="$2"
FORCE="$3"
CRON_START="$4"
CRON_STOP="$5"
TIME=$6
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nZONE: $ALIAS\nFORCED IRRIGATION: $FORCE\nCRON START: $CRON_START\nCRON STOP: $CRON_STOP\nTIME: $(/bin/date -d@$TIME)"
;;
"ev_close_before" | "ev_close_after")
ALIAS="$2"
TIME=$3
@@ -49,13 +68,40 @@ case "$EVENT" in
"check_rain_sensor_before" | "check_rain_sensor_after" | "check_rain_sensor_change")
STATE="$2"
TIME=$3
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nSTATE: $ALIAS\nTIME: $(/bin/date -d@$TIME)"
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nSTATE: $STATE\nTIME: $(/bin/date -d@$TIME)"
;;
"check_rain_online_before" | "check_rain_online_after" | "check_rain_online_change")
"check_rain_online_before")
STATE="$2"
TIME=$3
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nSTATE: $ALIAS\nTIME: $(/bin/date -d@$TIME)"
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nSTATE: $STATE\nTIME: $(/bin/date -d@$TIME)"
;;
"check_rain_online_after" | "check_rain_online_change")
STATE="$2"
WEATHER="$3"
TIME=$4
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nSTATE: $STATE\nWEATHER: $WEARTHER\nTIME: $(/bin/date -d@$TIME)"
;;
"cron_add_before" | "cron_add_after")
CRON_TYPE="$2"
CRON_ARG="$3"
CRON_ELEMENT="$4"
TIME=$5
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nCRON TYPE: $CRON_TYPE\nCRON ARG: $CRON_ARG\nCRON ELEMENT: $CRON_ELEMENT\nTIME: $(/bin/date -d@$TIME)"
;;
"cron_del_before" | "cron_del_after")
CRON_TYPE="$2"
CRON_ARG="$3"
TIME=$4
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nCRON TYPE: $CRON_TYPE\nCRON ARG: $CRON_ARG\nTIME: $(/bin/date -d@$TIME)"
;;
"exec_poweroff_before" | "exec_poweroff_after" | "exec_reboot_before" | "exec_reboot_after")
TIME=$2
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nTIME: $(/bin/date -d@$TIME)"
;;
*)

View File

@@ -39,10 +39,10 @@ function cron_del {
return 1
fi
trigger_event "cron_del_before" "$1" "$2"
$SED "$START,${END}d" "$TMP_CRON_FILE" | $SED '$!N; /^\(.*\)\n\1$/!P; D' | $CRONTAB -
#$CRONTAB "$TMP_CRON_FILE"
rm "$TMP_CRON_FILE"
trigger_event "cron_del_after" "$1" "$2"
}
@@ -206,8 +206,10 @@ function cron_add {
echo "$CRON_DISABLED$CRON_M $CRON_H $CRON_DOM $CRON_MON $CRON_DOW $CRON_COMMAND" >> "$TMP_CRON_FILE2"
echo "# END cron $CRON_TYPE $CRON_ARG" >> "$TMP_CRON_FILE2"
trigger_event "cron_add_before" "$CRON_TYPE" "$CRON_ARG" "$CRON_DISABLED$CRON_M $CRON_H $CRON_DOM $CRON_MON $CRON_DOW $CRON_COMMAND"
$CRONTAB "$TMP_CRON_FILE2"
rm "$TMP_CRON_FILE" "$TMP_CRON_FILE2"
trigger_event "cron_add_after" "$CRON_TYPE" "$CRON_ARG" "$CRON_DISABLED$CRON_M $CRON_H $CRON_DOM $CRON_MON $CRON_DOW $CRON_COMMAND"
}

View File

@@ -5,19 +5,6 @@
function trigger_event {
# check_rain_online_after
# check_rain_online_before
# check_rain_online_change
# check_rain_sensor_after
# check_rain_sensor_before
# check_rain_sensor_change
# ev_close_after
# ev_close_before
# ev_open_after
# ev_open_before
# init_after
# init_before
local EVENT="$1"
local CAUSE="$2"
local current_event_dir="$EVENT_DIR/$EVENT"
@@ -34,6 +21,22 @@ function trigger_event {
$f "$EVENT" "$ALIAS" "$FORCE" `date +%s` &> /dev/null
;;
"ev_open_in_before")
ALIAS="$2"
FORCE="$3"
local MINUTE_START="$4"
local MINUTE_STOP="$5"
$f "$EVENT" "$ALIAS" "$FORCE" "$MINUTE_START" "$MINUTE_STOP" `date +%s` &> /dev/null
;;
"ev_open_in_after")
ALIAS="$2"
FORCE="$3"
local CRON_START="$4"
local CRON_STOP="$5"
$f "$EVENT" "$ALIAS" "$FORCE" "$CRON_START" "$CRON_STOP" `date +%s` &> /dev/null
;;
"ev_close_before" | "ev_close_after")
ALIAS="$2"
$f "$EVENT" "$ALIAS" `date +%s` &> /dev/null
@@ -45,11 +48,40 @@ function trigger_event {
$f "$EVENT" "$STATE" `date +%s` &> /dev/null
;;
"check_rain_online_before" | "check_rain_online_after" | "check_rain_online_change")
"check_rain_online_before")
STATE="$2"
$f "$EVENT" "$STATE" `date +%s` &> /dev/null
;;
"check_rain_online_after" | "check_rain_online_change")
STATE="$2"
WEATHER="$3"
$f "$EVENT" "$STATE" "$WEATHER" `date +%s` &> /dev/null
;;
"init_before" | "init_after")
STATE="$2"
$f "$EVENT" `date +%s` &> /dev/null
;;
"cron_add_before" | "cron_add_after")
local CRON_TYPE="$2"
local CRON_ARG="$3"
local CRON_ELEMENT="$4"
$f "$EVENT" "$CRON_TYPE" "$CRON_ARG" "$CRON_ELEMENT" `date +%s` &> /dev/null
;;
"cron_del_before" | "cron_del_after")
local CRON_TYPE="$2"
local CRON_ARG="$3"
$f "$EVENT" "$CRON_TYPE" "$CRON_ARG" `date +%s` &> /dev/null
;;
"exec_poweroff_before" | "exec_poweroff_after" | "exec_reboot_before" | "exec_reboot_after" )
$f "$EVENT" `date +%s` &> /dev/null
;;
*)
$f "$EVENT" "$CAUSE" `date +%s` &> /dev/null
;;

View File

@@ -35,11 +35,11 @@ function check_rain_online {
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"
trigger_event "check_rain_online_change" "$current_state_rain_online" "$weather"
fi
fi
trigger_event "check_rain_online_after" "$current_state_rain_online"
trigger_event "check_rain_online_after" "$current_state_rain_online" "$weather"
}
#

View File

@@ -190,6 +190,9 @@ function ev_open_in {
message_write "warning" "Alias solenoid not specified"
return 1
fi
trigger_event "ev_open_in_before" "$3" "$4" "$1" "$2"
gpio_alias2number $alias > /dev/null 2>&1
minute_start=$(($minute_start + 1))
@@ -201,6 +204,7 @@ function ev_open_in {
if [ "$minute_start" -eq "1" ]; then
ev_open $alias $force
cron_start="- - - - -"
else
cron_add open_in $cron_start "$alias" "$force"
fi
@@ -210,6 +214,8 @@ function ev_open_in {
message_write "success" "Scheduled start successfully performed"
trigger_event "ev_open_in_after" "$3" "$4" "$cron_start" "$cron_stop"
#echo $cron_start
#echo $cron_stop
@@ -757,19 +763,22 @@ function send_identifier {
# Spenge il sistema
#
function exec_poweroff {
trigger_event "exec_poweroff_before"
local PATH_SCRIPT=`$READLINK -f "$DIR_SCRIPT/scripts/poweroff.sh"`
echo "$PATH_SCRIPT" > tmp/prova.txt
sleep 15
. $PATH_SCRIPT
trigger_event "exec_poweroff_after"
}
#
# Spenge il sistema
#
function exec_reboot {
trigger_event "exec_reboot_before"
local PATH_SCRIPT=`$READLINK -f "$DIR_SCRIPT/scripts/reboot.sh"`
sleep 15
. $PATH_SCRIPT
trigger_event "exec_reboot_after"
}
function debug1 {