Aggiunto driver 'remote' per gestire da un'installazione master di piGarden più installazioni remote
This commit is contained in:
4
drv/remote/README.md
Normal file
4
drv/remote/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Driver per controllare pigarden remoti in rete da un'installazione pigarden master
|
||||
|
||||
Per maggiori informazioni consulta https://www.lejubila.net/2018/03/pigardent-0-5-5-driver-master-per-implementare-un-architettura-master-slave/
|
||||
|
||||
38
drv/remote/common.include.sh
Normal file
38
drv/remote/common.include.sh
Normal file
@@ -0,0 +1,38 @@
|
||||
#
|
||||
# Funzioni comuni utilizzate dal driver
|
||||
#
|
||||
|
||||
#
|
||||
# Esegue un comando su un pigarden remoto tramite socket
|
||||
#
|
||||
# $1 identificativo pigarden remoto
|
||||
# $2 comando da eseguire
|
||||
#
|
||||
function drv_remote_command {
|
||||
|
||||
local remote="$1"
|
||||
local command="$2"
|
||||
|
||||
local remote_ip_var=$remote"_IP"
|
||||
local remote_port_var=$remote"_PORT"
|
||||
local remote_user_var=$remote"_USER"
|
||||
local remote_pwd_var=$remote"_PWD"
|
||||
|
||||
local remote_ip="${!remote_ip_var}"
|
||||
local remote_port="${!remote_port_var}"
|
||||
local remote_user="${!remote_user_var}"
|
||||
local remote_pwd="${!remote_pwd_var}"
|
||||
|
||||
exec 5<>/dev/tcp/$remote_ip/$remote_port
|
||||
|
||||
if [[ ! -z $remote_user ]] && [[ ! -z $remote_pwd ]]; then
|
||||
command="$remote_user\n$remote_pwd\n$command"
|
||||
fi
|
||||
|
||||
echo -e "$command" >&5
|
||||
|
||||
cat <&5
|
||||
|
||||
}
|
||||
|
||||
|
||||
7
drv/remote/config.include.sh
Normal file
7
drv/remote/config.include.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
# File di configurazione del driver
|
||||
#
|
||||
|
||||
# Dichiarazione variabile di esempio
|
||||
#declare -g SAMPLE_FOO
|
||||
#SAMPLE_FOO="bar"
|
||||
9
drv/remote/init.include.sh
Normal file
9
drv/remote/init.include.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# Questa funzione viene inviocata dalla funzione "init" di piGarden se sono presenti elettrovalvole o sensori che utilizzano questo driver
|
||||
#
|
||||
function drv_remote_init {
|
||||
|
||||
local FOO=bar
|
||||
|
||||
}
|
||||
|
||||
23
drv/remote/rainsensor.include.sh
Normal file
23
drv/remote/rainsensor.include.sh
Normal file
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# Inizializza il sensore di rilevamento pioggia
|
||||
#
|
||||
# $i identificativo gpio del sensore di pioggia
|
||||
#
|
||||
function drv_remote_rain_sensor_init {
|
||||
|
||||
local FOO="bar"
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
# Ritorna lo stato del sensore di rilevamento pioggia
|
||||
#
|
||||
# $i identificativo gpio del sensore di pioggia
|
||||
#
|
||||
function drv_remote_rain_sensor_get {
|
||||
|
||||
local FOO="bar"
|
||||
|
||||
}
|
||||
|
||||
|
||||
76
drv/remote/rele.include.sh
Normal file
76
drv/remote/rele.include.sh
Normal file
@@ -0,0 +1,76 @@
|
||||
#
|
||||
# Inizializzazione rele
|
||||
#
|
||||
# $1 identificativo relè da inizializzare
|
||||
#
|
||||
function drv_remote_rele_init {
|
||||
|
||||
drv_remote_rele_open "$1"
|
||||
}
|
||||
|
||||
#
|
||||
# Apertura rele
|
||||
#
|
||||
# $1 identificativo relè da aprire (chiude l'elettrovalvola)
|
||||
#
|
||||
function drv_remote_rele_open {
|
||||
|
||||
local remote=`echo $1 | $CUT -d':' -f3,3`
|
||||
local remote_alias=`echo $1 | $CUT -d':' -f4,4`
|
||||
|
||||
local command="close $remote_alias"
|
||||
|
||||
echo "remote=$remote"
|
||||
echo "remote_alias=$remote_alias"
|
||||
echo "command=$command"
|
||||
|
||||
local response=$(drv_remote_command "$remote" "$command")
|
||||
|
||||
echo "response=$response"
|
||||
|
||||
local result=$(echo $response|$JQ -M ".error.description")
|
||||
echo "result=$result"
|
||||
if [[ "$result" != "\"\"" ]]; then
|
||||
local error=$result
|
||||
error="${error%\"}"
|
||||
error="${error#\"}"
|
||||
echo "error=$error"
|
||||
log_write "Remote rele open error: $error"
|
||||
message_write "warning" "Remote rele open error: $error"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Chiusura rele
|
||||
#
|
||||
# $1 identificativo relè da chiudere (apre l'elettrovalvola)
|
||||
#
|
||||
function drv_remote_rele_close {
|
||||
|
||||
local remote=`echo $1 | $CUT -d':' -f3,3`
|
||||
local remote_alias=`echo $1 | $CUT -d':' -f4,4`
|
||||
|
||||
local command="open $remote_alias force"
|
||||
|
||||
echo "remote=$remote"
|
||||
echo "remote_alias=$remote_alias"
|
||||
echo "command=$command"
|
||||
|
||||
local response=$(drv_remote_command "$remote" "$command")
|
||||
|
||||
echo "response=$response"
|
||||
|
||||
local result=`echo $response|$JQ -M ".error.description"`
|
||||
echo "result=$result"
|
||||
if [[ "$result" != "\"\"" ]]; then
|
||||
local error=$result
|
||||
error="${error%\"}"
|
||||
error="${error#\"}"
|
||||
echo "error=$error"
|
||||
log_write "Remote rele open error: $error"
|
||||
message_write "warning" "Remote rele open error: $error"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
27
drv/remote/setup.include.sh
Normal file
27
drv/remote/setup.include.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# Questa funzione viene invocata dalla funzione "setup_drv" di piGarden ad ogni avvio dello script
|
||||
# e serve per eseguire l'evenutale setup del driver se necessario
|
||||
#
|
||||
function drv_remote_setup {
|
||||
|
||||
local all_remote=0
|
||||
|
||||
# Imposta le zone come remote
|
||||
for i in $(seq $EV_TOTAL)
|
||||
do
|
||||
local a=EV"$i"_GPIO
|
||||
local gpio="${!a}"
|
||||
if [[ "$gpio" == drv:remote:* ]]; then
|
||||
local varname=EV"$i"_REMOTE
|
||||
declare -g $varname=1
|
||||
all_remote=$((all_remote+1))
|
||||
fi
|
||||
done
|
||||
|
||||
# Se tutte le zone sono remote disabilita la gestione dell'alimentazione bistabile
|
||||
if [ $all_remote -eq $EV_TOTAL ]; then
|
||||
EV_MONOSTABLE=1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
34
drv/remote/supply.include.sh
Normal file
34
drv/remote/supply.include.sh
Normal file
@@ -0,0 +1,34 @@
|
||||
#
|
||||
# Inizializza i rele che gestiscono l'alimentazione per le valvole bistabili
|
||||
#
|
||||
# $1 identificativo relè
|
||||
#
|
||||
function drv_remote_supply_bistable_init {
|
||||
|
||||
local FOO="bar"
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
# Imposta l'alimentazione delle elettrovalvole con voltaggio positivo
|
||||
#
|
||||
# $1 identificativo relè
|
||||
#
|
||||
function drv_remote_supply_positive {
|
||||
|
||||
local FOO="bar"
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
# Imposta l'alimentazione delle elettrovalvole con voltaggio negativo
|
||||
#
|
||||
# $1 identificativo relè
|
||||
#
|
||||
function drv_remote_supply_negative {
|
||||
|
||||
local FOO="bar"
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user