Iniziato integrazione codice di @androtto nel driver rainsensorqty
This commit is contained in:
@@ -1,12 +1,24 @@
|
||||
#
|
||||
# Funzioni comuni utilizzate dal driver
|
||||
#
|
||||
|
||||
#RAINSENSORQTY_MONPID="$TMP_PATH/rainsensorqty_monitor.pid"
|
||||
#
|
||||
# Funzione di esempio
|
||||
#
|
||||
function rainsensorqty_foo {
|
||||
|
||||
echo "bar"
|
||||
function drv_rainsensorqty_check () {
|
||||
|
||||
if [[ -f "$RAINSENSORQTY_MONPID" && -z "$RAINSENSORQTY_MONPID" ]] ; then
|
||||
pid=$( < "$RAINSENSORQTY_MONPID" )
|
||||
echo "drv_rainsensorqty_check - NORMAL: checking if $pid pid is running" >> "$LOG_OUTPUT_DRV_FILE"
|
||||
log_write "$$ pid monitor process - see $RAINSENSORQTY_MONPID"
|
||||
if ps -fp $pid >/dev/null ; then
|
||||
echo "drv_rainsensorqty_check - NORMAL: $pid pid is running" >> "$LOG_OUTPUT_DRV_FILE"
|
||||
return 0
|
||||
else
|
||||
echo "drv_rainsensorqty_check - NORMAL: $pid pid is NOT running" >> "$LOG_OUTPUT_DRV_FILE"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "drv_rainsensorqty_check - ERROR: no raining monitor process file \$RAINSENSORQTY_MONPID" >> "$LOG_OUTPUT_DRV_FILE"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -2,6 +2,20 @@
|
||||
# File di configurazione del driver
|
||||
#
|
||||
|
||||
declare -g RAINSENSORQTY_FILE_RUN
|
||||
RAINSENSORQTY_FILE_RUN="$STATUS_DIR/rainsensorqty_run"
|
||||
declare -g RAINSENSORQTY_LASTRAIN
|
||||
RAINSENSORQTY_LASTRAIN="$STATUS_DIR/rainsensorqty_lastrain"
|
||||
|
||||
declare -g RAINSENSORQTY_LOG
|
||||
RAINSENSORQTY_LOG="$DIR_SCRIPT/log/rainsensorqty.log"
|
||||
|
||||
declare -g RAINSENSORQTY_PID
|
||||
RAINSENSORQTY_MONPID="$TMP_PATH/rainsensorqty_monitor.pid"
|
||||
|
||||
declare -g RAINSENSORQTY_DIR
|
||||
RAINSENSORQTY_DIR="$DIR_SCRIPT/drv/rainsensorqty"
|
||||
|
||||
declare -g RAINSENSORQTY_PULSE
|
||||
RAINSENSORQTY_PULSE=falling
|
||||
|
||||
declare -g RAINSENSORQTY_WAIT
|
||||
RAINSENSORQTY_WAIT=rising
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
#
|
||||
# Inizializza il driver, viene richiamata nella funzione init di piGarden
|
||||
#
|
||||
function drv_rainsensorqty_init {
|
||||
# variables from general config file /etc/piGarden.conf
|
||||
#RAINSENSORQTY_LOOPSFORSETRAINING=10 # 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
|
||||
|
||||
function drv_rainsensorqty_init {
|
||||
# format RAIN_GPIO="drv:rainsensorqty:25"
|
||||
|
||||
# esegue rainmonitor
|
||||
if [[ -x "$monitor_sh" ]] ; then
|
||||
echo "OK - run rainmonitor"
|
||||
nohup "$monitor_sh" $gpio $RAINSENSORQTY_LOOPSFORSETRAINING $RAINSENSORQTY_SECSBETWEENRAINEVENT >> /tmp/debug_rainmonitor.log 2>&1 &
|
||||
sleep 1
|
||||
else
|
||||
:
|
||||
echo "KO - not run rainmonitor"
|
||||
fi
|
||||
|
||||
local FOO="bar"
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,40 +6,48 @@
|
||||
function drv_rainsensorqty_rain_sensor_init {
|
||||
|
||||
echo "drv_rainsensorqty_rain_sensor_init $1" >> "$LOG_OUTPUT_DRV_FILE"
|
||||
echo 0 > "$RAINSENSORQTY_FILE_RUN"
|
||||
|
||||
local drvt="$( echo $RAIN_GPIO | $CUT -f 1 -d: )"
|
||||
local drv="$( echo $RAIN_GPIO | $CUT -f 2 -d: )"
|
||||
local gpio="$( echo $RAIN_GPIO | $CUT -f 3 -d: )"
|
||||
|
||||
$GPIO -g mode $gpio in
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
# Ritorna lo stato del sensore di rilevamento pioggia
|
||||
# Ritorna in output lo stato del sensore di rilevamento pioggia
|
||||
#
|
||||
# $1 identificativo gpio del sensore di pioggia
|
||||
# return 0 = pioggia
|
||||
#
|
||||
function drv_rainsensorqty_rain_sensor_get {
|
||||
|
||||
echo "drv_rainsensorqty_rain_sensor_get $1" >> "$LOG_OUTPUT_DRV_FILE"
|
||||
|
||||
local state_rain=""
|
||||
|
||||
if [ $(cat "$RAINSENSORQTY_FILE_RUN") == 1 ]; then
|
||||
return
|
||||
else
|
||||
echo 1 > "$RAINSENSORQTY_FILE_RUN"
|
||||
if [ drv_rainsensorqty_check ]; then
|
||||
# Cosa deve fare ????
|
||||
# gli facciamo rieseguire drv_rainsensorqty_init in modo che riavvii il monitor ???
|
||||
fi
|
||||
|
||||
# Inserisci qui il codice per il controllo della pioggia e imposta il valore 0 a state_rain quando se sta piovendo
|
||||
|
||||
local state_rain=""
|
||||
|
||||
# INSERISCI QUI DENTRO I CONTROLLI SUL FILE $STATUS_DIR/rainsensorqty_lastrain
|
||||
# SE SI VERIFICANO LE CONDIZIONI PER CUI SI DEVE INTERROMPERE L'IRRIGAZIONE
|
||||
# DEVI IMPOSTARE last_rain CON IL VALORE $RAIN_GPIO_STATE
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
echo 0 > "$RAINSENSORQTY_FILE_RUN"
|
||||
|
||||
return $state_rain
|
||||
echo $state_rain
|
||||
|
||||
}
|
||||
|
||||
|
||||
83
drv/rainsensorqty/rainsensorqty_monitor.sh
Executable file
83
drv/rainsensorqty/rainsensorqty_monitor.sh
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash -x
|
||||
#
|
||||
# Bash script to measure rainfall
|
||||
# Author: androtto
|
||||
# Url:
|
||||
#
|
||||
#
|
||||
# Scrive un messaggio nel file di log
|
||||
# $1 log da scrivere
|
||||
# 3 parameter expected in order:
|
||||
#$gpio
|
||||
#$RAINSENSORQTY_LOOPSFORSETRAINING
|
||||
#$RAINSENSORQTY_SECSBETWEENRAINEVENT
|
||||
|
||||
function log_write {
|
||||
echo -e "`date`\t\t$1" >> $RAINSENSORQTY_LOG
|
||||
}
|
||||
|
||||
###############
|
||||
# MAIN
|
||||
###############
|
||||
|
||||
if [ ! $# = 3 ] ; then
|
||||
echo "ERROR: 3 parameters expected"
|
||||
fi
|
||||
|
||||
GPIO=$1
|
||||
LOOPSFORSETRAINING=$2
|
||||
SECSBETWEENRAINEVENT=$3
|
||||
|
||||
DIRNAME="$( dirname $0 )"
|
||||
. /etc/piGarden.conf # test sulla presenza del file gia' fatti prima
|
||||
. "$DIRNAME/config.include.sh"
|
||||
|
||||
#got from config file above:
|
||||
#RAINSENSORQTY_LASTRAIN="$STATUS_DIR/rainsensorqty_lastrain"
|
||||
#RAINSENSORQTY_LOG="$DIR_SCRIPT/log/rainsensorqty.log"
|
||||
#RAINSENSORQTY_MONPID="$TMP_PATH/rainsensorqty_monitor.pid"
|
||||
#RAINSENSORQTY_DIR="$DIR_SCRIPT/drv/rainsensorqty"
|
||||
#RAINSENSORQTY_PULSE=falling
|
||||
#RAINSENSORQTY_WAIT=rising
|
||||
|
||||
|
||||
if [[ -f "$RAINSENSORQTY_MONPID" && -z "$RAINSENSORQTY_MONPID" ]] ; then
|
||||
pid=$( < "$RAINSENSORQTY_MONPID" )
|
||||
if ps -fp $pid >/dev/null ; then
|
||||
log_write "ERROR monitor process already running\n$( ps -fp $pid )"
|
||||
exit 1
|
||||
else
|
||||
log_write "no rainmonitor process running"
|
||||
echo $$ > $RAINSENSORQTY_MONPID
|
||||
log_write "$$ pid monitor process - see $RAINSENSORQTY_MONPID"
|
||||
fi
|
||||
fi
|
||||
|
||||
MMEACH=0.303030303
|
||||
|
||||
counter=0
|
||||
|
||||
while true
|
||||
do
|
||||
before=`date +%s`
|
||||
#gpio -g wfi $GPIO $RAINSENSORQTY_PULSE # falling 1->0
|
||||
sleep $(</tmp/secs_to_wait) # for testing only
|
||||
now=`date +%s`
|
||||
(( elapsed = now - before ))
|
||||
if (( elapsed >= $SECSBETWEENRAINEVENT )) ; then
|
||||
counter=0
|
||||
log_write "sono passati $elapsed secondi ( > di $SECSBETWEENRAINEVENT ) dall'ultima precipitazione, reset counter"
|
||||
echo "sono passati $elapsed secondi ( > di $SECSBETWEENRAINEVENT ) dall'ultima precipitazione, reset counter"
|
||||
fi
|
||||
counter=$(( counter+=1 ))
|
||||
MMWATER=$( $JQ -n "$counter*$MMEACH" )
|
||||
log_write "counter $counter - $MMWATER mm acqua"
|
||||
echo "counter $counter - $MMWATER mm acqua"
|
||||
if (( counter >= $LOOPSFORSETRAINING )) ; then
|
||||
log_write "raggiunta acqua per impedire irrigazione: $MMWATER mm"
|
||||
echo "raggiunta acqua per impedire irrigazione: $MMWATER mm"
|
||||
date +%s > ${RAINSENSORQTY_LASTRAIN}
|
||||
date > ${RAINSENSORQTY_LASTRAIN}_date
|
||||
fi
|
||||
#gpio -g wfi $GPIO $RAINSENSORQTY_WAIT # rising 0->1
|
||||
done
|
||||
@@ -1,11 +0,0 @@
|
||||
#
|
||||
# Questa funzione viene invocata dalla funzione "setup_drv" di piGarden ad ogni avvio dello script
|
||||
# e serve per eseguire l'eventuale setup del driver se necessario
|
||||
#
|
||||
function drv_rainsensorqty_setup {
|
||||
|
||||
declare -g RAINSENSORQTY_FILE_RUN
|
||||
RAINSENSORQTY_FILE_RUN="$STATUS_DIR/rainsensorqty_run"
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#
|
||||
# Funzione di esempio
|
||||
#
|
||||
function sample_foo {
|
||||
function drv_sample_foo {
|
||||
|
||||
echo "bar"
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
declare -a list_drv
|
||||
|
||||
#
|
||||
# Funzione eseguita ad ogni avvio di piGarden.sh, si occupa includere tutti i file dei driver utilizzati e di lanciare
|
||||
# la funzione di setup di ogni driver se esistente
|
||||
#
|
||||
function setup_drv {
|
||||
|
||||
#declare -a list_drv
|
||||
list_drv=()
|
||||
|
||||
# Inizializza i driver per le elettrovalvole
|
||||
# Raccoglie i nomi dei driver utilizzati per le elettrovalvole
|
||||
for i in $(seq $EV_TOTAL)
|
||||
do
|
||||
local a=EV"$i"_GPIO
|
||||
@@ -18,7 +22,7 @@ function setup_drv {
|
||||
fi
|
||||
done
|
||||
|
||||
# Inizializza i driver per gli altri gpio
|
||||
# Raccoglie i nomi dei driver utilizzati per gli altri gpio
|
||||
for gpio in "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2" "$RAIN_GPIO" "$WEATHER_SERVICE"
|
||||
do
|
||||
if [[ "$gpio" == drv:* ]]; then
|
||||
@@ -29,6 +33,9 @@ function setup_drv {
|
||||
fi
|
||||
done
|
||||
|
||||
#
|
||||
# Esegue l'unclusione dei file dei driver e per ognuno lancia l'eventuale funzione di setup
|
||||
#
|
||||
local file_drv
|
||||
for drv in "${list_drv[@]}"
|
||||
do
|
||||
|
||||
Reference in New Issue
Block a user