Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d324faf8bb | ||
|
|
383cbc44a9 | ||
|
|
9864709b44 | ||
|
|
6d8c82f0a3 | ||
|
|
a997081aa9 | ||
|
|
c145171306 | ||
|
|
e9a676188f | ||
|
|
0d748031fd | ||
|
|
3ed46d80ad | ||
|
|
05a73720bb | ||
|
|
fc717f18a2 | ||
|
|
50117a5a96 | ||
|
|
309c209b1b | ||
|
|
9a81f0fbba |
@@ -1,4 +1,10 @@
|
|||||||
# 0.5.8 - xx/07/2018
|
# 0.5.10 - 11/11/2018
|
||||||
|
- Fix bug in single monostable solenodid management caused from wrong variable name EV_IS_MONOSTAVLE
|
||||||
|
|
||||||
|
# 0.5.9 - 01/11/2018
|
||||||
|
- Added mqtt support for publishing status to broker
|
||||||
|
|
||||||
|
# 0.5.8 - 19/07/2018
|
||||||
- Added "openweathermap" driver for impement check weather condition from openweatermap api
|
- Added "openweathermap" driver for impement check weather condition from openweatermap api
|
||||||
|
|
||||||
# 0.5.7 - 01/06/2018
|
# 0.5.7 - 01/06/2018
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ READLINK="/bin/readlink"
|
|||||||
# Percorso stat
|
# Percorso stat
|
||||||
STAT="/usr/bin/stat"
|
STAT="/usr/bin/stat"
|
||||||
|
|
||||||
|
# Percorso mosquito_pub
|
||||||
|
# # Installare con apt install mosquitto-clients
|
||||||
|
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
|
||||||
|
|
||||||
|
|
||||||
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
||||||
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
||||||
EV_MONOSTABLE=0
|
EV_MONOSTABLE=0
|
||||||
@@ -139,3 +144,12 @@ TCPSERVER_PWD=""
|
|||||||
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
||||||
NO_SEND_IDENTIFIER=0
|
NO_SEND_IDENTIFIER=0
|
||||||
|
|
||||||
|
# Parametri connessione al broker mqtt
|
||||||
|
MQTT_ENABLE=0 # set 1 to enable
|
||||||
|
MQTT_HOST=you_host_mqtt
|
||||||
|
MQTT_PORT=1883
|
||||||
|
MQTT_USER=your_user_mqtt
|
||||||
|
MQTT_PWD=yout_password_mqtt
|
||||||
|
MQTT_TOPIC="pigarden/result"
|
||||||
|
MQTT_CLIENT_ID=piGarden
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ READLINK="/bin/readlink"
|
|||||||
# Percorso stat
|
# Percorso stat
|
||||||
STAT="/usr/bin/stat"
|
STAT="/usr/bin/stat"
|
||||||
|
|
||||||
|
# Percorso mosquito_pub
|
||||||
|
# Installare con apt install mosquitto-clients
|
||||||
|
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
|
||||||
|
|
||||||
|
|
||||||
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
||||||
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
||||||
EV_MONOSTABLE=0
|
EV_MONOSTABLE=0
|
||||||
@@ -131,6 +136,15 @@ TCPSERVER_PWD=""
|
|||||||
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
||||||
NO_SEND_IDENTIFIER=0
|
NO_SEND_IDENTIFIER=0
|
||||||
|
|
||||||
|
# Parametri connessione al broker mqtt
|
||||||
|
MQTT_ENABLE=0 # set 1 to enable
|
||||||
|
MQTT_HOST=you_host_mqtt
|
||||||
|
MQTT_PORT=1883
|
||||||
|
MQTT_USER=your_user_mqtt
|
||||||
|
MQTT_PWD=yout_password_mqtt
|
||||||
|
MQTT_TOPIC="pigarden/result"
|
||||||
|
MQTT_CLIENT_ID=piGarden
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Configurazione piGarden remoti
|
# Configurazione piGarden remoti
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ READLINK="/bin/readlink"
|
|||||||
# Percorso stat
|
# Percorso stat
|
||||||
STAT="/usr/bin/stat"
|
STAT="/usr/bin/stat"
|
||||||
|
|
||||||
|
# Percorso mosquito_pub
|
||||||
|
# # Installare con apt install mosquitto-clients
|
||||||
|
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
|
||||||
|
|
||||||
|
|
||||||
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
||||||
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
||||||
EV_MONOSTABLE=0
|
EV_MONOSTABLE=0
|
||||||
@@ -133,6 +138,15 @@ TCPSERVER_PWD=""
|
|||||||
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
||||||
NO_SEND_IDENTIFIER=0
|
NO_SEND_IDENTIFIER=0
|
||||||
|
|
||||||
|
# Parametri connessione al broker mqtt
|
||||||
|
MQTT_ENABLE=0 # set 1 to enable
|
||||||
|
MQTT_HOST=you_host_mqtt
|
||||||
|
MQTT_PORT=1883
|
||||||
|
MQTT_USER=your_user_mqtt
|
||||||
|
MQTT_PWD=yout_password_mqtt
|
||||||
|
MQTT_TOPIC="pigarden/result"
|
||||||
|
MQTT_CLIENT_ID=piGarden
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Configurazione moduli sonoff
|
# Configurazione moduli sonoff
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ READLINK="/bin/readlink"
|
|||||||
# Percorso stat
|
# Percorso stat
|
||||||
STAT="/usr/bin/stat"
|
STAT="/usr/bin/stat"
|
||||||
|
|
||||||
|
# Percorso mosquito_pub
|
||||||
|
# Installare con apt install mosquitto-clients
|
||||||
|
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
|
||||||
|
|
||||||
|
|
||||||
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
||||||
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
||||||
EV_MONOSTABLE=1
|
EV_MONOSTABLE=1
|
||||||
@@ -503,6 +508,15 @@ TCPSERVER_PWD=""
|
|||||||
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
||||||
NO_SEND_IDENTIFIER=0
|
NO_SEND_IDENTIFIER=0
|
||||||
|
|
||||||
|
# Parametri connessione al broker mqtt
|
||||||
|
MQTT_ENABLE=0 # set 1 to enable
|
||||||
|
MQTT_HOST=you_host_mqtt
|
||||||
|
MQTT_PORT=1883
|
||||||
|
MQTT_USER=your_user_mqtt
|
||||||
|
MQTT_PWD=yout_password_mqtt
|
||||||
|
MQTT_TOPIC="pigarden/result"
|
||||||
|
MQTT_CLIENT_ID=piGarden
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Configurazione schede spb16ch
|
# Configurazione schede spb16ch
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
For more information see 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
|
# Example of zone configuration in piGarden.conf
|
||||||
|
```bash
|
||||||
EV1_ALIAS="Giarino_Posteriore_DX" #
|
EV1_ALIAS="Giarino_Posteriore_DX" #
|
||||||
EV1_GPIO="drv:remote:PIREMOTE1:Giardino_Posteriore_DX"
|
EV1_GPIO="drv:remote:PIREMOTE1:Giardino_Posteriore_DX"
|
||||||
|
|
||||||
@@ -11,3 +11,4 @@ PIREMOTE1_IP="192.168.1.51"
|
|||||||
PIREMOTE1_PORT="8084"
|
PIREMOTE1_PORT="8084"
|
||||||
PIREMOTE1_USER=""
|
PIREMOTE1_USER=""
|
||||||
PIREMOTE1_PWD=""
|
PIREMOTE1_PWD=""
|
||||||
|
```
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ More information on Sonoff Tasmota firmware: https://github.com/arendst/Sonoff-T
|
|||||||
|
|
||||||
# Example of zone configuration in piGarden.conf
|
# Example of zone configuration in piGarden.conf
|
||||||
|
|
||||||
|
```bash
|
||||||
EV1_ALIAS="Giardino_Posteriore_DX"
|
EV1_ALIAS="Giardino_Posteriore_DX"
|
||||||
EV1_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power1"
|
EV1_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power1"
|
||||||
EV1_MONOSTABLE=1
|
EV1_MONOSTABLE=1
|
||||||
@@ -16,6 +17,6 @@ EV2_MONOSTABLE=1
|
|||||||
SONOFF1_IP="192.168.1.1"
|
SONOFF1_IP="192.168.1.1"
|
||||||
SONOFF1_USER="user"
|
SONOFF1_USER="user"
|
||||||
SONOFF1_PWD="pwd"
|
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
|
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
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,14 @@ function trigger_event {
|
|||||||
case "$EVENT" in
|
case "$EVENT" in
|
||||||
"ev_open_before" | "ev_open_after")
|
"ev_open_before" | "ev_open_after")
|
||||||
ALIAS="$2"
|
ALIAS="$2"
|
||||||
|
CURRENT_EVENT_ALIAS="$ALIAS"
|
||||||
FORCE="$3"
|
FORCE="$3"
|
||||||
$f "$EVENT" "$ALIAS" "$FORCE" `date +%s` &> /dev/null
|
$f "$EVENT" "$ALIAS" "$FORCE" `date +%s` &> /dev/null
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"ev_open_in_before")
|
"ev_open_in_before")
|
||||||
ALIAS="$2"
|
ALIAS="$2"
|
||||||
|
CURRENT_EVENT_ALIAS="$ALIAS"
|
||||||
FORCE="$3"
|
FORCE="$3"
|
||||||
local MINUTE_START="$4"
|
local MINUTE_START="$4"
|
||||||
local MINUTE_STOP="$5"
|
local MINUTE_STOP="$5"
|
||||||
@@ -31,6 +33,7 @@ function trigger_event {
|
|||||||
|
|
||||||
"ev_open_in_after")
|
"ev_open_in_after")
|
||||||
ALIAS="$2"
|
ALIAS="$2"
|
||||||
|
CURRENT_EVENT_ALIAS="$ALIAS"
|
||||||
FORCE="$3"
|
FORCE="$3"
|
||||||
local CRON_START="$4"
|
local CRON_START="$4"
|
||||||
local CRON_STOP="$5"
|
local CRON_STOP="$5"
|
||||||
@@ -39,6 +42,7 @@ function trigger_event {
|
|||||||
|
|
||||||
"ev_close_before" | "ev_close_after")
|
"ev_close_before" | "ev_close_after")
|
||||||
ALIAS="$2"
|
ALIAS="$2"
|
||||||
|
CURRENT_EVENT_ALIAS="$ALIAS"
|
||||||
$f "$EVENT" "$ALIAS" `date +%s` &> /dev/null
|
$f "$EVENT" "$ALIAS" `date +%s` &> /dev/null
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -89,6 +93,10 @@ function trigger_event {
|
|||||||
|
|
||||||
local ec=$?
|
local ec=$?
|
||||||
#echo "$EVENT ec=$ec" >> /tmp/piGarden.testevent
|
#echo "$EVENT ec=$ec" >> /tmp/piGarden.testevent
|
||||||
|
|
||||||
|
CURRENT_EVENT="$EVENT"
|
||||||
|
mqtt_status &
|
||||||
|
|
||||||
if [ $ec -ne 0 ]; then
|
if [ $ec -ne 0 ]; then
|
||||||
log_write "Stop events chain for exit code $ec in $current_event_dir/$f"
|
log_write "Stop events chain for exit code $ec in $current_event_dir/$f"
|
||||||
return $ec
|
return $ec
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ function socket_server_command {
|
|||||||
|
|
||||||
log_write "socket connection from: $TCPREMOTEIP - command: $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8"
|
log_write "socket connection from: $TCPREMOTEIP - command: $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8"
|
||||||
|
|
||||||
reset_messages &> /dev/null
|
#reset_messages &> /dev/null
|
||||||
|
|
||||||
case "$arg1" in
|
case "$arg1" in
|
||||||
status)
|
status)
|
||||||
@@ -225,7 +225,7 @@ function socket_server_command {
|
|||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
reset_messages &> /dev/null
|
#reset_messages &> /dev/null
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
119
piGarden.sh
119
piGarden.sh
@@ -63,7 +63,7 @@ function initialize {
|
|||||||
#
|
#
|
||||||
# Elimina i file contenente i messaggi da inserire nel json status
|
# Elimina i file contenente i messaggi da inserire nel json status
|
||||||
#
|
#
|
||||||
function reset_messages {
|
function reset_messages_old {
|
||||||
rm -f "$LAST_INFO_FILE.$!"
|
rm -f "$LAST_INFO_FILE.$!"
|
||||||
rm -f "$LAST_WARNING_FILE.$!"
|
rm -f "$LAST_WARNING_FILE.$!"
|
||||||
rm -f "$LAST_SUCCESS_FILE.$!"
|
rm -f "$LAST_SUCCESS_FILE.$!"
|
||||||
@@ -85,8 +85,8 @@ function ev_open {
|
|||||||
local EVNORAIN=`ev_number2norain $EVNUM`
|
local EVNORAIN=`ev_number2norain $EVNUM`
|
||||||
local EV_IS_REMOTE_VAR=EV"$EVNUM"_REMOTE
|
local EV_IS_REMOTE_VAR=EV"$EVNUM"_REMOTE
|
||||||
local EV_IS_REMOTE=${!EV_IS_REMOTE_VAR}
|
local EV_IS_REMOTE=${!EV_IS_REMOTE_VAR}
|
||||||
local EV_IS_MONOSTAVLE_VAR=EV"$EVNUM"_MONOSTABLE
|
local EV_IS_MONOSTABLE_VAR=EV"$EVNUM"_MONOSTABLE
|
||||||
local EV_IS_MONOSTAVLE=${!EV_IS_MONOSTAVLE_VAR}
|
local EV_IS_MONOSTABLE=${!EV_IS_MONOSTAVLE_VAR}
|
||||||
|
|
||||||
if [ ! "$2" = "force" ] && [ "$EVNORAIN" != "1" ]; then
|
if [ ! "$2" = "force" ] && [ "$EVNORAIN" != "1" ]; then
|
||||||
if [[ "$NOT_IRRIGATE_IF_RAIN_ONLINE" -gt 0 && -f $STATUS_DIR/last_rain_online ]]; then
|
if [[ "$NOT_IRRIGATE_IF_RAIN_ONLINE" -gt 0 && -f $STATUS_DIR/last_rain_online ]]; then
|
||||||
@@ -95,10 +95,10 @@ function ev_open {
|
|||||||
local dif=0
|
local dif=0
|
||||||
let "dif = now - last_rain"
|
let "dif = now - last_rain"
|
||||||
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_ONLINE ]; then
|
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_ONLINE ]; then
|
||||||
|
message_write "warning" "Solenoid not open for rain"
|
||||||
trigger_event "ev_not_open_for_rain_online" "$1"
|
trigger_event "ev_not_open_for_rain_online" "$1"
|
||||||
trigger_event "ev_not_open_for_rain" "$1"
|
trigger_event "ev_not_open_for_rain" "$1"
|
||||||
log_write "Solenoid '$1' not open for rain (online check)"
|
log_write "Solenoid '$1' not open for rain (online check)"
|
||||||
message_write "warning" "Solenoid not open for rain"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -110,10 +110,10 @@ function ev_open {
|
|||||||
local dif=0
|
local dif=0
|
||||||
let "dif = now - last_rain"
|
let "dif = now - last_rain"
|
||||||
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_SENSOR ]; then
|
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_SENSOR ]; then
|
||||||
|
message_write "warning" "Solenoid not open for rain"
|
||||||
trigger_event "ev_not_open_for_rain_sensor" "$1"
|
trigger_event "ev_not_open_for_rain_sensor" "$1"
|
||||||
trigger_event "ev_not_open_for_rain" "$1"
|
trigger_event "ev_not_open_for_rain" "$1"
|
||||||
log_write "Solenoid '$1' not open for rain (sensor check)"
|
log_write "Solenoid '$1' not open for rain (sensor check)"
|
||||||
message_write "warning" "Solenoid not open for rain"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -128,6 +128,7 @@ function ev_open {
|
|||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
log_write "Solenoid '$1' not open due to external event"
|
log_write "Solenoid '$1' not open due to external event"
|
||||||
message_write 'warning' "Solenoid not open due to external event"
|
message_write 'warning' "Solenoid not open due to external event"
|
||||||
|
mqtt_status
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -149,12 +150,12 @@ function ev_open {
|
|||||||
|
|
||||||
ev_set_state $EVNUM $state
|
ev_set_state $EVNUM $state
|
||||||
|
|
||||||
|
log_write "Solenoid '$1' open"
|
||||||
|
message_write "success" "Solenoid open"
|
||||||
|
|
||||||
trigger_event "ev_open_after" "$1" "$2"
|
trigger_event "ev_open_after" "$1" "$2"
|
||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
log_write "Solenoid '$1' open"
|
|
||||||
message_write "success" "Solenoid open"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -175,21 +176,25 @@ function ev_open_in {
|
|||||||
if ! [[ $minute_start =~ $re ]] ; then
|
if ! [[ $minute_start =~ $re ]] ; then
|
||||||
echo -e "Time start of irrigation is wrong or not specified"
|
echo -e "Time start of irrigation is wrong or not specified"
|
||||||
message_write "warning" "Time start of irrigation is wrong or not specified"
|
message_write "warning" "Time start of irrigation is wrong or not specified"
|
||||||
|
mqtt_status
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if ! [[ $minute_stop =~ $re ]] ; then
|
if ! [[ $minute_stop =~ $re ]] ; then
|
||||||
echo -e "Time stop of irrigation is wrong or not specified"
|
echo -e "Time stop of irrigation is wrong or not specified"
|
||||||
message_write "warning" "Time stop of irrigation is wrong or not specified"
|
message_write "warning" "Time stop of irrigation is wrong or not specified"
|
||||||
|
mqtt_status
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [ $minute_stop -lt "1" ] ; then
|
if [ $minute_stop -lt "1" ] ; then
|
||||||
echo -e "Time stop of irrigation is wrong"
|
echo -e "Time stop of irrigation is wrong"
|
||||||
message_write "warning" "Time stop of irrigation is wrong"
|
message_write "warning" "Time stop of irrigation is wrong"
|
||||||
|
mqtt_status
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [ "empty$alias" == "empty" ]; then
|
if [ "empty$alias" == "empty" ]; then
|
||||||
echo -e "Alias solenoid not specified"
|
echo -e "Alias solenoid not specified"
|
||||||
message_write "warning" "Alias solenoid not specified"
|
message_write "warning" "Alias solenoid not specified"
|
||||||
|
mqtt_status
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -257,13 +262,13 @@ function ev_close {
|
|||||||
|
|
||||||
ev_set_state $EVNUM 0
|
ev_set_state $EVNUM 0
|
||||||
|
|
||||||
|
log_write "Solenoid '$1' close"
|
||||||
|
message_write "success" "Solenoid close"
|
||||||
|
|
||||||
trigger_event "ev_close_after" "$1"
|
trigger_event "ev_close_after" "$1"
|
||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
log_write "Solenoid '$1' close"
|
|
||||||
message_write "success" "Solenoid close"
|
|
||||||
|
|
||||||
cron_del open_in_stop $1 > /dev/null 2>&1
|
cron_del open_in_stop $1 > /dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,6 +308,20 @@ function log_write {
|
|||||||
# $2 messaggio
|
# $2 messaggio
|
||||||
#
|
#
|
||||||
function message_write {
|
function message_write {
|
||||||
|
local file_message=""
|
||||||
|
if [ "$1" = 'info' ]; then
|
||||||
|
MESSAGE_INFO="$2"
|
||||||
|
elif [ "$1" = "warning" ]; then
|
||||||
|
MESSAGE_WARNING="$2"
|
||||||
|
elif [ "$1" = "success" ]; then
|
||||||
|
MESSAGE_SUCCESS="$2"
|
||||||
|
else
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function message_write_old {
|
||||||
local file_message=""
|
local file_message=""
|
||||||
if [ "$1" = 'info' ]; then
|
if [ "$1" = 'info' ]; then
|
||||||
file_message="$LAST_INFO_FILE.$!"
|
file_message="$LAST_INFO_FILE.$!"
|
||||||
@@ -351,6 +370,7 @@ function gpio_alias2number {
|
|||||||
|
|
||||||
log_write "ERROR solenoid alias not found: $1"
|
log_write "ERROR solenoid alias not found: $1"
|
||||||
message_write "warning" "Solenoid alias not found"
|
message_write "warning" "Solenoid alias not found"
|
||||||
|
mqtt_status
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,6 +390,7 @@ function ev_alias2number {
|
|||||||
|
|
||||||
log_write "ERROR solenoid alias not found: $1"
|
log_write "ERROR solenoid alias not found: $1"
|
||||||
message_write "warning" "Solenoid alias not found"
|
message_write "warning" "Solenoid alias not found"
|
||||||
|
mqtt_status
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,6 +513,12 @@ function json_status {
|
|||||||
local last_success=""
|
local last_success=""
|
||||||
local with_get_cron="0"
|
local with_get_cron="0"
|
||||||
local with_get_cron_open_in="0"
|
local with_get_cron_open_in="0"
|
||||||
|
local current_pid=$!
|
||||||
|
local json_event="\"event\": {\"event\": \"$CURRENT_EVENT\", \"alias\": \"$CURRENT_EVENT_ALIAS\"}"
|
||||||
|
|
||||||
|
if [ "$PARENT_PID" -gt "0" ]; then
|
||||||
|
current_pid=$PARENT_PID
|
||||||
|
fi
|
||||||
|
|
||||||
local vret=""
|
local vret=""
|
||||||
for i in $1 $2 $3 $4 $5 $6
|
for i in $1 $2 $3 $4 $5 $6
|
||||||
@@ -516,7 +543,8 @@ function json_status {
|
|||||||
if [ -n "$json" ]; then
|
if [ -n "$json" ]; then
|
||||||
json="$json,"
|
json="$json,"
|
||||||
fi
|
fi
|
||||||
json="$json\"$i\":{\"name\":\"$av\",\"state\":$sv}"
|
#json="$json\"$i\":{\"name\":\"$av\",\"state\":$sv}"
|
||||||
|
json="$json\"$av\":{\"name\":\"$av\",\"state\":$sv}"
|
||||||
done
|
done
|
||||||
json="\"zones\":{$json}"
|
json="\"zones\":{$json}"
|
||||||
|
|
||||||
@@ -527,15 +555,18 @@ function json_status {
|
|||||||
if [[ ! -z "$last_weather_online" ]]; then
|
if [[ ! -z "$last_weather_online" ]]; then
|
||||||
json_last_weather_online=$last_weather_online
|
json_last_weather_online=$last_weather_online
|
||||||
fi
|
fi
|
||||||
if [ -f "$LAST_INFO_FILE.$!" ]; then
|
#if [ -f "$LAST_INFO_FILE.$current_pid" ]; then
|
||||||
last_info=`cat "$LAST_INFO_FILE.$!"`
|
# last_info=`cat "$LAST_INFO_FILE.$current_pid"`
|
||||||
fi
|
#fi
|
||||||
if [ -f "$LAST_WARNING_FILE.$!" ]; then
|
#if [ -f "$LAST_WARNING_FILE.$current_pid" ]; then
|
||||||
last_warning=`cat "$LAST_WARNING_FILE.$!"`
|
# last_warning=`cat "$LAST_WARNING_FILE.$current_pid"`
|
||||||
fi
|
#fi
|
||||||
if [ -f "$LAST_SUCCESS_FILE.$!" ]; then
|
#if [ -f "$LAST_SUCCESS_FILE.$current_pid" ]; then
|
||||||
last_success=`cat "$LAST_SUCCESS_FILE.$!"`
|
# last_success=`cat "$LAST_SUCCESS_FILE.$current_pid"`
|
||||||
fi
|
#fi
|
||||||
|
last_info="$MESSAGE_INFO"
|
||||||
|
last_warning="$MESSAGE_WARNING"
|
||||||
|
last_success="$MESSAGE_SUCCESS"
|
||||||
local json_last_weather_online="\"last_weather_online\":$json_last_weather_online"
|
local json_last_weather_online="\"last_weather_online\":$json_last_weather_online"
|
||||||
local json_last_rain_sensor="\"last_rain_sensor\":\"$last_rain_sensor\""
|
local json_last_rain_sensor="\"last_rain_sensor\":\"$last_rain_sensor\""
|
||||||
local json_last_rain_online="\"last_rain_online\":\"$last_rain_online\""
|
local json_last_rain_online="\"last_rain_online\":\"$last_rain_online\""
|
||||||
@@ -608,8 +639,9 @@ function json_status {
|
|||||||
json_get_cron_open_in="\"open_in\": {$values_open_in},\"open_in_stop\": {$values_open_in_stop}"
|
json_get_cron_open_in="\"open_in\": {$values_open_in},\"open_in_stop\": {$values_open_in_stop}"
|
||||||
fi
|
fi
|
||||||
local json_cron_open_in="\"cron_open_in\":{$json_get_cron_open_in}"
|
local json_cron_open_in="\"cron_open_in\":{$json_get_cron_open_in}"
|
||||||
|
local json_timestamp="\"timestamp\": $(date +%s)"
|
||||||
|
|
||||||
json="{$json_version,$json,$json_last_weather_online,$json_error,$json_last_info,$json_last_warning,$json_last_success,$json_last_rain_online,$json_last_rain_sensor,$json_cron,$json_cron_open_in}"
|
json="{$json_version,$json_timestamp,$json_event,$json,$json_last_weather_online,$json_error,$json_last_info,$json_last_warning,$json_last_success,$json_last_rain_online,$json_last_rain_sensor,$json_cron,$json_cron_open_in}"
|
||||||
|
|
||||||
echo "$json"
|
echo "$json"
|
||||||
|
|
||||||
@@ -617,6 +649,26 @@ function json_status {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Invia al broker mqtt il json contentente lo stato del sistema
|
||||||
|
#
|
||||||
|
# $1 parent pid (opzionale)
|
||||||
|
#
|
||||||
|
function mqtt_status {
|
||||||
|
|
||||||
|
if [ ! $MQTT_ENABLE -eq 1 ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -z "$1" ]; then
|
||||||
|
PARENT_PID=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local js=$(json_status)
|
||||||
|
$MOSQUITTO_PUB -h $MQTT_HOST -p $MQTT_PORT -u $MQTT_USER -P $MQTT_PWD -i $MQTT_CLIENT_ID -r -t "$MQTT_TOPIC" -m "$js"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Mostra il i parametri dello script
|
# Mostra il i parametri dello script
|
||||||
#
|
#
|
||||||
@@ -632,6 +684,7 @@ function show_usage {
|
|||||||
echo -e "\t$NAME_SCRIPT ev_status alias show status solenoid"
|
echo -e "\t$NAME_SCRIPT ev_status alias show status solenoid"
|
||||||
echo -e "\t$NAME_SCRIPT ev_status_all show status solenoids"
|
echo -e "\t$NAME_SCRIPT ev_status_all show status solenoids"
|
||||||
echo -e "\t$NAME_SCRIPT json_status [get_cron|get_cron_open_in] show status in json format"
|
echo -e "\t$NAME_SCRIPT json_status [get_cron|get_cron_open_in] show status in json format"
|
||||||
|
echo -e "\t$NAME_SCRIPT mqtt_status send status in json format to mqtt broker"
|
||||||
echo -e "\t$NAME_SCRIPT check_rain_online check rain from http://api.wunderground.com/"
|
echo -e "\t$NAME_SCRIPT check_rain_online check rain from http://api.wunderground.com/"
|
||||||
echo -e "\t$NAME_SCRIPT check_rain_sensor check rain from hardware sensor"
|
echo -e "\t$NAME_SCRIPT check_rain_sensor check rain from hardware sensor"
|
||||||
echo -e "\t$NAME_SCRIPT close_all_for_rain close all solenoid if it's raining"
|
echo -e "\t$NAME_SCRIPT close_all_for_rain close all solenoid if it's raining"
|
||||||
@@ -880,7 +933,7 @@ function debug2 {
|
|||||||
|
|
||||||
VERSION=0
|
VERSION=0
|
||||||
SUB_VERSION=5
|
SUB_VERSION=5
|
||||||
RELEASE_VERSION=8
|
RELEASE_VERSION=10
|
||||||
|
|
||||||
DIR_SCRIPT=`dirname $0`
|
DIR_SCRIPT=`dirname $0`
|
||||||
NAME_SCRIPT=${0##*/}
|
NAME_SCRIPT=${0##*/}
|
||||||
@@ -908,9 +961,17 @@ fi
|
|||||||
. "$DIR_SCRIPT/include/rain.include.sh"
|
. "$DIR_SCRIPT/include/rain.include.sh"
|
||||||
. "$DIR_SCRIPT/include/events.include.sh"
|
. "$DIR_SCRIPT/include/events.include.sh"
|
||||||
|
|
||||||
LAST_INFO_FILE="$STATUS_DIR/last_info"
|
#LAST_INFO_FILE="$STATUS_DIR/last_info"
|
||||||
LAST_WARNING_FILE="$STATUS_DIR/last_warning"
|
#LAST_WARNING_FILE="$STATUS_DIR/last_warning"
|
||||||
LAST_SUCCESS_FILE="$STATUS_DIR/last_success"
|
#LAST_SUCCESS_FILE="$STATUS_DIR/last_success"
|
||||||
|
MESSAGE_INFO=""
|
||||||
|
MESSAGE_WARNING=""
|
||||||
|
MESSAGE_SUCCESS=""
|
||||||
|
|
||||||
|
CURRENT_EVENT=""
|
||||||
|
CURRENT_EVENT_ALIAS=""
|
||||||
|
|
||||||
|
PARENT_PID=0
|
||||||
|
|
||||||
if [ -z $LOG_OUTPUT_DRV_FILE ]; then
|
if [ -z $LOG_OUTPUT_DRV_FILE ]; then
|
||||||
LOG_OUTPUT_DRV_FILE="/dev/null"
|
LOG_OUTPUT_DRV_FILE="/dev/null"
|
||||||
@@ -981,6 +1042,10 @@ case "$1" in
|
|||||||
json_status $2 $3 $4 $5 $6
|
json_status $2 $3 $4 $5 $6
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
mqtt_status)
|
||||||
|
mqtt_status $2
|
||||||
|
;;
|
||||||
|
|
||||||
check_rain_online)
|
check_rain_online)
|
||||||
check_rain_online
|
check_rain_online
|
||||||
;;
|
;;
|
||||||
@@ -1122,4 +1187,4 @@ esac
|
|||||||
rm "$TMP_CRON_FILE" 2> /dev/null
|
rm "$TMP_CRON_FILE" 2> /dev/null
|
||||||
rm "$TMP_CRON_FILE-2" 2> /dev/null
|
rm "$TMP_CRON_FILE-2" 2> /dev/null
|
||||||
|
|
||||||
reset_messages &> /dev/null
|
#reset_messages &> /dev/null
|
||||||
|
|||||||
Reference in New Issue
Block a user