Merge branch 'rainsensorqty' into develop

Eseguito merge del brench rainsensorqty nel brench develop
This commit is contained in:
lejubila
2019-09-24 17:06:25 +02:00
15 changed files with 281 additions and 106 deletions

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.30
# Data: 21/Sep/2019
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,15 +27,15 @@ 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
commands/rainsensorqty_INIT.sh
@@ -44,14 +44,19 @@ commands/rainsensorqty_INIT.sh
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
commands/rainsensorqty_REMOVELASTRAIN.sh
rimuove dai file $RAINSENSORQTY_LASTRAIN $RAINSENSORQTY_HISTORY 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
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,40 +64,44 @@ 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_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_STATE="$TMPDIR/rainsensorqty_state"
file che viene popolato con l'ultimo stato della vaschetta (formato timestamp:counter)
RAINSENSORQTY_DIR="$DIR_SCRIPT/drv/rainsensorqty"
home directory del driver
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

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.0a
# Data: 13/Aug/2019
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,7 @@ LOG_OUTPUT_DRV_FILE="$DIR_SCRIPT/log/$LOG_OUTPUT_DRV_FILE"
. ./init.include.sh
. ./rainsensor.include.sh
rain_history # update rain history file if not
echo "RAIN HISTORY"
rain_history
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
cat $RAINSENSORQTY_HISTORY | rain_when_amount

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.0a
# Data: 13/Aug/2019
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,8 @@ fi
. ./init.include.sh
. ./rainsensor.include.sh
echo "RAIN now!"
echo "$(date +%s):$RAINSENSORQTY_LOOPSFORSETRAINING" > ${RAINSENSORQTY_LASTRAIN}
echo "file ${RAINSENSORQTY_LASTRAIN} updated."
echo -e "\nLAST RAIN:"
cat $RAINSENSORQTY_LASTRAIN | rain_when_amount

View File

@@ -0,0 +1,51 @@
#!/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.0a
# Data: 13/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"
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
rain_history # update rain history file if not
echo "RAIN HISTORY - last five events"
tail -5 $RAINSENSORQTY_HISTORY | rain_when_amount
echo -e "\nLAST RAIN"
cat $RAINSENSORQTY_LASTRAIN | rain_when_amount
#exit # for test
echo -e "\nbackup to .old files"
cp -p $RAINSENSORQTY_HISTORY ${RAINSENSORQTY_HISTORY}.old
cp -p $RAINSENSORQTY_LASTRAIN ${RAINSENSORQTY_LASTRAIN}.old
echo "...removing last event"
head -n-1 ${RAINSENSORQTY_HISTORY}.old > $RAINSENSORQTY_HISTORY
tail -1 $RAINSENSORQTY_HISTORY > $RAINSENSORQTY_LASTRAIN
echo -e "\nnew RAIN HISTORY - last five events"
tail -5 $RAINSENSORQTY_HISTORY | rain_when_amount
echo -e "\nnew LAST RAIN"
cat $RAINSENSORQTY_LASTRAIN | 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,12 +3,12 @@
# Author: androtto
# file "common.include.sh"
# common functions used by driver
# Version: 0.2.0
# Data: 11/Aug/2019
# Version: 0.2.0a
# Data: 13/Aug/2019
#note:
#RAINSENSORQTY_MONPID="$TMP_PATH/rainsensorqty_monitor.pid"
#RAINSENSORQTY_MONPID="$TMPDIR/rainsensorqty_monitor.pid"
#
d() # short date & time
@@ -67,3 +67,24 @@ rain_history()
return 0
fi
}
rain_when_amount()
{
# from standard input
cat - | 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
}
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
}

View File

@@ -6,34 +6,59 @@
# Version: 0.2.0
# Data: 11/Aug/2019
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_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.2
# Data: 08/Sep/2019
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,32 @@ MMEACH="$RAINSENSORQTY_MMEACH"
rain_history
echo ""
en_echo "---- NEW RUN "
en_echo "---- NEW RUN ----"
# loop forever
while true
do
before=`date +%s`
sleep $RAINSENSOR_ANTIBOUNCE
en_echo "WAITING FOR PULSE"
sleep $RAINSENSOR_DEBOUNCE
en_echo "WAITING FOR $RAINSENSORQTY_PULSE PULSE"
$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)"
en_echo "$RAINSENSORQTY_PULSE PULSE #$counter RECEIVED"
echo "$now:$counter" > ${RAINSENSORQTY_STATE} &
echo "$now:$counter" >> ${RAINSENSORQTY_STATE_HIST} &
MMWATER=$( $JQ -n "$counter*$MMEACH" )
text=$(printf "%.2f mm height (loop %d)" $MMWATER $counter )
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
}
#