Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22ec16cc9d | ||
|
|
8d4849db75 | ||
|
|
35665c74a7 | ||
|
|
80bcbbc92a | ||
|
|
67f2d6fe7f | ||
|
|
83e23d6bad | ||
|
|
daf8a7baa6 | ||
|
|
4a0d6178d3 | ||
|
|
3761c6cb94 | ||
|
|
e29dc9dfd4 | ||
|
|
6ccb8d3c19 | ||
|
|
b3dae26372 |
16
CHANGELOG.md
16
CHANGELOG.md
@@ -1,3 +1,19 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# 0.5.1 - 28/10/2017
|
||||||
|
- Added events managemets
|
||||||
|
- Added support for zones not subject to rainfall (with parameter EVx_NORAIN)
|
||||||
|
|
||||||
# 0.5.0 - 12/10/2017
|
# 0.5.0 - 12/10/2017
|
||||||
- Implemented driver subsystem for interfacing with other board
|
- Implemented driver subsystem for interfacing with other board
|
||||||
- Added driver spb16ch for interfacing with "Smart Power Board 16 channel with RTC"
|
- Added driver spb16ch for interfacing with "Smart Power Board 16 channel with RTC"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Bash script to manage an irrigation system built with a Raspberry Pi
|
|||||||
|
|
||||||
## Official documentation
|
## 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
|
## License
|
||||||
|
|
||||||
@@ -66,5 +66,3 @@ sudo cp piGarden/conf/piGarden.conf.example /etc/piGarden.conf
|
|||||||
Customize the configuration file.
|
Customize the configuration file.
|
||||||
For more information see
|
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/)
|
[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/)
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log"
|
|||||||
# Status directory
|
# Status directory
|
||||||
STATUS_DIR="/home/pi/piGarden/state"
|
STATUS_DIR="/home/pi/piGarden/state"
|
||||||
|
|
||||||
|
# Event directory
|
||||||
|
EVENT_DIR="/home/pi/piGarden/events"
|
||||||
|
|
||||||
# Posizione gpio
|
# Posizione gpio
|
||||||
GPIO="/usr/local/bin/gpio"
|
GPIO="/usr/local/bin/gpio"
|
||||||
|
|
||||||
@@ -86,6 +89,7 @@ EV_TOTAL=6
|
|||||||
# Definizione delle elettrovalvole
|
# Definizione delle elettrovalvole
|
||||||
EV1_ALIAS="1" #
|
EV1_ALIAS="1" #
|
||||||
EV1_GPIO=17 # Physical 11 - wPi 0
|
EV1_GPIO=17 # Physical 11 - wPi 0
|
||||||
|
#EV1_NORAIN=1 # Non interrompe l'irrigazione di questa zona in caso di pioggia
|
||||||
|
|
||||||
EV2_ALIAS="2" #
|
EV2_ALIAS="2" #
|
||||||
EV2_GPIO=27 # Physical 13 - wPi 2
|
EV2_GPIO=27 # Physical 13 - wPi 2
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ LOG_FILE_MAX_SIZE=1048576 # 1MB
|
|||||||
# Status directory
|
# Status directory
|
||||||
STATUS_DIR="/home/pi/piGarden/state"
|
STATUS_DIR="/home/pi/piGarden/state"
|
||||||
|
|
||||||
|
# Event directory
|
||||||
|
EVENT_DIR="/home/pi/piGarden/events"
|
||||||
|
|
||||||
# Posizione gpio
|
# Posizione gpio
|
||||||
GPIO="/usr/local/bin/gpio"
|
GPIO="/usr/local/bin/gpio"
|
||||||
|
|
||||||
@@ -85,6 +88,7 @@ EV_TOTAL=128
|
|||||||
# Definizione delle elettrovalvole
|
# Definizione delle elettrovalvole
|
||||||
EV1_ALIAS="Zona_1" #
|
EV1_ALIAS="Zona_1" #
|
||||||
EV1_GPIO="drv:spb16ch:1"
|
EV1_GPIO="drv:spb16ch:1"
|
||||||
|
#EV1_NORAIN=1 # Non interrompe l'irrigazione di questa zona in caso di pioggia
|
||||||
|
|
||||||
EV2_ALIAS="Zona_2" #
|
EV2_ALIAS="Zona_2" #
|
||||||
EV2_GPIO="drv:spb16ch:2"
|
EV2_GPIO="drv:spb16ch:2"
|
||||||
|
|||||||
4
events/check_rain_online_after/.gitignore
vendored
Normal file
4
events/check_rain_online_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/check_rain_online_before/.gitignore
vendored
Normal file
4
events/check_rain_online_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/check_rain_online_change/.gitignore
vendored
Normal file
4
events/check_rain_online_change/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/check_rain_sensor_after/.gitignore
vendored
Normal file
4
events/check_rain_sensor_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/check_rain_sensor_before/.gitignore
vendored
Normal file
4
events/check_rain_sensor_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/check_rain_sensor_change/.gitignore
vendored
Normal file
4
events/check_rain_sensor_change/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/cron_add_after/.gitignore
vendored
Normal file
4
events/cron_add_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/cron_add_before/.gitignore
vendored
Normal file
4
events/cron_add_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/cron_del_after/.gitignore
vendored
Normal file
4
events/cron_del_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/cron_del_before/.gitignore
vendored
Normal file
4
events/cron_del_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/ev_close_after/.gitignore
vendored
Normal file
4
events/ev_close_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/ev_close_before/.gitignore
vendored
Normal file
4
events/ev_close_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/ev_open_after/.gitignore
vendored
Normal file
4
events/ev_open_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/ev_open_before/.gitignore
vendored
Normal file
4
events/ev_open_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/ev_open_in_after/.gitignore
vendored
Normal file
4
events/ev_open_in_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/ev_open_in_before/.gitignore
vendored
Normal file
4
events/ev_open_in_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/exec_poweroff_after/.gitignore
vendored
Normal file
4
events/exec_poweroff_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/exec_poweroff_before/.gitignore
vendored
Normal file
4
events/exec_poweroff_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/exec_reboot_after/.gitignore
vendored
Normal file
4
events/exec_reboot_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/exec_reboot_before/.gitignore
vendored
Normal file
4
events/exec_reboot_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/init_after/.gitignore
vendored
Normal file
4
events/init_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/init_before/.gitignore
vendored
Normal file
4
events/init_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/scripts/.gitignore
vendored
Normal file
4
events/scripts/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*custom*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
114
events/scripts/sendmail.sh
Executable file
114
events/scripts/sendmail.sh
Executable file
@@ -0,0 +1,114 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Send mail on triggered event
|
||||||
|
#
|
||||||
|
# $1 = event
|
||||||
|
# $2 = cause
|
||||||
|
# $3 = time
|
||||||
|
#
|
||||||
|
# To send an email with this script you must install and configure ssmtp and mailutils:
|
||||||
|
# sudo apt-get install ssmtp mailutils
|
||||||
|
#
|
||||||
|
# edit the configuration file /etc/ssmtp/ssmtp.conf and insert the below lines:
|
||||||
|
#
|
||||||
|
# root=postmaster
|
||||||
|
# mailhub=smtp.gmail.com:587
|
||||||
|
# hostname=guard
|
||||||
|
# FromLineOverride=YES
|
||||||
|
# AuthUser=your_mail@gmail.com
|
||||||
|
# AuthPass=your_password
|
||||||
|
# UseSTARTTLS=YES
|
||||||
|
#
|
||||||
|
|
||||||
|
EVENT="$1"
|
||||||
|
|
||||||
|
TO="mail@destination.com"
|
||||||
|
FROM="piGarden@your_domain.com"
|
||||||
|
SUBJECT="[piGarden notification mail] event $EVENT"
|
||||||
|
BODY=""
|
||||||
|
|
||||||
|
case "$EVENT" in
|
||||||
|
"init_before" | "init_after")
|
||||||
|
TIME=$2
|
||||||
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nTIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"ev_open_before" | "ev_open_after")
|
||||||
|
ALIAS="$2"
|
||||||
|
FORCE="$3"
|
||||||
|
TIME=$4
|
||||||
|
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
|
||||||
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nZONE: $ALIAS\nTIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"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: $STATE\nTIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"check_rain_online_before")
|
||||||
|
STATE="$2"
|
||||||
|
TIME=$3
|
||||||
|
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)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo -e "$BODY" | /usr/bin/mail -s "$SUBJECT" $TO -r $FROM &
|
||||||
|
|
||||||
14
events/scripts/testevent.sh
Executable file
14
events/scripts/testevent.sh
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Send mail on triggered event
|
||||||
|
#
|
||||||
|
# $1 = event
|
||||||
|
EVENT="$1"
|
||||||
|
P2="$2"
|
||||||
|
P3="$3"
|
||||||
|
P4="$4"
|
||||||
|
P5="$5"
|
||||||
|
|
||||||
|
echo "$(date) $EVENT $P2 $P3 $P4 $P5" >> /tmp/piGarden.testevent
|
||||||
|
|
||||||
|
|
||||||
14
events/scripts/testeventbreak.sh
Executable file
14
events/scripts/testeventbreak.sh
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Send mail on triggered event
|
||||||
|
#
|
||||||
|
# $1 = event
|
||||||
|
EVENT="$1"
|
||||||
|
P2="$2"
|
||||||
|
P3="$3"
|
||||||
|
P4="$4"
|
||||||
|
P5="$5"
|
||||||
|
|
||||||
|
echo "testevent break $(date) $EVENT $P2 $P3 $P4 $P5" >> /tmp/piGarden.testevent
|
||||||
|
|
||||||
|
exit 1
|
||||||
@@ -39,10 +39,10 @@ function cron_del {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
trigger_event "cron_del_before" "$1" "$2"
|
||||||
$SED "$START,${END}d" "$TMP_CRON_FILE" | $SED '$!N; /^\(.*\)\n\1$/!P; D' | $CRONTAB -
|
$SED "$START,${END}d" "$TMP_CRON_FILE" | $SED '$!N; /^\(.*\)\n\1$/!P; D' | $CRONTAB -
|
||||||
#$CRONTAB "$TMP_CRON_FILE"
|
|
||||||
rm "$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 "$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"
|
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"
|
$CRONTAB "$TMP_CRON_FILE2"
|
||||||
rm "$TMP_CRON_FILE" "$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"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ function drv_rain_sensor_get {
|
|||||||
|
|
||||||
# Nessun driver definito, esegue la lettura del sensore tramite gpio del raspberry
|
# Nessun driver definito, esegue la lettura del sensore tramite gpio del raspberry
|
||||||
if [ -z "$fnc" ]; then
|
if [ -z "$fnc" ]; then
|
||||||
val=`$GPIO -g read $idx`
|
vret=`$GPIO -g read $idx`
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc" == "drvnotfound" ]; then
|
elif [ "$fnc" == "drvnotfound" ]; then
|
||||||
log_write "Driver not found: $idx"
|
log_write "Driver not found: $idx"
|
||||||
|
|||||||
103
include/events.include.sh
Normal file
103
include/events.include.sh
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
#
|
||||||
|
# Triggered an event and executge associated scripts
|
||||||
|
# $1 event
|
||||||
|
#
|
||||||
|
|
||||||
|
function trigger_event {
|
||||||
|
|
||||||
|
local EVENT="$1"
|
||||||
|
local CAUSE="$2"
|
||||||
|
local current_event_dir="$EVENT_DIR/$EVENT"
|
||||||
|
|
||||||
|
if [ -d "$current_event_dir" ]; then
|
||||||
|
local FILES="$current_event_dir/*"
|
||||||
|
for f in $FILES
|
||||||
|
do
|
||||||
|
if [ -x "$f" ]; then
|
||||||
|
case "$EVENT" in
|
||||||
|
"ev_open_before" | "ev_open_after")
|
||||||
|
ALIAS="$2"
|
||||||
|
FORCE="$3"
|
||||||
|
$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
|
||||||
|
;;
|
||||||
|
|
||||||
|
|
||||||
|
"check_rain_sensor_before" | "check_rain_sensor_after" | "check_rain_sensor_change")
|
||||||
|
STATE="$2"
|
||||||
|
$f "$EVENT" "$STATE" `date +%s` &> /dev/null
|
||||||
|
;;
|
||||||
|
|
||||||
|
"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
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
local ec=$?
|
||||||
|
#echo "$EVENT ec=$ec" >> /tmp/piGarden.testevent
|
||||||
|
if [ $ec -ne 0 ]; then
|
||||||
|
log_write "Stop events chain for exit code $ec in $current_event_dir/$f"
|
||||||
|
return $ec
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2,11 +2,16 @@
|
|||||||
# Controlla se se piove tramite http://api.wunderground.com/
|
# Controlla se se piove tramite http://api.wunderground.com/
|
||||||
#
|
#
|
||||||
function check_rain_online {
|
function check_rain_online {
|
||||||
|
|
||||||
|
trigger_event "check_rain_online_before" ""
|
||||||
|
|
||||||
# http://www.wunderground.com/weather/api/d/docs?d=resources/phrase-glossary&MR=1
|
# 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
|
$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 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 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 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
|
#echo $weather
|
||||||
#weather="[Light/Heavy] Drizzle"
|
#weather="[Light/Heavy] Drizzle"
|
||||||
if [ "$weather" = "null" ]; then
|
if [ "$weather" = "null" ]; then
|
||||||
@@ -22,12 +27,19 @@ function check_rain_online {
|
|||||||
[[ "$weather" == *"Thunderstorm"* ]] ||
|
[[ "$weather" == *"Thunderstorm"* ]] ||
|
||||||
[[ "$weather" == *"Drizzle"* ]];
|
[[ "$weather" == *"Drizzle"* ]];
|
||||||
then
|
then
|
||||||
#echo "ECCOMI!!!!!"
|
current_state_rain_online='rain'
|
||||||
echo $local_epoch > "$STATUS_DIR/last_rain_online"
|
echo $local_epoch > "$STATUS_DIR/last_rain_online"
|
||||||
#return $local_epoch
|
else
|
||||||
|
current_state_rain_online='norain'
|
||||||
fi
|
fi
|
||||||
echo "$current_observation" > "$STATUS_DIR/last_weather_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" "$weather"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
trigger_event "check_rain_online_after" "$current_state_rain_online" "$weather"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -36,16 +48,25 @@ function check_rain_online {
|
|||||||
function check_rain_sensor {
|
function check_rain_sensor {
|
||||||
|
|
||||||
if [ -n "$RAIN_GPIO" ]; then
|
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`
|
local s=`drv_rain_sensor_get $RAIN_GPIO`
|
||||||
if [ "$s" = "$RAIN_GPIO_STATE" ]; then
|
if [ "$s" = "$RAIN_GPIO_STATE" ]; then
|
||||||
|
current_state_rain_sensor='rain'
|
||||||
local local_epoch=`date +%s`
|
local local_epoch=`date +%s`
|
||||||
echo $local_epoch > "$STATUS_DIR/last_rain_sensor"
|
echo $local_epoch > "$STATUS_DIR/last_rain_sensor"
|
||||||
log_write "check_rain_sensor - now it's raining ($local_epoch)"
|
log_write "check_rain_sensor - now it's raining ($local_epoch)"
|
||||||
return $local_epoch
|
#return $local_epoch
|
||||||
else
|
else
|
||||||
|
current_state_rain_sensor='norain'
|
||||||
log_write "check_rain_sensor - now is not raining"
|
log_write "check_rain_sensor - now is not raining"
|
||||||
fi
|
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
|
else
|
||||||
log_write "Rain sensor not present"
|
log_write "Rain sensor not present"
|
||||||
fi
|
fi
|
||||||
@@ -84,10 +105,12 @@ function close_all_for_rain {
|
|||||||
do
|
do
|
||||||
local a=EV"$i"_ALIAS
|
local a=EV"$i"_ALIAS
|
||||||
local al=${!a}
|
local al=${!a}
|
||||||
|
local a=EV"$i"_NORAIN
|
||||||
|
local evnorain=${!a}
|
||||||
ev_status $al
|
ev_status $al
|
||||||
local state=$?
|
local state=$?
|
||||||
#echo "$al = $state"
|
#echo "$al = $state"
|
||||||
if [ "$state" = "1" ]; then
|
if [ "$state" = "1" ] && [ "$evnorain" != "1" ]; then
|
||||||
ev_close $al
|
ev_close $al
|
||||||
log_write "close_all_for_rain - Close solenoid '$al' for rain"
|
log_write "close_all_for_rain - Close solenoid '$al' for rain"
|
||||||
fi
|
fi
|
||||||
|
|||||||
67
piGarden.sh
67
piGarden.sh
@@ -14,6 +14,8 @@ function initialize {
|
|||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
|
trigger_event "init_before" ""
|
||||||
|
|
||||||
# Inizializza i driver gpio
|
# Inizializza i driver gpio
|
||||||
for drv in "${list_drv[@]}"
|
for drv in "${list_drv[@]}"
|
||||||
do
|
do
|
||||||
@@ -60,6 +62,7 @@ function initialize {
|
|||||||
log_write "Rain sensor not present"
|
log_write "Rain sensor not present"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
trigger_event "init_after" ""
|
||||||
log_write "End initialize"
|
log_write "End initialize"
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -82,7 +85,13 @@ function ev_open {
|
|||||||
|
|
||||||
cron_del open_in $1 > /dev/null 2>&1
|
cron_del open_in $1 > /dev/null 2>&1
|
||||||
|
|
||||||
if [ ! "$2" = "force" ]; then
|
# Dall'alias dell'elettrovalvola recupero il numero e dal numero recupero gpio da usare
|
||||||
|
ev_alias2number $1
|
||||||
|
local EVNUM=$?
|
||||||
|
local g=`ev_number2gpio $EVNUM`
|
||||||
|
local EVNORAIN=`ev_number2norain $EVNUM`
|
||||||
|
|
||||||
|
if [ ! "$2" = "force" ] && [ "$EVNORAIN" != "1" ]; then
|
||||||
if [[ "$NOT_IRRIGATE_IF_RAIN_ONLINE" -gt 0 && -f $STATUS_DIR/last_rain_online ]]; then
|
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 last_rain=`cat $STATUS_DIR/last_rain_online`
|
||||||
local now=`date +%s`
|
local now=`date +%s`
|
||||||
@@ -114,10 +123,12 @@ function ev_open {
|
|||||||
state=2
|
state=2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Dall'alias dell'elettrovalvola recupero il numero e dal numero recupero gpio da usare
|
trigger_event "ev_open_before" "$1" "$2"
|
||||||
ev_alias2number $1
|
if [ $? -ne 0 ]; then
|
||||||
EVNUM=$?
|
log_write "Solenoid '$1' not open due to external event"
|
||||||
g=`ev_number2gpio $EVNUM`
|
message_write 'warning' "Solenoid not open due to external event"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
lock
|
lock
|
||||||
|
|
||||||
@@ -136,6 +147,8 @@ function ev_open {
|
|||||||
|
|
||||||
ev_set_state $EVNUM $state
|
ev_set_state $EVNUM $state
|
||||||
|
|
||||||
|
trigger_event "ev_open_after" "$1" "$2"
|
||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
log_write "Solenoid '$1' open"
|
log_write "Solenoid '$1' open"
|
||||||
@@ -177,6 +190,9 @@ function ev_open_in {
|
|||||||
message_write "warning" "Alias solenoid not specified"
|
message_write "warning" "Alias solenoid not specified"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
trigger_event "ev_open_in_before" "$3" "$4" "$1" "$2"
|
||||||
|
|
||||||
gpio_alias2number $alias > /dev/null 2>&1
|
gpio_alias2number $alias > /dev/null 2>&1
|
||||||
|
|
||||||
minute_start=$(($minute_start + 1))
|
minute_start=$(($minute_start + 1))
|
||||||
@@ -188,6 +204,7 @@ function ev_open_in {
|
|||||||
|
|
||||||
if [ "$minute_start" -eq "1" ]; then
|
if [ "$minute_start" -eq "1" ]; then
|
||||||
ev_open $alias $force
|
ev_open $alias $force
|
||||||
|
cron_start="- - - - -"
|
||||||
else
|
else
|
||||||
cron_add open_in $cron_start "$alias" "$force"
|
cron_add open_in $cron_start "$alias" "$force"
|
||||||
fi
|
fi
|
||||||
@@ -197,6 +214,8 @@ function ev_open_in {
|
|||||||
|
|
||||||
message_write "success" "Scheduled start successfully performed"
|
message_write "success" "Scheduled start successfully performed"
|
||||||
|
|
||||||
|
trigger_event "ev_open_in_after" "$3" "$4" "$cron_start" "$cron_stop"
|
||||||
|
|
||||||
#echo $cron_start
|
#echo $cron_start
|
||||||
#echo $cron_stop
|
#echo $cron_stop
|
||||||
|
|
||||||
@@ -214,6 +233,8 @@ function ev_close {
|
|||||||
EVNUM=$?
|
EVNUM=$?
|
||||||
g=`ev_number2gpio $EVNUM`
|
g=`ev_number2gpio $EVNUM`
|
||||||
|
|
||||||
|
trigger_event "ev_close_before" "$1"
|
||||||
|
|
||||||
lock
|
lock
|
||||||
|
|
||||||
# Gestisce l'apertura dell'elettrovalvola in base alla tipologia (monostabile / bistabile)
|
# Gestisce l'apertura dell'elettrovalvola in base alla tipologia (monostabile / bistabile)
|
||||||
@@ -231,6 +252,8 @@ function ev_close {
|
|||||||
|
|
||||||
ev_set_state $EVNUM 0
|
ev_set_state $EVNUM 0
|
||||||
|
|
||||||
|
trigger_event "ev_close_after" "$1"
|
||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
log_write "Solenoid '$1' close"
|
log_write "Solenoid '$1' close"
|
||||||
@@ -372,11 +395,20 @@ function alias_exists {
|
|||||||
# $1 numero elettrovalvola
|
# $1 numero elettrovalvola
|
||||||
#
|
#
|
||||||
function ev_number2gpio {
|
function ev_number2gpio {
|
||||||
# echo "numero ev $1"
|
local i=$1
|
||||||
i=$1
|
local g=EV"$i"_GPIO
|
||||||
g=EV"$i"_GPIO
|
local gv=${!g}
|
||||||
gv=${!g}
|
echo "$gv"
|
||||||
# echo "gv = $gv"
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Recupera il valore norain associato ad una elettrovalvola
|
||||||
|
# $1 numero elettrovalvola
|
||||||
|
#
|
||||||
|
function ev_number2norain {
|
||||||
|
local i=$1
|
||||||
|
local g=EV"$i"_NORAIN
|
||||||
|
local gv=${!g}
|
||||||
echo "$gv"
|
echo "$gv"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -731,19 +763,22 @@ function send_identifier {
|
|||||||
# Spenge il sistema
|
# Spenge il sistema
|
||||||
#
|
#
|
||||||
function exec_poweroff {
|
function exec_poweroff {
|
||||||
|
trigger_event "exec_poweroff_before"
|
||||||
local PATH_SCRIPT=`$READLINK -f "$DIR_SCRIPT/scripts/poweroff.sh"`
|
local PATH_SCRIPT=`$READLINK -f "$DIR_SCRIPT/scripts/poweroff.sh"`
|
||||||
echo "$PATH_SCRIPT" > tmp/prova.txt
|
|
||||||
sleep 15
|
sleep 15
|
||||||
. $PATH_SCRIPT
|
. $PATH_SCRIPT
|
||||||
|
trigger_event "exec_poweroff_after"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Spenge il sistema
|
# Spenge il sistema
|
||||||
#
|
#
|
||||||
function exec_reboot {
|
function exec_reboot {
|
||||||
|
trigger_event "exec_reboot_before"
|
||||||
local PATH_SCRIPT=`$READLINK -f "$DIR_SCRIPT/scripts/reboot.sh"`
|
local PATH_SCRIPT=`$READLINK -f "$DIR_SCRIPT/scripts/reboot.sh"`
|
||||||
sleep 15
|
sleep 15
|
||||||
. $PATH_SCRIPT
|
. $PATH_SCRIPT
|
||||||
|
trigger_event "exec_reboot_after"
|
||||||
}
|
}
|
||||||
|
|
||||||
function debug1 {
|
function debug1 {
|
||||||
@@ -756,7 +791,7 @@ function debug2 {
|
|||||||
|
|
||||||
VERSION=0
|
VERSION=0
|
||||||
SUB_VERSION=5
|
SUB_VERSION=5
|
||||||
RELEASE_VERSION=0
|
RELEASE_VERSION=3
|
||||||
|
|
||||||
DIR_SCRIPT=`dirname $0`
|
DIR_SCRIPT=`dirname $0`
|
||||||
NAME_SCRIPT=${0##*/}
|
NAME_SCRIPT=${0##*/}
|
||||||
@@ -782,15 +817,21 @@ fi
|
|||||||
. "$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"
|
. "$DIR_SCRIPT/include/rain.include.sh"
|
||||||
|
. "$DIR_SCRIPT/include/events.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_warning"
|
||||||
LAST_SUCCESS_FILE="$STATUS_DIR/last_success"
|
LAST_SUCCESS_FILE="$STATUS_DIR/last_success"
|
||||||
|
|
||||||
if [ -z $LOG_OUTPUT_DRV_FILE ]; then
|
if [ -z $LOG_OUTPUT_DRV_FILE ]; then
|
||||||
$LOG_OUTPUT_DRV_FILE="/dev/null"
|
$LOG_OUTPUT_DRV_FILE="/dev/null"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "$EVENT_DIR" ]; then
|
||||||
|
EVENT_DIR="$DIR_SCRIPT/events"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Elimina il file di lock se più vecchio di 11 secondi
|
# Elimina il file di lock se più vecchio di 11 secondi
|
||||||
if [ -f "$LOCK_FILE" ]; then
|
if [ -f "$LOCK_FILE" ]; then
|
||||||
max_age_lock_file=11
|
max_age_lock_file=11
|
||||||
|
|||||||
Reference in New Issue
Block a user