Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3239006922 | ||
|
|
24baa97dad | ||
|
|
c354f72c0c | ||
|
|
6f80b8ea21 | ||
|
|
87edbbbe7a | ||
|
|
3eb45fd1e9 |
@@ -1,3 +1,6 @@
|
||||
# 0.5.7 - 01/06/2018
|
||||
- Added "sonoff_tasmota_http" driver for interfacin with Sonoff module with Tasmota firmware over http protocol
|
||||
|
||||
# 0.5.6 - 04/05/2018
|
||||
- Added events ev_not_open_for_rain, ev_not_open_for_rain_sensor, ev_not_open_for_rain_online
|
||||
- Added script rpinotify.sh for notificate events to telegram
|
||||
|
||||
@@ -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
|
||||
|
||||
141
conf/piGarden.conf.sonoff_tasmota_http.example
Normal file
141
conf/piGarden.conf.sonoff_tasmota_http.example
Normal file
@@ -0,0 +1,141 @@
|
||||
# Log file
|
||||
LOG_FILE="/home/pi/piGarden/log/piGarden.log"
|
||||
LOG_FILE_MAX_SIZE=1048576 # 1MB
|
||||
|
||||
# Log file for driver output
|
||||
#LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log"
|
||||
|
||||
# Status directory
|
||||
STATUS_DIR="/home/pi/piGarden/state"
|
||||
|
||||
# Event directory
|
||||
EVENT_DIR="/home/pi/piGarden/events"
|
||||
|
||||
# Posizione gpio
|
||||
GPIO="/usr/local/bin/gpio"
|
||||
|
||||
# Posizione js
|
||||
JQ="/usr/local/bin/jq"
|
||||
|
||||
# Percorso curl
|
||||
CURL="/usr/bin/curl"
|
||||
|
||||
# Percorso wc
|
||||
WC="/usr/bin/wc"
|
||||
|
||||
# Percorso gzip
|
||||
GZIP="/bin/gzip"
|
||||
|
||||
# Percorso mv
|
||||
MV="/bin/mv"
|
||||
|
||||
# Percorso di tr
|
||||
TR="/usr/bin/tr"
|
||||
|
||||
# Percorso di cut
|
||||
CUT="/usr/bin/cut"
|
||||
|
||||
# Percorso tcpserver
|
||||
TCPSERVER="/usr/bin/tcpserver"
|
||||
|
||||
# Percorso cron
|
||||
CRONTAB="/usr/bin/crontab"
|
||||
|
||||
# Percorso grep
|
||||
GREP="/bin/grep"
|
||||
|
||||
# Percorsp sed
|
||||
SED="/bin/sed"
|
||||
|
||||
# Percorso readlink
|
||||
READLINK="/bin/readlink"
|
||||
|
||||
# Percorso stat
|
||||
STAT="/usr/bin/stat"
|
||||
|
||||
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
||||
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
||||
EV_MONOSTABLE=0
|
||||
|
||||
# Id gpio usati per simulare il doppio deviatore con cui eseguire l'alimentazione alle elettrovalvole
|
||||
SUPPLY_GPIO_1=2
|
||||
SUPPLY_GPIO_2=3
|
||||
|
||||
# Stato dei due gpio per impartire l'alimentazione positiva alle elettrovalvole (aperta)
|
||||
SUPPLY_GPIO_POS=0
|
||||
|
||||
# Stato dei due gpio per impartire l'alimentazione negativa alle elettrovalvole (chiusa)
|
||||
SUPPLY_GPIO_NEG=1
|
||||
|
||||
# Stato di ingresso da assegnare al gpio per chiudere il rele
|
||||
RELE_GPIO_CLOSE=0
|
||||
|
||||
# Stato di ingresso da assegnare al gpio per aprire il rele
|
||||
RELE_GPIO_OPEN=1
|
||||
|
||||
# Id del gpio usato per collegare il sensore di rilevamento pioggia
|
||||
RAIN_GPIO=25 # Physical 22 - wPi 6
|
||||
|
||||
# Valore in ingresso sul gpio definito in RAIN_GPIO che indica lo stato di pioggia
|
||||
RAIN_GPIO_STATE=0
|
||||
|
||||
|
||||
|
||||
|
||||
# Numero totale di elettrovalvole
|
||||
EV_TOTAL=4
|
||||
|
||||
# Definizione delle elettrovalvole
|
||||
EV1_ALIAS="Giardino_Posteriore_DX"
|
||||
EV1_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power1"
|
||||
EV1_MONOSTABLE=1
|
||||
|
||||
EV2_ALIAS="Giardino_Posteriore_CN"
|
||||
EV2_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power2"
|
||||
EV2_MONOSTABLE=1
|
||||
|
||||
EV3_ALIAS="Giardino_Posteriore_SX"
|
||||
EV3_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power3"
|
||||
EV3_MONOSTABLE=1
|
||||
|
||||
EV4_ALIAS="Giardino_Anteriore"
|
||||
EV4_GPIO="drv:sonoff_tasmota_http:SONOFF2:Power1"
|
||||
|
||||
|
||||
# Definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||
WUNDERGROUND_KEY=""
|
||||
WUNDERGROUND_LOCATION="IT/Pieve%20a%20Nievole" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||
|
||||
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
||||
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||
NOT_IRRIGATE_IF_RAIN_ONLINE=86400
|
||||
|
||||
# Il parametro è simile a quello precedente, il controllo però anziché essere fatto attingendo a wunderground, viene eseguito direttamente sul sensore se installato. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||
NOT_IRRIGATE_IF_RAIN_SENSOR=86400
|
||||
|
||||
# Indirizzo ip e porta di ascolto del socket server
|
||||
TCPSERVER_IP="127.0.0.1"
|
||||
TCPSERVER_PORT="8084"
|
||||
|
||||
# Utente e password che i clients devono utilizzare per stabilire una connessione tramite socket server
|
||||
TCPSERVER_USER=""
|
||||
TCPSERVER_PWD=""
|
||||
|
||||
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
||||
NO_SEND_IDENTIFIER=0
|
||||
|
||||
|
||||
#
|
||||
# Configurazione moduli sonoff
|
||||
#
|
||||
SONOFF1_IP="192.168.1.1"
|
||||
SONOFF1_USER="user"
|
||||
SONOFF1_PWD="pwd"
|
||||
|
||||
SONOFF2_IP="192.168.1.21"
|
||||
SONOFF2_USER=""
|
||||
SONOFF2_PWD=""
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
# Driver per controllare pigarden remoti in rete da un'installazione pigarden master
|
||||
# Driver for controlling remote pigarden on the network from a pigarden master installation
|
||||
|
||||
Per maggiori informazioni consulta https://www.lejubila.net/2018/03/pigardent-0-5-5-driver-master-per-implementare-un-architettura-master-slave/
|
||||
For more information see https://www.lejubila.net/2018/03/pigardent-0-5-5-driver-master-per-implementare-un-architettura-master-slave/
|
||||
|
||||
# Example of zone configuration in piGarden.conf
|
||||
|
||||
EV1_ALIAS="Giarino_Posteriore_DX" #
|
||||
EV1_GPIO="drv:remote:PIREMOTE1:Giardino_Posteriore_DX"
|
||||
|
||||
PIREMOTE1_IP="192.168.1.51"
|
||||
PIREMOTE1_PORT="8084"
|
||||
PIREMOTE1_USER=""
|
||||
PIREMOTE1_PWD=""
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
21
drv/sonoff_tasmota_http/README.md
Normal file
21
drv/sonoff_tasmota_http/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Driver for controlling Sonoff remote relays with Tasmota firmware via http protocol
|
||||
|
||||
More information on Sonoff Tasmota firmware: https://github.com/arendst/Sonoff-Tasmota
|
||||
|
||||
|
||||
# Example of zone configuration in piGarden.conf
|
||||
|
||||
EV1_ALIAS="Giardino_Posteriore_DX"
|
||||
EV1_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power1"
|
||||
EV1_MONOSTABLE=1
|
||||
|
||||
EV2_ALIAS="Giardino_Posteriore_CN"
|
||||
EV2_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power2"
|
||||
EV2_MONOSTABLE=1
|
||||
|
||||
SONOFF1_IP="192.168.1.1"
|
||||
SONOFF1_USER="user"
|
||||
SONOFF1_PWD="pwd"
|
||||
|
||||
More information for configuration: https://www.lejubila.net/2018/06/pigarden-0-5-7-gestisci-le-tue-elettrovalvole-con-i-moduli-sonoff-grazie-al-nuovo-driver-sonoff_tasmota_http
|
||||
|
||||
50
drv/sonoff_tasmota_http/common.include.sh
Normal file
50
drv/sonoff_tasmota_http/common.include.sh
Normal file
@@ -0,0 +1,50 @@
|
||||
#
|
||||
# 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://$remote_ip/cm"
|
||||
local credentials=""
|
||||
local response=""
|
||||
|
||||
if [[ ! -z $remote_user ]] && [[ ! -z $remote_pwd ]]; then
|
||||
credentials="user=$remote_user&password=$remote_pwd&"
|
||||
fi
|
||||
|
||||
url="$url?$credentials$command"
|
||||
|
||||
echo "url api sonoff: $url" >> "$LOG_OUTPUT_DRV_FILE"
|
||||
|
||||
$CURL --connect-timeout 5 -sb -H "$url"
|
||||
|
||||
local res=$?
|
||||
|
||||
echo "curl code response: $res" >> "$LOG_OUTPUT_DRV_FILE"
|
||||
|
||||
if [ "$res" != "0" ]; then
|
||||
echo "The curl command failed with: $res - url: $url"
|
||||
fi
|
||||
|
||||
#echo "{\"POWER1\":\"ON\"}"
|
||||
|
||||
}
|
||||
|
||||
|
||||
7
drv/sonoff_tasmota_http/config.include.sh
Normal file
7
drv/sonoff_tasmota_http/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/sonoff_tasmota_http/init.include.sh
Normal file
9
drv/sonoff_tasmota_http/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_sonoff_tasmota_http_init {
|
||||
|
||||
local FOO=bar
|
||||
|
||||
}
|
||||
|
||||
23
drv/sonoff_tasmota_http/rainsensor.include.sh
Normal file
23
drv/sonoff_tasmota_http/rainsensor.include.sh
Normal 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"
|
||||
|
||||
}
|
||||
|
||||
|
||||
78
drv/sonoff_tasmota_http/rele.include.sh
Normal file
78
drv/sonoff_tasmota_http/rele.include.sh
Normal file
@@ -0,0 +1,78 @@
|
||||
#
|
||||
# Inizializzazione rele
|
||||
#
|
||||
# $1 identificativo relè da inizializzare
|
||||
#
|
||||
function drv_sonoff_tasmota_http_rele_init {
|
||||
drv_sonoff_tasmota_http_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 jskey=${remote_alias^^}
|
||||
|
||||
local result=$(echo $response|$JQ -M ".$jskey")
|
||||
echo "result=$result"
|
||||
if [[ "$result" != "\"OFF\"" ]]; then
|
||||
local error="Command error: $response"
|
||||
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 jskey=${remote_alias^^}
|
||||
|
||||
local result=$(echo $response|$JQ -M ".$jskey")
|
||||
echo "result=$result"
|
||||
if [[ "$result" != "\"ON\"" ]]; then
|
||||
local error="Command error: $response"
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
10
drv/sonoff_tasmota_http/setup.include.sh
Normal file
10
drv/sonoff_tasmota_http/setup.include.sh
Normal 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"
|
||||
|
||||
}
|
||||
|
||||
34
drv/sonoff_tasmota_http/supply.include.sh
Normal file
34
drv/sonoff_tasmota_http/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_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"
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -790,7 +792,7 @@ function debug2 {
|
||||
|
||||
VERSION=0
|
||||
SUB_VERSION=5
|
||||
RELEASE_VERSION=6
|
||||
RELEASE_VERSION=7
|
||||
|
||||
DIR_SCRIPT=`dirname $0`
|
||||
NAME_SCRIPT=${0##*/}
|
||||
|
||||
Reference in New Issue
Block a user