Aggiunto prima implementazione del driver sonoff_tesmota_http, aggiunto implementazione parametro EVx_MONOSTABLE per potere definire singolarmente le elettrovamvole monostabili, corretto alcuni commenti

This commit is contained in:
lejubila
2018-05-20 17:14:58 +02:00
parent 7c96a6afd1
commit 3eb45fd1e9
13 changed files with 215 additions and 5 deletions

View File

@@ -90,6 +90,7 @@ EV_TOTAL=6
EV1_ALIAS="1" #
EV1_GPIO=17 # Physical 11 - wPi 0
#EV1_NORAIN=1 # Non interrompe l'irrigazione di questa zona in caso di pioggia
#EV1_MONOSTAVLE=1 # L'elettrovalvola è monostabile
EV2_ALIAS="2" #
EV2_GPIO=27 # Physical 13 - wPi 2

View File

@@ -68,8 +68,8 @@ function drv_remote_rele_close {
error="${error%\"}"
error="${error#\"}"
echo "error=$error"
log_write "Remote rele open error: $error"
message_write "warning" "Remote rele open error: $error"
log_write "Remote rele close error: $error"
message_write "warning" "Remote rele close error: $error"
return 1
fi
}

View File

@@ -1,6 +1,6 @@
#
# 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
# e serve per eseguire l'eventuale setup del driver se necessario
#
function drv_remote_setup {

View File

@@ -1,6 +1,6 @@
#
# 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
# e serve per eseguire l'eventuale setup del driver se necessario
#
function drv_sample_setup {

View File

@@ -0,0 +1,5 @@
# Driver per controllare relè remoti Sonoff con firmware Tasmota tramite protocollo http
Maggiori informazioni sul firmware Sonoff Tasmota: https://github.com/arendst/Sonoff-Tasmota

View File

@@ -0,0 +1,42 @@
#
# Funzioni comuni utilizzate dal driver
#
#
# Invia un comando al modulo sonoff tramite http
#
# $1 identificativo modulo sonoff
# $2 comando da eseguire
#
function drv_sonoff_tasmota_http_command {
local remote="$1"
local command="$2"
local remote_ip_var=$remote"_IP"
local remote_user_var=$remote"_USER"
local remote_pwd_var=$remote"_PWD"
local remote_ip="${!remote_ip_var}"
local remote_user="${!remote_user_var}"
local remote_pwd="${!remote_pwd_var}"
local url="http://$remore_ip/cm"
local credentials=""
local response=""
#$CURL -LI http://$remote_ip/ -o /dev/null -w '%{http_code}\n' -s
if [[ ! -z $remote_user ]] && [[ ! -z $remote_pwd ]]; then
credentials="user=$remote_user&password=$remote_pwd&"
fi
url="$url?$credentials$command"
$CURL -sb -H "$url"
#$CURL -LI $url -o /dev/null -w '%{http_code}\n' -s
}

View File

@@ -0,0 +1,7 @@
#
# File di configurazione del driver
#
# Dichiarazione variabile di esempio
#declare -g SAMPLE_FOO
#SAMPLE_FOO="bar"

View 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_sonoff_tasmota_http_init {
local FOO=bar
}

View File

@@ -0,0 +1,23 @@
#
# Inizializza il sensore di rilevamento pioggia
#
# $i identificativo gpio del sensore di pioggia
#
function drv_sonoff_tasmota_http_rain_sensor_init {
local FOO="bar"
}
#
# Ritorna lo stato del sensore di rilevamento pioggia
#
# $i identificativo gpio del sensore di pioggia
#
function drv_sonoff_tasmota_http_rain_sensor_get {
local FOO="bar"
}

View File

@@ -0,0 +1,77 @@
#
# 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_sonoff_tasmota_http_rele_open {
local remote=`echo $1 | $CUT -d':' -f3,3`
local remote_alias=`echo $1 | $CUT -d':' -f4,4`
local command="cmnd=$remote_alias%20Off"
echo "remote=$remote"
echo "remote_alias=$remote_alias"
echo "command=$command"
local response=$(drv_sonoff_tasmota_http_command "$remote" "$command")
echo "response=$response"
local result=$(echo $response|$JQ -M ".$remore_alias")
echo "result=$result"
if [[ "$result" != "\"Off\"" ]]; then
local error="Command 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_sonoff_tasmota_http_rele_close {
local remote=`echo $1 | $CUT -d':' -f3,3`
local remote_alias=`echo $1 | $CUT -d':' -f4,4`
local command="cmnd=$remote_alias%20On"
echo "remote=$remote"
echo "remote_alias=$remote_alias"
echo "command=$command"
local response=$(drv_sonoff_tasmota_http_command "$remote" "$command")
echo "response=$response"
local result=$(echo $response|$JQ -M ".$remore_alias")
echo "result=$result"
if [[ "$result" != "\"On\"" ]]; then
local error="Command error: $result"
error="${error%\"}"
error="${error#\"}"
echo "error=$error"
log_write "Remote rele close error: $error"
message_write "warning" "Remote rele close error: $error"
return 1
fi
}

View File

@@ -0,0 +1,10 @@
#
# 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_sonoff_tasmota_http_setup {
local FOO="bar"
}

View File

@@ -0,0 +1,34 @@
#
# Inizializza i rele che gestiscono l'alimentazione per le valvole bistabili
#
# $1 identificativo relè
#
function drv_sonoff_tasmota_http_supply_bistable_init {
drv_sonoff_tasmota_http_supply_negative "$1"
}
#
# Imposta l'alimentazione delle elettrovalvole con voltaggio positivo
#
# $1 identificativo relè
#
function drv_sonoff_tasmota_http_supply_positive {
drv_sonoff_tasmota_http_rele_open "$1"
}
#
# Imposta l'alimentazione delle elettrovalvole con voltaggio negativo
#
# $1 identificativo relè
#
function drv_sonoff_tasmota_http_supply_negative {
drv_sonoff_tasmota_http_rele_close "$1"
}

View File

@@ -85,6 +85,8 @@ function ev_open {
local EVNORAIN=`ev_number2norain $EVNUM`
local EV_IS_REMOTE_VAR=EV"$EVNUM"_REMOTE
local EV_IS_REMOTE=${!EV_IS_REMOTE_VAR}
local EV_IS_MONOSTAVLE_VAR=EV"$EVNUM"_MONOSTABLE
local EV_IS_MONOSTAVLE=${!EV_IS_MONOSTAVLE_VAR}
if [ ! "$2" = "force" ] && [ "$EVNORAIN" != "1" ]; then
if [[ "$NOT_IRRIGATE_IF_RAIN_ONLINE" -gt 0 && -f $STATUS_DIR/last_rain_online ]]; then
@@ -132,7 +134,7 @@ function ev_open {
lock
# Gestisce l'apertura dell'elettrovalvola in base alla tipologia (monostabile / bistabile)
if [ "$EV_MONOSTABLE" == "1" ] || [ "$EV_IS_REMOTE" == "1" ]; then
if [ "$EV_MONOSTABLE" == "1" ] || [ "$EV_IS_REMOTE" == "1" ] || [ "$EV_IS_MONOSTABLE" == "1" ]; then
drv_rele_close "$g"
if [ $? -eq 1 ]; then
unlock