18 Commits

Author SHA1 Message Date
lejubila
bdab0fb6fe Fix changelog 2020-05-16 18:14:21 +02:00
lejubila
6ed0510c7f Published version 0.6.0: - Add support for enable all cron fron api
- Update rainsensorqty driver to version 0.2.5b
2020-05-16 18:11:51 +02:00
lejubila
15e36e95a3 Update rainsensorqty to version 0.2.5 2020-04-08 22:17:14 +02:00
lejubila
3a5c3ef934 Add support for enable all cron fron api 2020-04-07 23:20:41 +02:00
lejubila
f3c11a7fee Corretto repositori git da cui scaricare wiringPi 2020-04-01 12:45:58 +02:00
lejubila
ac95194b3e Rimosso file con riferimento alla vecchia versione di rainsensorqty 2019-09-24 18:47:39 +02:00
lejubila
a125ff31d8 Aggiornato changelog alla version 0.5.14 2019-09-24 17:12:25 +02:00
lejubila
bb435f0ee6 Merge branch 'rainsensorqty' into develop
Eseguito merge del brench rainsensorqty nel brench develop
2019-09-24 17:06:25 +02:00
lejubila
b8daa7acab Cambiato numero di versione 2019-09-24 17:05:50 +02:00
lejubila
dd289f8b31 Adattato alla versione 0.3.3 i nomi zone presente nelle schedulazione mostrate nello stato in formato json 2019-09-24 16:58:23 +02:00
androtto
2add0c725f versione 0.2.3 2019-09-21 23:00:50 +02:00
androtto
0b34b7010f version 0.2.1 2019-09-02 14:42:29 +02:00
lejubila
c527702c72 Aggiunto elenco elettrovalvole con relativi alias nello status json 2019-09-01 22:22:42 +02:00
lejubila
b6de96debe Aggiunto api per gestire le schedulazioni di piGardenSched 2019-08-29 19:00:42 +02:00
lejubila
ea681816fe Aggiunto nello status json la lettura delle schedulazioni gestite con piGardenSched 2019-08-25 17:25:12 +02:00
lejubila
8ca698d4ee rimosso alcune linee commentate 2019-08-24 10:04:46 +02:00
lejubila
70943c5f5e Rimosso alcune linee commentate 2019-08-24 09:59:18 +02:00
lejubila
aa9799cdaf Rimosso alcune linee commentate 2019-08-24 09:52:46 +02:00
26 changed files with 755 additions and 143 deletions

View File

@@ -1,3 +1,11 @@
# 0.6.0 - 16/05/2020
- Add support for enable all cron fron api
- Update rainsensorqty driver to version 0.2.5b
# 0.5.14 - 24/09/2019
- Updated rainsensorqty driver to version 0.2.3
- Added api and command for manage piGardenSched scheduling
# 0.5.13 - 12/08/2019
- Added driver rainsensorqty for menage rainfall detection based on quantity

View File

@@ -41,8 +41,8 @@ sudo make install
``` bash
cd
git clone git://git.drogon.net/wiringPi
cd wiringPi
git clone https://github.com/WiringPi/WiringPi.git
cd WiringPi
git pull origin
./build
```

View File

@@ -57,6 +57,9 @@ STAT="/usr/bin/stat"
# # Installare con apt install mosquitto-clients
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
# Percorso di piGardenSched, se non definito non verranno gestire le schedulazioni di piGardenSched tramite api
#PIGARDENSCHED_PATH="/home/pi/piGardenSched/piGardenSched.sh"
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
# se impostato a 0 il sistema gestirà elettrovalvole bistabili

View File

@@ -57,6 +57,9 @@ STAT="/usr/bin/stat"
# # Installare con apt install mosquitto-clients
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
# Percorso di piGardenSched, se non definito non verranno gestire le schedulazioni di piGardenSched tramite api
#PIGARDENSCHED_PATH="/home/pi/piGardenSched/piGardenSched.sh"
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
# se impostato a 0 il sistema gestirà elettrovalvole bistabili

View File

@@ -57,6 +57,9 @@ STAT="/usr/bin/stat"
# Installare con apt install mosquitto-clients
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
# Percorso di piGardenSched, se non definito non verranno gestire le schedulazioni di piGardenSched tramite api
#PIGARDENSCHED_PATH="/home/pi/piGardenSched/piGardenSched.sh"
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili

View File

@@ -57,6 +57,9 @@ STAT="/usr/bin/stat"
# # Installare con apt install mosquitto-clients
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
# Percorso di piGardenSched, se non definito non verranno gestire le schedulazioni di piGardenSched tramite api
#PIGARDENSCHED_PATH="/home/pi/piGardenSched/piGardenSched.sh"
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili

View File

@@ -57,6 +57,9 @@ STAT="/usr/bin/stat"
# Installare con apt install mosquitto-clients
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
# Percorso di piGardenSched, se non definito non verranno gestire le schedulazioni di piGardenSched tramite api
#PIGARDENSCHED_PATH="/home/pi/piGardenSched/piGardenSched.sh"
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili

View File

@@ -2,24 +2,24 @@
# Driver rainsensorqty - driver for measure the rain volume
# Author: androtto
# file README.md
# Version: 0.2.0
# Data: 11/Aug/2019
# Version: 0.2.5
# Data: 07/Apr/2020
FILE DI CONFIGURAZIONE /etc/piGarden.conf:
-----------------------------------------
NOTA: vedere nella directory conf_example il file esempio piu' aggiornato!
per attivare il driver è necessario inserire la seguente variabile nel file di configurazion
per attivare il driver e' necessario inserire la seguente variabile nel file di configurazion
RAIN_GPIO="drv:rainsensorqty:25" # Physical 22 - wPi 6
la variabile seguente è impiegata anche da drvrainsensorqty per rilevare la chiusura del contatto magnetico che, in un circuito pull-up, è lo stato 1.
la variabile seguente e' impiegata anche da drv_rainsensorqty per rilevare la chiusura del contatto magnetico che, in un circuito pull-up, e' lo stato 1.
# Valore in ingresso sul gpio definito in RAIN_GPIO che indica lo stato di pioggia
RAIN_GPIO_STATE=1
le seguenti variabili controllano il driver come descritto:
RAINSENSORQTY_LOOPSFORSETRAINING=16 # dopo 10 impulsi, 10 vaschette riempite si considera pioggia
RAINSENSORQTY_SECSBETWEENRAINEVENT=10800 # =3h, significa che dopo 3 si resetta il numero di vaschette da riempire e solo dopo il riempimento del numero di vaschette si considera una nuova pioggia
infine la variabile seguente è la quantita' di acqua espressa in mm di precipitazioni:
RAINSENSORQTY_LOOPSFORSETRAINING=16 # dopo 16 impulsi, 16 vaschette riempite si considera pioggia
RAINSENSORQTY_SECSBETWEENRAINEVENT=10800 # =3h, significa che dopo 3 si resetta il numero di vaschette da riempire e solo dopo il riempimento del nuovo numero di vaschette si considera una nuova pioggia
infine la variabile seguente e' la quantita' di acqua espressa in mm di precipitazioni:
RAINSENSORQTY_MMEACH=0.33 # see RAINSENSORQTY driver readme for details
CALIBRAZIONE SENSORE PIOGGIA
@@ -27,31 +27,55 @@ CALIBRAZIONE SENSORE PIOGGIA
secondo il seguente processo da me effettuato sul mio misuratore di pioggia:
Ho erogato 18 ml di acqua nel rain gauge che hanno prodotto 10 impulsi; pertanto il riempimento di 1.8 ml ha causato un impulso, 1 ml = 1000 mmc (mm cubici),
1.8 ml sono pari a 1800 mmc
la superficie della vaschetta in mmq è pari a 110 mm x 55 mm = 5500 mmq
la superficie della vaschetta in mmq e' pari a 110 mm x 55 mm = 5500 mmq
volume / superficie mi da' l'altezza, quindi 1800 mmc / 5500 mmq = 0.32727273 mm
se fossero stati 1.7 ml di acqua per ogni impulso/vaschetta riempita, la varibile sarebbe stata impostata a 0.30909091 mm
se fossero stati 1.7 ml di acqua per ogni impulso/vaschetta riempita, la variabile sarebbe stata impostata a 0.30909091 mm
COMANDI SPECIALI
----------------
nella sottidirectory command sono prensenti:
nella sottodirectory command sono presenti:
commands/rainsensorqty_CHECK.sh
chiama la funzione di verifica piggio, la medesima chiamata da check_rain_sensor
chiama la funzione di verifica pioggia, la medesima chiamata da check_rain_sensor
commands/rainsensorqty_HISTORY.sh
visualizza lo storico della pioggia
visualizza lo storico della pioggia consultando il file $RAINSENSORQTY_HISTORY
puo' essere lanciato con l''opzione -force per ricostruire il file $RAINSENSORQTY_HISTORY dal $RAINSENSORQTY_HISTORYRAW
e con un argomento X, che permette di evidenziare solo gli ultimi X eventi
commands/rainsensorqty_HISTORYRAW.sh
visualizza lo storico della pioggia consultando il file $RAINSENSORQTY_HISTORYRAW
puo' essere lanciato senza argomenti per processare l'intero file, chiede conferma visto che i tempi sono potenzialmente lunghi
con un argomento X, che permette di evidenziare solo gli ultimi X eventi
commands/rainsensorqty_INIT.sh
inizializza il driver eseguendo lo script di monitoring - normalmente tale processo avviene da piGarden.sh
utile quando si vuole testare dei cambiamenti o se necessario riavviare dopo il kill del comando successivo
commands/rainsensorqty_KILL.sh
killa i processi di monitoring ed eventuali figli
commands/rainsensorqty_RAINNOW.sh
simula una pioggia
simula una pioggia registrandola in $RAINSENSORQTY_LASTRAIN $RAINSENSORQTY_HISTORY $RAINSENSORQTY_HISTORYRAW
puo' essere lanciato in 3 modi:
senza argomenti: genera una pioggia per un numero di loop pari al valore della variabile RAINSENSORQTY_LOOPSFORSETRAINING, quindi una pioggia completa
con un argomento: che indica quanti loop
con due argomenti: quanti loop e quanti secondi tra uno e l'altro
commands/rainsensorqty_REMOVELASTRAIN.sh
rimuove dai file $RAINSENSORQTY_LASTRAIN $RAINSENSORQTY_HISTORY $RAINSENSORQTY_HISTORYRAW l'ultima pioggia registrata
commands/rainsensorqty_RESET.sh
invia il SIGUSR1 al processo di monitor per resettare i cicli. Viene visualizzato il reset solo dopo il successivo PULSE, questo perche' non e' possibile per lo script ricevere il trap in quanto il processo $GPIO e' attivo in attesa del PULSE
questi i timestamps alla data del file:
-rwxr-xr-x 1 pi pi 1044 Sep 24 18:26 rainsensorqty_CHECK.sh
-rwxr-xr-x 1 pi pi 1139 Nov 28 00:17 rainsensorqty_HISTORYRAW.sh
-rwxr-xr-x 1 pi pi 1462 Nov 19 00:19 rainsensorqty_HISTORY.sh
-rwxr-xr-x 1 pi pi 596 Sep 24 18:26 rainsensorqty_INIT.sh
-rwxr-xr-x 1 pi pi 1300 Sep 24 18:26 rainsensorqty_KILL.sh
-rwxr-xr-x 1 pi pi 1111 Nov 27 00:05 rainsensorqty_RAINNOW.sh
-rwxr-xr-x 1 pi pi 1252 Nov 22 00:18 rainsensorqty_REMOVELASTRAIN.sh
-rwxr-xr-x 1 pi pi 897 Sep 24 18:26 rainsensorqty_RESET.sh
ULTERIORI VARIABILI in config.include.sh
----------------------------------------
esistono ulteriori variabili che potrebbe essere necessario variare
RAINSENSOR_ANTIBOUNCE=0.3 # 0.3 seconds for manage antibounce of reed contact
server per ritardare la lettura di un secondo impulso falso causato dal rimbalzo del contatto magnetico
RAINSENSOR_DEBOUNCE=0.3 # 0.3 seconds for manage debounce of reed contact
serve per ritardare la lettura di un secondo impulso falso causato dal rimbalzo del contatto magnetico
RAINSENSORQTY_verbose="yes"
aumenta il livello di verbosita' nei file di log
@@ -59,12 +83,14 @@ RAINSENSORQTY_verbose="yes"
RAINSENSORQTY_LASTRAIN="$STATUS_DIR/rainsensorqty_lastrain"
memorizza l'ultima pioggia
RAINSENSORQTY_HISTORY="$STATUS_DIR/rainsensorqty_history"
memorizza tutte le piogge permettendo di visualizzarlo storico (commands/rainsensorqty_HISTORY.sh)
memorizza tutte le piogge permettendo di visualizzare lo storico (commands/rainsensorqty_HISTORY.sh)
RAINSENSORQTY_HISTORYRAW="$STATUS_DIR/rainsensorqty_history.raw"
memorizza in formato grezzo (raw) tutti gli impulsi registrati (formato: "secondi:impulsi" ) - consultabile il contenuto con commands/rainsensorqty_HISTORYRAW.sh
RAINSENSORQTY_MONITORLOG="$DIR_SCRIPT/log/rainsensorqty_monitor.log"
log del script di monitoring, popolato solo se RAINSENSORQTY_verbose="yes"
log dello script di monitoring, popolato solo se RAINSENSORQTY_verbose="yes"
RAINSENSORQTY_MONPID="$TMP_PATH/rainsensorqty_monitor.pid"
RAINSENSORQTY_MONPID="$TMPDIR/rainsensorqty_monitor.pid"
file che viene popolato con il pid dello script di monitoring
RAINSENSORQTY_DIR="$DIR_SCRIPT/drv/rainsensorqty"
@@ -72,27 +98,27 @@ RAINSENSORQTY_DIR="$DIR_SCRIPT/drv/rainsensorqty"
monitor_sh="$RAINSENSORQTY_DIR/drv_rainsensorqty_monitor.sh"
script di monitoring
lo script eredita le varibili di ambiente da .set_var in $RAINSENSORQTY_DIR
lo script eredita le variabili di ambiente da $RAINSENSORQTY_VAR ($TMPDIR/.rainsensorqty_var)
NOTA: $TMPDIR e' /tmp e lo script visualizza un warning se non e' un tmpfs
# internal gpio resistor, 3 values: pull-up, pull-down, none
# pull-up/down if rain gauge is connected directly to raspberry
# none if connected through an optocoupler circuit
GPIO_RESISTOR="none" #pull-up|pull-down|none
enable pull-up or pull-down resistor: https://raspberry-projects.com/pi/pi-hardware/raspberry-pi-model-b-plus/model-b-plus-io-pins
Pull-up is 50K min - 65K max.
Pull-down is 50K min - 60K max.
#rising means waiting for 1 status (from 0)
#falling means waiting for 0 status (from 1)
#RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
#RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
if (( RAIN_GPIO_STATE = 1 )) ; then
RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
fi
if (( RAIN_GPIO_STATE = 0 )) ; then
RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
fi
if [[ -z $RAINSENSORQTY_PULSE ]] ; then
echo "ERROR: RAIN_GPIO_STATE non set in piGarden.conf"
exit 1
fi
(( RAIN_GPIO_STATE == 1 )) && RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
(( RAIN_GPIO_STATE == 0 )) && RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
lo script di monitoring ascolta il cambiamento di stato da quello di riposo allo stato di impulso (chiusura del contatto reed).
dipendentemente dal circuto implementato, se lo stato di riposo e' 0, lo script attende la variazione verso 1 (rising)
se lo stato di riposo e' 1, lo script attende la variazione verso 0 (falling)
la variabile RAINSENSORQTY_PULSE viene impostata secondo il valore di RAIN_GPIO_STATE presente in /etc/piGarden.conf
cioe' il valore che ci si aspetta per registrare lo stato di pioggia
cioe' il valore che ci si aspetta per registrare il riempimento della vaschetta dello stato di pioggia

View File

View File

@@ -2,7 +2,7 @@
#
# Driver rainsensorqty - driver for measure the rain volume
# Author: androtto
# file "test_rainsensorqty_CHECK.sh"
# file "rainsensorqty_CHECK.sh"
# test script for checking rain status using drv_rainsensorqty_rain_sensor_get function
# Version: 0.2.0
# Data: 11/Aug/2019
@@ -13,11 +13,6 @@ cd $SCRIPTDIR/.. # command is a subdirectory of driver
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
CONFIG_ETC="/etc/piGarden.conf"
TMP_PATH="/run/shm"
if [ ! -d "$TMP_PATH" ]; then
TMP_PATH="/tmp"
fi
LOG_OUTPUT_DRV_FILE="$DIR_SCRIPT/log/$LOG_OUTPUT_DRV_FILE"
. $CONFIG_ETC

View File

@@ -2,10 +2,10 @@
#
# Driver rainsensorqty - driver for measure the rain volume
# Author: androtto
# file "test_rainsensorqty_CHECK.sh"
# file "rainsensorqty_CHECK.sh"
# test script for checking rain status using drv_rainsensorqty_rain_sensor_get function
# Version: 0.2.0
# Data: 11/Aug/2019
# Version: 0.2.5
# Data: 08/Jan/2020
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
SCRIPTNAME=${0##*/}
@@ -13,11 +13,6 @@ cd $SCRIPTDIR/.. # command is a subdirectory of driver
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
CONFIG_ETC="/etc/piGarden.conf"
TMP_PATH="/run/shm"
if [ ! -d "$TMP_PATH" ]; then
TMP_PATH="/tmp"
fi
LOG_OUTPUT_DRV_FILE="$DIR_SCRIPT/log/$LOG_OUTPUT_DRV_FILE"
. $CONFIG_ETC
@@ -27,14 +22,38 @@ LOG_OUTPUT_DRV_FILE="$DIR_SCRIPT/log/$LOG_OUTPUT_DRV_FILE"
. ./init.include.sh
. ./rainsensor.include.sh
echo "RAIN HISTORY"
rain_history
if [[ $1 = "-force" ]] ; then
if [[ -s $RAINSENSORQTY_HISTORY ]] ; then
echo backup $RAINSENSORQTY_HISTORY to ${RAINSENSORQTY_HISTORY}.old$$
cp $RAINSENSORQTY_HISTORY ${RAINSENSORQTY_HISTORY}.old$$
fi
cat $RAINSENSORQTY_HISTORY | while read line
do
set -- ${line//:/ }
when=$1
howmuch=$2
printf "RAINED on %s for %.2f mm\n" "$(date --date="@$1")" $( $JQ -n "$howmuch * $RAINSENSORQTY_MMEACH" )
done
echo "generate all rain events to $RAINSENSORQTY_HISTORY"
if ! rainevents > ${RAINSENSORQTY_HISTORY} ; then
echo "WARNING: rainevents function had error"
fi
shift
fi
if ! rain_history tmp ; then # update rain history with last rain if not
echo "WARNING: rain_history function had error"
fi
cmd="cat"
if [[ $# > 0 ]] ; then
if (( $1 >= 1 )) ; then
echo "processing last $1 lines of $RAINSENSORQTY_HISTORYRAW file"
cmd="tail -$1"
else
echo "argument not recognized - exit"
exit 1
fi
fi
echo -e "\n\n"
if [[ -s $RAINSENSORQTY_HISTORY ]] ; then
echo "RAIN HISTORY"
cat $RAINSENSORQTY_HISTORY $RAINSENSORQTY_HISTORYTMP | $cmd | rain_when_amount
else
echo "WARNING: no \$RAINSENSORQTY_HISTORY file"
fi

View File

@@ -0,0 +1,50 @@
#!/bin/bash
#
# Driver rainsensorqty - driver for measure the rain volume
# Author: androtto
# file "rainsensorqty_CHECK.sh"
# test script for checking rain status using drv_rainsensorqty_rain_sensor_get function
# Version: 0.2.5
# Data: 07/Apr/2020
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
SCRIPTNAME=${0##*/}
cd $SCRIPTDIR/.. # command is a subdirectory of driver
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
CONFIG_ETC="/etc/piGarden.conf"
LOG_OUTPUT_DRV_FILE="$DIR_SCRIPT/log/$LOG_OUTPUT_DRV_FILE"
. $CONFIG_ETC
. ./common.include.sh
. ./config.include.sh
. ./init.include.sh
. ./rainsensor.include.sh
if [[ $# = 0 ]] ; then
cmd=cat
echo "processing all entire $RAINSENSORQTY_HISTORYRAW file, will go on? (y/n)"
read answer
echo $answer
[[ $answer = [yY] ]] || exit 1
else
if (( $1 >= 1 )) ; then
echo "processing $1 lines of $RAINSENSORQTY_HISTORYRAW file"
cmd="tail -$1"
else
echo "argument not recognized - exit"
exit 1
fi
fi
echo -e "\n\n"
$cmd $RAINSENSORQTY_HISTORYRAW | while read line
do
set -- ${line//:/ }
secs=$1
counter=$2
echo "$(sec2date $1):$counter"
done

View File

@@ -1,7 +1,7 @@
#!/bin/bash
# Driver rainsensorqty - driver for measure the rain volume
# Author: androtto
# file "test_rainsensorqty_INIT.sh"
# file "rainsensorqty_INIT.sh"
# test script for initialize driver and executing monitor process
# Version: 0.2.0
# Data: 11/Aug/2019
@@ -12,10 +12,6 @@ cd $SCRIPTDIR/.. # command is a subdirectory of driver
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
CONFIG_ETC="/etc/piGarden.conf"
TMP_PATH="/run/shm"
if [ ! -d "$TMP_PATH" ]; then
TMP_PATH="/tmp"
fi
. $CONFIG_ETC

View File

@@ -1,4 +1,11 @@
#!/bin/bash
# Driver rainsensorqty - driver for measure the rain volume
# Author: androtto
# file "rainsensorqty_KILL.sh"
# script for killing monitor process(es)
# Version: 0.2.0a
# Data: 29/Aug/2019
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
SCRIPTNAME=${0##*/}
@@ -6,10 +13,6 @@ cd $SCRIPTDIR/.. # command is a subdirectory of driver
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
CONFIG_ETC="/etc/piGarden.conf"
TMP_PATH="/run/shm"
if [ ! -d "$TMP_PATH" ]; then
TMP_PATH="/tmp"
fi
. $CONFIG_ETC
@@ -43,6 +46,7 @@ if [[ -f "$RAINSENSORQTY_MONPID" ]] ; then
else
echo "no RAIN process alive"
fi
else
echo "no RAIN process alive"
fi

View File

@@ -1,10 +1,10 @@
#!/bin/bash
# Driver rainsensorqty - driver for measure the rain volume
# Author: androtto
# file "test_rainsensorqty_RAINNOW.sh"
# file "rainsensorqty_RAINNOW.sh"
# test script for simulate rain ... now!
# Version: 0.2.0
# Data: 11/Aug/2019
# Version: 0.2.5
# Data: 07/Apr/2020
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
SCRIPTNAME=${0##*/}
@@ -12,11 +12,6 @@ cd $SCRIPTDIR/.. # command is a subdirectory of driver
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
CONFIG_ETC="/etc/piGarden.conf"
TMP_PATH="/run/shm"
if [ ! -d "$TMP_PATH" ]; then
TMP_PATH="/tmp"
fi
. $CONFIG_ETC
. ./config.include.sh
@@ -24,4 +19,49 @@ fi
. ./init.include.sh
. ./rainsensor.include.sh
echo "$(date +%s):$RAINSENSORQTY_LOOPSFORSETRAINING" > ${RAINSENSORQTY_LASTRAIN}
wait=0
timestart=$( date +%s)
if [[ $# -ne 0 ]] ; then
if [[ $# = 1 ]] ; then
howmany=$1
echo "one argument passed: rain event for $howmany loops"
(( time = timestart - howmany ))
elif [[ $# = 2 ]] ; then
howmany=$1
wait=$2
echo "two arguments passed: rain event for $howmany loops every $wait seconds"
(( time = timestart ))
else
echo "too many arguments... exit"
exit 1
fi
else
howmany=$RAINSENSORQTY_LOOPSFORSETRAINING
(( time = timestart - $RAINSENSORQTY_LOOPSFORSETRAINING ))
fi
echo "RAIN now! (for $howmany loops)"
for (( c=1; c<=$howmany; c++ ))
do
if (( wait > 0 )) ; then
time=$( date +%s)
else
(( time+= 1 ))
fi
linetoadd="$time:$c"
echo $linetoadd >> $RAINSENSORQTY_HISTORYRAW
sleep $wait
echo -e ".\c"
done
echo
if ! rain_history ; then # update rain history with last rain if not
echo "WARNING: rain_history function had error"
fi
echo $linetoadd > ${RAINSENSORQTY_LASTRAIN}
echo "file ${RAINSENSORQTY_LASTRAIN} updated."
echo "last 2 rain events:"
tail -2 $RAINSENSORQTY_HISTORY | rain_when_amount

View File

@@ -0,0 +1,44 @@
#!/bin/bash
# Driver rainsensorqty - driver for measure the rain volume
# Author: androtto
# file "test_rainsensorqty_CHECK.sh"
# test script for checking rain status using drv_rainsensorqty_rain_sensor_get function
# Version: 0.2.5
# Data: 07/Apr/2020
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
SCRIPTNAME=${0##*/}
cd $SCRIPTDIR/.. # command is a subdirectory of driver
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
CONFIG_ETC="/etc/piGarden.conf"
LOG_OUTPUT_DRV_FILE="$DIR_SCRIPT/log/$LOG_OUTPUT_DRV_FILE"
. $CONFIG_ETC
. ./common.include.sh
. ./config.include.sh
. ./init.include.sh
. ./rainsensor.include.sh
# two variables for store rain data
# RAINSENSORQTY_LASTRAIN
# RAINSENSORQTY_HISTORY
echo "RAIN HISTORY - last two events"
tail -2 $RAINSENSORQTY_HISTORY
tail -2 $RAINSENSORQTY_HISTORY | rain_when_amount
echo "...removing last event"
removelastrain
echo "...rebuilding ${RAINSENSORQTY_HISTORY} from ${RAINSENSORQTY_HISTORYRAW}"
if ! rainevents > ${RAINSENSORQTY_HISTORY} ; then
echo "WARNING: rainevents function had error"
fi
tail -1 ${RAINSENSORQTY_HISTORYRAW} > ${RAINSENSORQTY_LASTRAIN}
echo -e "\nnew RAIN HISTORY - last two events"
tail -2 $RAINSENSORQTY_HISTORY
tail -2 $RAINSENSORQTY_HISTORY | rain_when_amount

View File

@@ -0,0 +1,35 @@
#!/bin/bash
# Driver rainsensorqty - driver for measure the rain volume
# Author: androtto
# file "rainsensorqty_RESET.sh"
# script for reset counter in monitor script
# Version: 0.2.0a
# Data: 29/Aug/2019
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
SCRIPTNAME=${0##*/}
cd $SCRIPTDIR/.. # command is a subdirectory of driver
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
CONFIG_ETC="/etc/piGarden.conf"
. $CONFIG_ETC
. ./config.include.sh
. ./common.include.sh
. ./init.include.sh
. ./rainsensor.include.sh
# check if rain monitor process is running...
if [[ -f "$RAINSENSORQTY_MONPID" ]] ; then
pid="$( < "$RAINSENSORQTY_MONPID" )"
if ps -fp $pid >/dev/null ; then
echo "sending SIGUSR1 to $pid"
kill -SIGUSR1 $pid
echo -e "sent SIGUSR1 - reset will be shown after next cycle"
else
echo "no RAIN process alive"
fi
else
echo "no RAIN process alive"
fi

View File

@@ -3,14 +3,19 @@
# Author: androtto
# file "common.include.sh"
# common functions used by driver
# Version: 0.2.0
# Data: 11/Aug/2019
# Version: 0.2.5
# Data: 08/Jan/2020
#note:
#RAINSENSORQTY_MONPID="$TMP_PATH/rainsensorqty_monitor.pid"
#RAINSENSORQTY_MONPID="$TMPDIR/rainsensorqty_monitor.pid"
#
sec2date()
{
date --date="@$1"
}
d() # short date & time
{
date '+%X-%x'
@@ -57,13 +62,102 @@ en_echo() # enhanched echo - check verbose variable
rain_history()
{
[[ ! -f $RAINSENSORQTY_HISTORYRAW ]] && return 1
[[ ! -f $RAINSENSORQTY_HISTORY ]] && touch $RAINSENSORQTY_HISTORY
[[ ! -f $RAINSENSORQTY_LASTRAIN ]] && return 1
if grep -q ^$(<$RAINSENSORQTY_LASTRAIN)$ $RAINSENSORQTY_HISTORY ; then
: # do nothing
return 2
> $RAINSENSORQTY_HISTORYTMP
if lastrainevent=$( rainevents 1 ) ; then
: # done ok
else
cat $RAINSENSORQTY_LASTRAIN >> $RAINSENSORQTY_HISTORY
echo "WARNING: rainevents function had errors"
return 1
fi
#old #if grep -q ^$(<$RAINSENSORQTY_LASTRAIN)$ $RAINSENSORQTY_HISTORY ; then
if grep -q ^${lastrainevent}$ $RAINSENSORQTY_HISTORY ; then
: # already present
return 0
else
: # missing and fixed
if [[ $1 == tmp ]] ; then
echo $lastrainevent > $RAINSENSORQTY_HISTORYTMP
else
echo $lastrainevent >> $RAINSENSORQTY_HISTORY
fi
return 0
fi
}
rain_when_amount()
{
# from standard input
# format $time:$endtime:$endsequence
cat - | while read line
do
set -- ${line//:/ }
start=$1
stop=$2
howmuch=$3
printf "RAINED for %7.2f mm between %s and %s\n" $( $JQ -n "$howmuch * $RAINSENSORQTY_MMEACH" ) "$(date --date="@$start")" "$(date --date="@$stop")"
done
}
check_TMPDIR()
{
if [[ $(df | awk '$NF=="/tmp" {print $1}') != "tmpfs" ]] ; then
echo "WARNING: /tmp isn't a tmp file system"
echo -e "\tplease add to your /etc/fstab file:\n\ttmpfs /tmp tmpfs defaults,noatime,nosuid 0 0"
fi
}
rainevents()
{
if [[ ! -f $RAINSENSORQTY_HISTORYRAW ]] ; then
#echo "WARNING: no \$RAINSENSORQTY_HISTORYRAW file"# cannot echo, redirected output
return 1
fi
case $1 in
[0-9]|[0-9][0-9]) howmanyevent=$1 ;;
# -1) skiplast=true ;;
*) howmanyevent=-1 ;;
esac
newloop=yes
tac $RAINSENSORQTY_HISTORYRAW | while read line
do
set -- ${line//:/ }
time=$1
sequence=$2
if [[ $newloop == yes ]] ; then
endtime=$time
endsequence=$sequence
newloop=no
fi
if (( sequence == 1 )) ; then
# [[ $skiplast=true ]] && { skilast=false ; continue ; }
echo $time:$endtime:$endsequence
newloop=yes
(( event +=1 ))
fi
(( howmanyevent == event )) && break
done | sort -k1n
}
removelastrain()
{
if [[ ! -f $RAINSENSORQTY_HISTORYRAW ]] ; then
echo "WARNING: no \$RAINSENSORQTY_HISTORYRAW file"
return 1
fi
next=false
tac $RAINSENSORQTY_HISTORYRAW | while read line
do
set -- ${line//:/ }
time=$1
sequence=$2
[[ $next = true ]] && echo $line
(( sequence == 1 )) && next=true
done | tac > ${RAINSENSORQTY_HISTORYRAW}_$$
mv ${RAINSENSORQTY_HISTORYRAW}_$$ $RAINSENSORQTY_HISTORYRAW
}

View File

@@ -0,0 +1,66 @@
#
# Driver rainsensorqty - driver for measure the rain volume
# Author: androtto
# file "config.include.sh"
# specific driver config file
# Version: 0.2.5
# Data: 08/Jan/2020
export TMPDIR=/tmp
RAINSENSOR_DEBOUNCE=0.3 # 0.3 seconds for manage debounce of reed contact
RAINSENSORQTY_verbose="yes" # yes/no
RAINSENSORQTY_LASTRAIN="$STATUS_DIR/rainsensorqty_lastrain"
RAINSENSORQTY_HISTORY="$STATUS_DIR/rainsensorqty_history"
RAINSENSORQTY_HISTORYRAW="$STATUS_DIR/rainsensorqty_history.raw"
RAINSENSORQTY_HISTORYTMP="$TMPDIR/rainsensorqty_history.tmp"
RAINSENSORQTY_MONITORLOG="$DIR_SCRIPT/log/rainsensorqty_monitor.log"
RAINSENSORQTY_MONPID="$TMPDIR/rainsensorqty_monitor.pid"
RAINSENSORQTY_STATE="$TMPDIR/rainsensorqty_state"
RAINSENSORQTY_STATE_HIST="$TMPDIR/rainsensorqty_state.history"
RAINSENSORQTY_DIR="$DIR_SCRIPT/drv/rainsensorqty"
monitor_sh="$RAINSENSORQTY_DIR/drv_rainsensorqty_monitor.sh"
# internal gpio resistor, 3 values: pull-up, pull-down, none
# pull-up/down if rain gauge is connected directly to raspberry
# none if connected through an optocoupler circuit
GPIO_RESISTOR="pull-up" #pull-up|pull-down|none
#rising means waiting for 1 status (from 0)
#falling means waiting for 0 status (from 1)
#RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
#RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
(( RAIN_GPIO_STATE == 1 )) && RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
(( RAIN_GPIO_STATE == 0 )) && RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
config_check()
{
var2check="RAINSENSOR_DEBOUNCE RAINSENSORQTY_verbose RAINSENSORQTY_LASTRAIN RAINSENSORQTY_HISTORY RAINSENSORQTY_MONITORLOG RAINSENSORQTY_MONPID RAINSENSORQTY_DIR monitor_sh"
for var in $var2check
do
#${!a}
if [[ -z ${!var} ]] ; then
echo "ERROR: \$$var not set"
exit 1
fi
done
if [[ -z $RAINSENSORQTY_PULSE ]] ; then
echo "ERROR: RAIN_GPIO_STATE not set in piGarden.conf"
exit 1
fi
return 0
case $GPIO_RESISTOR in
pull-up|pull-down|none) return 0 ;;
*) echo "ERROR: GPIO_RESISTOR not set correctly - values are \"pull-up|pull-down|none\" "
exit 1
;;
esac
}

View File

@@ -3,37 +3,64 @@
# Author: androtto
# file "config.include.sh"
# specific driver config file
# Version: 0.2.0
# Data: 11/Aug/2019
# Version: 0.2.5
# Data: 08/Jan/2020
RAINSENSOR_ANTIBOUNCE=0.3 # 0.3 seconds for manage antibounce of reed contact
export TMPDIR=/tmp
RAINSENSORQTY_verbose="no" # yes/no
RAINSENSOR_DEBOUNCE=0.3 # 0.3 seconds for manage debounce of reed contact
RAINSENSORQTY_verbose="yes" # yes/no
RAINSENSORQTY_LASTRAIN="$STATUS_DIR/rainsensorqty_lastrain"
RAINSENSORQTY_HISTORY="$STATUS_DIR/rainsensorqty_history"
RAINSENSORQTY_HISTORYRAW="$STATUS_DIR/rainsensorqty_history.raw"
RAINSENSORQTY_HISTORYTMP="$TMPDIR/rainsensorqty_history.tmp"
RAINSENSORQTY_MONITORLOG="$DIR_SCRIPT/log/rainsensorqty_monitor.log"
RAINSENSORQTY_MONPID="$TMP_PATH/rainsensorqty_monitor.pid"
RAINSENSORQTY_MONPID="$TMPDIR/rainsensorqty_monitor.pid"
RAINSENSORQTY_STATE="$TMPDIR/rainsensorqty_state"
RAINSENSORQTY_STATE_HIST="$TMPDIR/rainsensorqty_state.history"
RAINSENSORQTY_DIR="$DIR_SCRIPT/drv/rainsensorqty"
monitor_sh="$RAINSENSORQTY_DIR/drv_rainsensorqty_monitor.sh"
# internal gpio resistor, 3 values: pull-up, pull-down, none
# pull-up/down if rain gauge is connected directly to raspberry
# none if connected through an optocoupler circuit
GPIO_RESISTOR="pull-up" #pull-up|pull-down|none
#rising means waiting for 1 status (from 0)
#falling means waiting for 0 status (from 1)
#RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
#RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
if (( RAIN_GPIO_STATE = 1 )) ; then
RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
fi
if (( RAIN_GPIO_STATE = 0 )) ; then
RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
fi
if [[ -z $RAINSENSORQTY_PULSE ]] ; then
echo "ERROR: RAIN_GPIO_STATE non set in piGarden.conf"
exit 1
fi
(( RAIN_GPIO_STATE == 1 )) && RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
(( RAIN_GPIO_STATE == 0 )) && RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
config_check()
{
var2check="RAINSENSOR_DEBOUNCE RAINSENSORQTY_verbose RAINSENSORQTY_LASTRAIN RAINSENSORQTY_HISTORY RAINSENSORQTY_MONITORLOG RAINSENSORQTY_MONPID RAINSENSORQTY_DIR monitor_sh"
for var in $var2check
do
#${!a}
if [[ -z ${!var} ]] ; then
echo "ERROR: \$$var not set"
exit 1
fi
done
if [[ -z $RAINSENSORQTY_PULSE ]] ; then
echo "ERROR: RAIN_GPIO_STATE not set in piGarden.conf"
exit 1
fi
return 0
case $GPIO_RESISTOR in
pull-up|pull-down|none) return 0 ;;
*) echo "ERROR: GPIO_RESISTOR not set correctly - values are \"pull-up|pull-down|none\" "
exit 1
;;
esac
}

View File

@@ -4,23 +4,34 @@
# Author: androtto
# file "drv_rainsensorqty_monitor.sh"
# monitor script
# Version: 0.2.0
# Data: 11/Aug/2019
# Version: 0.2.5b
# Data: 12/May/2020
resetcounter()
{
(( counter = 0 ))
drv_rainsensorqty_writelog $f "SIGUSR1 received after last PULSE - counter resetted" &
echo "SIGUSR1 received after last PULSE - counter resetted"
}
###############
# MAIN #
###############
trap "resetcounter" SIGUSR1
DIRNAME="$( dirname $0 )"
f="$(basename $0)"
. $DIRNAME/common.include.sh
set_var="$DIRNAME/.set_var"
if [[ -f "$set_var" ]] ; then
en_echo "NORMAL: file $set_var found - getting variables"
. "$set_var"
RAINSENSORQTY_VAR=$TMPDIR/.rainsensorqty_var
if [[ -f "$RAINSENSORQTY_VAR" ]] ; then
en_echo "NORMAL: file $RAINSENSORQTY_VAR found - getting variables"
. "$RAINSENSORQTY_VAR"
else
echo "ERROR: $set_var not found"
echo "ERROR: $RAINSENSORQTY_VAR not found"
exit 1
fi
@@ -46,29 +57,31 @@ MMEACH="$RAINSENSORQTY_MMEACH"
rain_history
echo ""
en_echo "---- NEW RUN "
en_echo "---- NEW RUN ----"
en_echo "WAITING FOR $RAINSENSORQTY_PULSE PULSE"
# loop forever
while true
do
before=`date +%s`
sleep $RAINSENSOR_ANTIBOUNCE
en_echo "WAITING FOR PULSE"
sleep $RAINSENSOR_DEBOUNCE
$GPIO -g wfi $gpio_port $RAINSENSORQTY_PULSE
now=`date +%s`
(( elapsed = now - before ))
if (( elapsed >= RAINSENSORQTY_SECSBETWEENRAINEVENT )) ; then
(( counter=0 ))
drv_rainsensorqty_writelog $f "first drops after $elapsed seconds since last rain ( greater than $RAINSENSORQTY_SECSBETWEENRAINEVENT )- new cycle - waiting for $( $JQ -n "$RAINSENSORQTY_LOOPSFORSETRAINING * $MMEACH" )" &
rain_history
drv_rainsensorqty_writelog $f "first drops after $elapsed seconds since last rain ( greater than $RAINSENSORQTY_SECSBETWEENRAINEVENT )- new cycle - waiting for $( $JQ -n "$RAINSENSORQTY_LOOPSFORSETRAINING * $MMEACH" ) mm of rain" &
en_echo "---- NEW CYCLE ----"
rain_history &
fi
(( counter+=1 ))
en_echo "PULSE RECEIVED (counter $counter)"
echo "$now:$counter" >> ${RAINSENSORQTY_HISTORYRAW} &
MMWATER=$( $JQ -n "$counter*$MMEACH" )
text=$(printf "%.2f mm height (loop %d)" $MMWATER $counter )
en_echo $( printf "%s PULSE #%d RECEIVED (%.2f mm)" $RAINSENSORQTY_PULSE $counter $MMWATER )
text=$(printf "%.2f mm height (#%d pulse)" $MMWATER $counter )
if (( counter >= RAINSENSORQTY_LOOPSFORSETRAINING )) ; then
drv_rainsensorqty_writelog $f "RAINING - $text" &
echo "$(date +%s):$counter" > ${RAINSENSORQTY_LASTRAIN}
echo "$now:$counter" > ${RAINSENSORQTY_LASTRAIN}
else
drv_rainsensorqty_writelog $f "now is $text" &
fi

View File

@@ -23,4 +23,15 @@ function drv_rainsensorqty_init {
fi
}
set | $GREP -e ^GPIO -e ^LOG -e ^CUT -e ^JQ -e ^RAIN -e ^SCR -e ^TMP > "${RAINSENSORQTY_DIR}/.set_var"
if ! config_check ; then
echo "ERROR in config_check function"
exit 1
else
: #echo "config_check ok"
fi
check_TMPDIR
RAINSENSORQTY_VAR=$TMPDIR/.rainsensorqty_var
set | $GREP -e ^GPIO -e ^LOG -e ^CUT -e ^JQ -e ^RAIN -e ^SCR -e ^TMP > $RAINSENSORQTY_VAR

View File

@@ -14,14 +14,41 @@
#
drv_rainsensorqty_rain_sensor_init()
{
drv_rainsensorqty_writelog "drv_rainsensorqty_rain_sensor_init" $1
local f=drv_rainsensorqty_rain_sensor_init
drv_rainsensorqty_writelog "launched: $f" $1
local drvt="$( echo $RAIN_GPIO | $CUT -f 1 -d: )"
local drv="$( echo $RAIN_GPIO | $CUT -f 2 -d: )"
local gpio_port="$( echo $RAIN_GPIO | $CUT -f 3 -d: )"
$GPIO -g mode $gpio_port in
if $GPIO -g mode $gpio_port in ; then
drv_rainsensorqty_writelog $f "NORMAL: '$GPIO -g mode $gpio_port in' set correctly"
else
drv_rainsensorqty_writelog $f "ERROR: '$GPIO -g mode $gpio_port in' has an error"
exit 1
fi
case $GPIO_RESISTOR in
pull-up) gpio_arg=up
message="NORMAL: '$GPIO -g mode $gpio_port up' set internal pull-up resistor"
;;
pull-down) gpio_arg=down
message="NORMAL: '$GPIO -g mode $gpio_port down' set internal pull-down resistor"
;;
none) gpio_arg=tri
message="NORMAL: '$GPIO -g mode $gpio_port tri' set none to internal resistor"
;;
*) echo "ERROR: GPIO_RESISTOR not set correctly - values are \"pull-up|pull-down|none\" "
drv_rainsensorqty_writelog "drv_rainsensorqty_rain_sensor_init" "ERROR: GPIO_RESISTOR not set correctly - values are \"pull-up|pull-down|none\" "
exit 1
;;
esac
if $GPIO -g mode $gpio_port $gpio_arg ; then
drv_rainsensorqty_writelog $f "$message"
else
drv_rainsensorqty_writelog $f "ERROR: '$GPIO -g mode $gpio_port $gpio_arg' command"
exit 1
fi
}
#

View File

@@ -559,7 +559,79 @@ function cron_disable_all_open_close {
fi
done
}
#
# Attiva tutte le schedulazioni di apertura e chiusura elettrovalvole
#
function cron_enable_all_open_close {
local a=""
local al=""
local cron=""
#
# Disabilita tutte le schedulazioni di apertura
#
for i in $(seq $EV_TOTAL)
do
a=EV"$i"_ALIAS
al=${!a}
local crons=`get_cron_open $al`
if [[ ! -z "$crons" ]]; then
del_cron_open $al
IFS=$'\n' # make newlines the only separator
for cron in $crons
do
#echo "-- $cron --"
CRON_M=`echo $cron | $CUT -d' ' -f1,1`
CRON_H=`echo $cron | $CUT -d' ' -f2,2`
CRON_DOM=`echo $cron | $CUT -d' ' -f3,3`
CRON_MON=`echo $cron | $CUT -d' ' -f4,4`
CRON_DOW=`echo $cron | $CUT -d' ' -f5,5`
if [[ ${CRON_M:0:1} == "#" ]]; then
CRON_M=${CRON_M:1:${#CRON_M}}
fi
#echo "++ $CRON_M $CRON_H $CRON_DOM $CRON_MON $CRON_DOW ++"
add_cron_open $al "$CRON_M" "$CRON_H" "$CRON_DOM" "$CRON_MON" "$CRON_DOW"
done
fi
done
#
# Disabilita tutte le schedulazioni di chiusura
#
for i in $(seq $EV_TOTAL)
do
a=EV"$i"_ALIAS
al=${!a}
local crons=`get_cron_close $al`
if [[ ! -z "$crons" ]]; then
del_cron_close $al
IFS=$'\n' # make newlines the only separator
for cron in $crons
do
#echo "-- $cron --"
CRON_M=`echo $cron | $CUT -d' ' -f1,1`
CRON_H=`echo $cron | $CUT -d' ' -f2,2`
CRON_DOM=`echo $cron | $CUT -d' ' -f3,3`
CRON_MON=`echo $cron | $CUT -d' ' -f4,4`
CRON_DOW=`echo $cron | $CUT -d' ' -f5,5`
if [[ ${CRON_M:0:1} == "#" ]]; then
CRON_M=${CRON_M:1:${#CRON_M}}
fi
#echo "++ $CRON_M $CRON_H $CRON_DOM $CRON_MON $CRON_DOW ++"
add_cron_close $al "$CRON_M" "$CRON_H" "$CRON_DOM" "$CRON_MON" "$CRON_DOW"
done
fi
done
}

View File

@@ -102,6 +102,12 @@ function socket_server_command {
json_status
;;
cron_enable_all_open_close)
cron_enable_all_open_close &> /dev/null
message_write "success" "All solenoid enabled"
json_status
;;
set_general_cron)
local vret=""
for i in $arg2 $arg3 $arg4 $arg5 $arg6 $arg7
@@ -205,6 +211,21 @@ function socket_server_command {
;;
cmd_pigardensched)
local vret=""
vret=`cmd_pigardensched $arg2 $arg3 $arg4 $arg5 $arg6`
if [[ ! -z $vret ]]; then
json_error 0 "piGardenSched command failed"
log_write "piGardenSched command failed: $vret"
else
message_write "success" "Schedule set successfull"
json_status
fi
;;
reboot)
message_write "warning" "System reboot is started"
json_status

View File

@@ -223,9 +223,6 @@ function ev_open_in {
trigger_event "ev_open_in_after" "$3" "$4" "$cron_start" "$cron_stop"
#echo $cron_start
#echo $cron_stop
}
@@ -506,8 +503,9 @@ function list_alias {
#
# Stampa un json contanente lo status della centralina
# $1 .. $6 parametri opzionali
# - get_cron: aggiunge i dati relativi ai crontab delle scehdulazioni di apertura/chisura delle elettrovalvole
# - get_cron: aggiunge i dati relativi ai crontab delle scehdulazioni di apertura/chisura
# - get_cron_open_in: aggiunge i dati relativi ai crontab degli avvii ritardati eseguiti con il comando open_in
# - get_schedule: aggiunge i dati relativi alle schedulazioni di piGardenSched
#
function json_status {
local json=""
@@ -521,6 +519,7 @@ function json_status {
local last_success=""
local with_get_cron="0"
local with_get_cron_open_in="0"
local with_get_schedule="0"
local current_pid=$!
local json_event="\"event\": {\"event\": \"$CURRENT_EVENT\", \"alias\": \"$CURRENT_EVENT_ALIAS\"}"
@@ -539,9 +538,12 @@ function json_status {
with_get_cron_open_in="1"
elif [[ "$i" == get_cron_open_in:* ]]; then
with_get_cron_open_in="${i#get_cron_open_in:}"
elif [ $i = "get_schedule" ] && [[ $PIGARDENSCHED == "1" ]]; then
with_get_schedule="1"
fi
done
local json_ev=""
for i in $(seq $EV_TOTAL)
do
local a=EV"$i"_ALIAS
@@ -551,10 +553,14 @@ function json_status {
if [ -n "$json" ]; then
json="$json,"
fi
#json="$json\"$i\":{\"name\":\"$av\",\"state\":$sv}"
json="$json\"$av\":{\"name\":\"$av\",\"state\":$sv}"
if [ -n "$json_ev" ]; then
json_ev="$json_ev,"
fi
json_ev="$json_ev\"$a\":{\"alias\":\"$av\"}"
done
json="\"zones\":{$json}"
json="\"zones\":{$json},\"ev\":{$json_ev}"
local last_rain_sensor=`cat "$STATUS_DIR/last_rain_sensor" 2> /dev/null`
local last_rain_online=`cat "$STATUS_DIR/last_rain_online" 2> /dev/null`
@@ -563,15 +569,7 @@ function json_status {
if [[ ! -z "$last_weather_online" ]]; then
json_last_weather_online=$last_weather_online
fi
#if [ -f "$LAST_INFO_FILE.$current_pid" ]; then
# last_info=`cat "$LAST_INFO_FILE.$current_pid"`
#fi
#if [ -f "$LAST_WARNING_FILE.$current_pid" ]; then
# last_warning=`cat "$LAST_WARNING_FILE.$current_pid"`
#fi
#if [ -f "$LAST_SUCCESS_FILE.$current_pid" ]; then
# last_success=`cat "$LAST_SUCCESS_FILE.$current_pid"`
#fi
last_info="$MESSAGE_INFO"
last_warning="$MESSAGE_WARNING"
last_success="$MESSAGE_SUCCESS"
@@ -615,6 +613,24 @@ function json_status {
fi
local json_cron="\"cron\":{$json_get_cron}"
local json_get_schedule=""
local json_schedule=""
if [ $with_get_schedule != "0" ]; then
json_get_schedule=""
for scheduled in `$PIGARDENSCHED_PATH sched`
do
local ev=$(echo $scheduled|$CUT -f1 -d";")
local evcomplete="$ev"_ALIAS
local al=${!evcomplete}
local json_get_schedule="\"$ev\": {\"alias\": \"$al\", \"entry\": \"$scheduled\"}, $json_get_schedule"
done
if [[ ! -z $json_get_schedule ]]; then
json_get_schedule="${json_get_schedule::-2}"
fi
local json_schedule=", \"schedule\":{$json_get_schedule}"
fi
local json_get_cron_open_in=""
if [ $with_get_cron_open_in != "0" ]; then
local values_open_in=""
@@ -649,7 +665,7 @@ function json_status {
local json_cron_open_in="\"cron_open_in\":{$json_get_cron_open_in}"
local json_timestamp="\"timestamp\": $(date +%s)"
json="{$json_version,$json_timestamp,$json_event,$json,$json_last_weather_online,$json_error,$json_last_info,$json_last_warning,$json_last_success,$json_last_rain_online,$json_last_rain_sensor,$json_cron,$json_cron_open_in}"
json="{$json_version,$json_timestamp,$json_event,$json,$json_last_weather_online,$json_error,$json_last_info,$json_last_warning,$json_last_success,$json_last_rain_online,$json_last_rain_sensor,$json_cron,$json_cron_open_in $json_schedule}"
echo "$json"
@@ -691,7 +707,7 @@ function show_usage {
echo -e "\t$NAME_SCRIPT list_alias view list of aliases solenoid"
echo -e "\t$NAME_SCRIPT ev_status alias show status solenoid"
echo -e "\t$NAME_SCRIPT ev_status_all show status solenoids"
echo -e "\t$NAME_SCRIPT json_status [get_cron|get_cron_open_in] show status in json format"
echo -e "\t$NAME_SCRIPT json_status [get_cron|get_cron_open_in|get_schedule] show status in json format"
echo -e "\t$NAME_SCRIPT mqtt_status send status in json format to mqtt broker"
echo -e "\t$NAME_SCRIPT check_rain_online check rain from http://api.wunderground.com/"
echo -e "\t$NAME_SCRIPT check_rain_sensor check rain from hardware sensor"
@@ -723,6 +739,8 @@ function show_usage {
echo -e "\t$NAME_SCRIPT del_cron_close alias remove all crontab for close a solenoid"
echo -e "\t$NAME_SCRIPT get_cron_close alias get all crontab for close a solenoid"
echo -e "\n"
echo -e "\t$NAME_SCRIPT cmd_pigardensched [prm1 [prm2 [prm3]...]] performs a pigardensched command"
echo -e "\n"
echo -e "\t$NAME_SCRIPT debug1 [parameter]|[parameter]|..] Run debug code 1"
echo -e "\t$NAME_SCRIPT debug2 [parameter]|[parameter]|..] Run debug code 2"
}
@@ -843,6 +861,31 @@ function exec_reboot {
trigger_event "exec_reboot_after"
}
#
# Esegue un comando con piGardenSched
#
# $1 parametro 1
# $2 parametro 2
# $3 parametro 3
# $4 parametro 4
# $5 parametro 5
function cmd_pigardensched {
local foo="bar"
if [ $PIGARDENSCHED == 0 ]; then
echo "piGardenSched not configured in piGarden" >&2
log_write "piGardenSched not configured in piGarden"
return
fi
$PIGARDENSCHED_PATH $1 $2 $3 $4 $5
if [ $? -ne 0 ]; then
echo "piGardenSched command failed"
fi
}
#
# Converte da gradi a direzione
@@ -940,8 +983,8 @@ function debug2 {
}
VERSION=0
SUB_VERSION=5
RELEASE_VERSION=13
SUB_VERSION=6
RELEASE_VERSION=0
DIR_SCRIPT=`dirname $0`
NAME_SCRIPT=${0##*/}
@@ -969,9 +1012,6 @@ fi
. "$DIR_SCRIPT/include/rain.include.sh"
. "$DIR_SCRIPT/include/events.include.sh"
#LAST_INFO_FILE="$STATUS_DIR/last_info"
#LAST_WARNING_FILE="$STATUS_DIR/last_warning"
#LAST_SUCCESS_FILE="$STATUS_DIR/last_success"
MESSAGE_INFO=""
MESSAGE_WARNING=""
MESSAGE_SUCCESS=""
@@ -995,6 +1035,11 @@ elif [ "$WEATHER_SERVICE" != "none" ]; then
WEATHER_SERVICE="drv:$WEATHER_SERVICE"
fi
PIGARDENSCHED="0"
if [[ -x "$PIGARDENSCHED_PATH" ]]; then
PIGARDENSCHED="1"
fi
# Elimina il file di lock se più vecchio di 11 secondi
if [ -f "$LOCK_FILE" ]; then
max_age_lock_file=11
@@ -1168,6 +1213,10 @@ case "$1" in
get_cron_close $2
;;
cmd_pigardensched)
cmd_pigardensched $2 $3 $4 $5
;;
reboot)
exec_reboot
;;