16 Commits

Author SHA1 Message Date
lejubila
9d9ef42679 Aggiornato numero versione 2018-11-13 12:47:26 +01:00
lejubila
70c4e063f8 corretto bug su driver openweathermap che in alcuni casi causa una malformazione dello status json e impediva la comunicazione con piGardenWeb 2018-11-13 12:45:28 +01:00
lejubila
4d4b35c3cc corretto bug su driver openweathermap che in alcuni casi causa una malformazione dello status json e impediva la comunicazione con piGardenWeb 2018-11-13 12:43:26 +01:00
lejubila
71e91cc861 Corretto bug che impediva la pubblicazione del topic mqtt per ogni evento 2018-11-12 23:15:34 +01:00
lejubila
a76c797b22 Corretto nome variabile errata EV1_MONOSTAVLE nel file di configurazione 2018-11-11 15:34:28 +01:00
lejubila
07a594e799 aggiunto possibilità di disabilitare servizio meteo online 2018-11-11 11:57:59 +01:00
lejubila
dfa68c2b83 Implementato possibilità di disabilitare servizio meteo online impostando il valore none in WEATHER_SERVICE 2018-11-11 11:49:35 +01:00
lejubila
e284bbcb25 Fix bug in single monostable solenodid management caused from wrong variable name EV_IS_MONOSTAVLE 2018-11-11 11:14:28 +01:00
lejubila
d324faf8bb Fix bug in single monostable solenodid management caused from wrong variable name EV_IS_MONOSTAVLE 2018-11-11 10:13:21 +01:00
lejubila
383cbc44a9 Fix bug in single monostable solenodid management caused from wrong variable name EV_IS_MONOSTAVLE 2018-11-11 10:09:02 +01:00
lejubila
9864709b44 Cambiato changelog 2018-11-01 12:03:07 +01:00
lejubila
6d8c82f0a3 Modificato gestione di invio messaggi tramite socket server 2018-10-14 22:47:43 +02:00
lejubila
a997081aa9 Rimosso mqttconnector 2018-09-22 08:23:13 +02:00
lejubila
c145171306 Aggiunto nel json_status il tipo di evento attualmente triggerato 2018-09-22 08:20:54 +02:00
lejubila
e9a676188f Aggiunto supporto mqtt per la pubblicazione dello stato in formato json verso il broker 2018-09-20 10:53:40 +02:00
lejubila
0d748031fd variato file di configurazione di mqttconnector 2018-08-15 12:09:47 +02:00
14 changed files with 201 additions and 197 deletions

View File

@@ -1,3 +1,16 @@
# 0.5.12 - 13/11/2018
- Fixed a bug that prevented the publication of the mqtt topic for each event
- Fixed a bug on openweathermap driver which in some cases causes a malformation of the json status and prevented communication with piGardenWeb
# 0.5.11 - 11/11/2018
- Added ability to disable online weather service by defining WEATHER_SERVICE="none" in the configuration file
# 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

View File

@@ -53,8 +53,13 @@ READLINK="/bin/readlink"
# Percorso 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 a 0 il sistema gestirà elettrovalvole bisstabili
# se impostato a 0 il sistema gestirà elettrovalvole bistabili
EV_MONOSTABLE=0
# Id gpio usati per simulare il doppio deviatore con cui eseguire l'alimentazione alle elettrovalvole
@@ -90,7 +95,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
#EV1_MONOSTABLE=1 # L'elettrovalvola è monostabile
EV2_ALIAS="2" #
EV2_GPIO=27 # Physical 13 - wPi 2
@@ -108,8 +113,10 @@ EV6_ALIAS="6" #
EV6_GPIO=24 # Physical 18 - wPi 5
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground.
# Se non vuoi configurare nessun servizio imposta il vale "none"
WEATHER_SERVICE="openweathermap"
#WEATHER_SERVICE="none" # Nessun servizio configurato
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
OPENWEATHERMAP_KEY=""
@@ -139,3 +146,12 @@ TCPSERVER_PWD=""
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
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

View File

@@ -53,6 +53,11 @@ READLINK="/bin/readlink"
# Percorso 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 a 0 il sistema gestirà elettrovalvole bisstabili
EV_MONOSTABLE=0
@@ -100,8 +105,10 @@ EV4_ALIAS="Giardino_Posteriore_GPIO" #
EV4_GPIO="18"
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground.
# Se non vuoi configurare nessun servizio imposta il vale "none"
WEATHER_SERVICE="openweathermap"
#WEATHER_SERVICE="none" # Nessun servizio configurato
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
OPENWEATHERMAP_KEY=""
@@ -131,6 +138,15 @@ TCPSERVER_PWD=""
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
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

View File

@@ -53,6 +53,11 @@ READLINK="/bin/readlink"
# Percorso 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 a 0 il sistema gestirà elettrovalvole bisstabili
EV_MONOSTABLE=0
@@ -102,8 +107,10 @@ EV4_ALIAS="Giardino_Anteriore"
EV4_GPIO="drv:sonoff_tasmota_http:SONOFF2:Power1"
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground.
# Se non vuoi configurare nessun servizio imposta il vale "none"
WEATHER_SERVICE="openweathermap"
#WEATHER_SERVICE="none" # Nessun servizio configurato
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
OPENWEATHERMAP_KEY=""
@@ -133,6 +140,15 @@ TCPSERVER_PWD=""
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
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

View File

@@ -53,6 +53,11 @@ READLINK="/bin/readlink"
# Percorso 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 a 0 il sistema gestirà elettrovalvole bisstabili
EV_MONOSTABLE=1
@@ -472,8 +477,10 @@ EV128_ALIAS="Zona_128" #
EV128_GPIO="drv:spb16ch:128"
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground.
# Se non vuoi configurare nessun servizio imposta il vale "none"
WEATHER_SERVICE="openweathermap"
#WEATHER_SERVICE="none" # Nessun servizio configurato
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
OPENWEATHERMAP_KEY=""
@@ -503,6 +510,15 @@ TCPSERVER_PWD=""
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
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

View File

@@ -34,11 +34,11 @@ function drv_openweathermap_rain_online_get {
"local_epoch": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".dt")",
"local_tz_long": "$OPENWEATHERMAP_TZ",
"weather": "$weather",
"temp_c": $(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".main.temp"),
"temp_c": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".main.temp")",
"relative_humidity": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".main.humidity")%",
"wind_dir": "$(deg2dir $wind_deg)",
"wind_degrees": $wind_deg,
"wind_kph": $wind_speed,
"wind_degrees": "$wind_deg",
"wind_kph": "$wind_speed",
"wind_gust_kph": "--",
"pressure_mb": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".main.pressure")",
"dewpoint_c": "--",

View File

@@ -17,12 +17,14 @@ function trigger_event {
case "$EVENT" in
"ev_open_before" | "ev_open_after")
ALIAS="$2"
CURRENT_EVENT_ALIAS="$ALIAS"
FORCE="$3"
$f "$EVENT" "$ALIAS" "$FORCE" `date +%s` &> /dev/null
;;
"ev_open_in_before")
ALIAS="$2"
CURRENT_EVENT_ALIAS="$ALIAS"
FORCE="$3"
local MINUTE_START="$4"
local MINUTE_STOP="$5"
@@ -31,6 +33,7 @@ function trigger_event {
"ev_open_in_after")
ALIAS="$2"
CURRENT_EVENT_ALIAS="$ALIAS"
FORCE="$3"
local CRON_START="$4"
local CRON_STOP="$5"
@@ -39,6 +42,7 @@ function trigger_event {
"ev_close_before" | "ev_close_after")
ALIAS="$2"
CURRENT_EVENT_ALIAS="$ALIAS"
$f "$EVENT" "$ALIAS" `date +%s` &> /dev/null
;;
@@ -89,7 +93,13 @@ function trigger_event {
local ec=$?
#echo "$EVENT ec=$ec" >> /tmp/piGarden.testevent
#CURRENT_EVENT="$EVENT"
#mqtt_status &
if [ $ec -ne 0 ]; then
CURRENT_EVENT="$EVENT"
mqtt_status &
log_write "Stop events chain for exit code $ec in $current_event_dir/$f"
return $ec
fi
@@ -98,6 +108,9 @@ function trigger_event {
fi
CURRENT_EVENT="$EVENT"
mqtt_status &
}

View File

@@ -1,61 +1,13 @@
#
# Controlla se se piove tramite http://api.wunderground.com/
#
function check_rain_online_old {
trigger_event "check_rain_online_before" ""
# http://www.wunderground.com/weather/api/d/docs?d=resources/phrase-glossary&MR=1
$CURL http://api.wunderground.com/api/$WUNDERGROUND_KEY/conditions/q/$WUNDERGROUND_LOCATION.json > $TMP_PATH/check_rain_online.json
local weather=`cat $TMP_PATH/check_rain_online.json | $JQ -M ".current_observation.weather"`
local current_observation=`cat $TMP_PATH/check_rain_online.json | $JQ -M ".current_observation"`
local local_epoch=`cat $TMP_PATH/check_rain_online.json | $JQ -M -r ".current_observation.local_epoch"`
local current_state_rain_online=""
local last_state_rain_online=`cat "$STATUS_DIR/last_state_rain_online" 2> /dev/null`
#echo $weather
#weather="[Light/Heavy] Drizzle"
if [ "$weather" = "null" ]; then
log_write "check_rain_online - failed read online data"
else
log_write "check_rain_online - weather=$weather, local_epoch=$local_epoch"
#if [[ "$weather" == *"Clear"* ]]; then
#if [[ "$weather" == *"Rain"* ]]; then
if [[ "$weather" == *"Rain"* ]] ||
[[ "$weather" == *"Snow"* ]] ||
[[ "$weather" == *"Hail"* ]] ||
[[ "$weather" == *"Ice"* ]] ||
[[ "$weather" == *"Thunderstorm"* ]] ||
[[ "$weather" == *"Drizzle"* ]];
then
current_state_rain_online='rain'
echo $local_epoch > "$STATUS_DIR/last_rain_online"
else
current_state_rain_online='norain'
fi
echo "$current_observation" > "$STATUS_DIR/last_weather_online"
if [ "$current_state_rain_online" != "$last_state_rain_online" ]; then
echo "$current_state_rain_online" > "$STATUS_DIR/last_state_rain_online"
trigger_event "check_rain_online_change" "$current_state_rain_online" "$weather"
fi
fi
trigger_event "check_rain_online_after" "$current_state_rain_online" "$weather"
}
#
# Controlla se se piove tramite http://api.wunderground.com/
# Esegue controllo meteo tramite servizio online configurato in WEATHER_SERVICE
#
function check_rain_online {
if [ "$WEATHER_SERVICE" == "none" ]; then
log_write "check_rain_online - online service is disable"
return
fi
trigger_event "check_rain_online_before" ""
local local_epoch=`drv_rain_online_get $WEATHER_SERVICE`

View File

@@ -63,7 +63,7 @@ function socket_server_command {
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
status)
@@ -225,7 +225,7 @@ function socket_server_command {
esac
reset_messages &> /dev/null
#reset_messages &> /dev/null
}

View File

@@ -1 +0,0 @@
piGardenMqttconnector.ini

View File

@@ -1,2 +0,0 @@
#!/bin/bash
echo -e "$1" | ../piGarden.sh socket_server_command

View File

@@ -1,88 +0,0 @@
#
# Installare libreria paho-mqtt, configparser:
# sudo pip install paho-mqtt configparser
#
import paho.mqtt.client as mqttClient
import time
import subprocess
import configparser
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to broker")
global Connected # Use global variable
Connected = True # Signal connection
else:
print("Connection failed")
def on_message(client, userdata, message):
print "Topic : " + message.topic
print "Message received: " + message.payload
if message.topic.startswith("pigarden/command/"):
print "pigarden command: " + message.payload
cmd = ""
cmd = message.payload
if pigarden_user != "" and pigarden_pwd != "":
cmd = pigarden_user + '\n' + pigarden_pwd + '\n' + cmd
p = subprocess.Popen([ pigarden_path + "mqttconnector/exec_command.sh", cmd ], stdout=subprocess.PIPE)
(output, err) = p.communicate()
## Wait for date to terminate. Get return returncode ##
p_status = p.wait()
print "Command : '" + cmd + "'"
print "Command output : ", output
print "Command exit status/return code : ", p_status
config = configparser.ConfigParser()
config.read('/etc/piGardenMqttconnector.ini')
Connected = False # global variable for the state of the connection
broker_address = config['mqtt']['broker_address']
port = int(config['mqtt']['port'])
user = config['mqtt']['user']
password = config['mqtt']['password']
client_id = config['mqtt']['client_id']
pigarden_path = config['pigarden']['path']
pigarden_user = config['pigarden']['user']
pigarden_pwd = config['pigarden']['pwd']
client = mqttClient.Client(client_id) # create new instance
client.username_pw_set(user, password=password) # set username and password
client.on_connect = on_connect # attach function to callback
client.on_message = on_message # attach function to callback
print broker_address, port, user, password
client.connect(broker_address, port=port) # connect to broker
client.loop_start() #start the loop
while Connected != True: #Wait for connection
time.sleep(0.1)
client.subscribe("pigarden/command/+")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print "exiting"
client.disconnect()
client.loop_stop()

View File

@@ -1,12 +0,0 @@
[mqtt]
broker_address=m20.cloudmqtt.com
port=13554
user=ucorgnpg
password=K5iJrLxNnhbM
client_id=Python
[pigarden]
path=/home/pi/piGarden/
user=a
pwd=b

View File

@@ -63,7 +63,7 @@ function initialize {
#
# 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_WARNING_FILE.$!"
rm -f "$LAST_SUCCESS_FILE.$!"
@@ -85,8 +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}
local EV_IS_MONOSTABLE_VAR=EV"$EVNUM"_MONOSTABLE
local EV_IS_MONOSTABLE=${!EV_IS_MONOSTABLE_VAR}
if [ ! "$2" = "force" ] && [ "$EVNORAIN" != "1" ]; 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
let "dif = now - last_rain"
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" "$1"
log_write "Solenoid '$1' not open for rain (online check)"
message_write "warning" "Solenoid not open for rain"
return
fi
fi
@@ -110,10 +110,10 @@ function ev_open {
local dif=0
let "dif = now - last_rain"
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" "$1"
log_write "Solenoid '$1' not open for rain (sensor check)"
message_write "warning" "Solenoid not open for rain"
return
fi
fi
@@ -128,6 +128,7 @@ function ev_open {
if [ $? -ne 0 ]; then
log_write "Solenoid '$1' not open due to external event"
message_write 'warning' "Solenoid not open due to external event"
mqtt_status
return
fi
@@ -149,12 +150,12 @@ function ev_open {
ev_set_state $EVNUM $state
log_write "Solenoid '$1' open"
message_write "success" "Solenoid open"
trigger_event "ev_open_after" "$1" "$2"
unlock
log_write "Solenoid '$1' open"
message_write "success" "Solenoid open"
}
#
@@ -175,21 +176,25 @@ function ev_open_in {
if ! [[ $minute_start =~ $re ]] ; then
echo -e "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
fi
if ! [[ $minute_stop =~ $re ]] ; then
echo -e "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
fi
if [ $minute_stop -lt "1" ] ; then
echo -e "Time stop of irrigation is wrong"
message_write "warning" "Time stop of irrigation is wrong"
mqtt_status
return 1
fi
if [ "empty$alias" == "empty" ]; then
echo -e "Alias solenoid not specified"
message_write "warning" "Alias solenoid not specified"
mqtt_status
return 1
fi
@@ -257,13 +262,13 @@ function ev_close {
ev_set_state $EVNUM 0
log_write "Solenoid '$1' close"
message_write "success" "Solenoid close"
trigger_event "ev_close_after" "$1"
unlock
log_write "Solenoid '$1' close"
message_write "success" "Solenoid close"
cron_del open_in_stop $1 > /dev/null 2>&1
}
@@ -303,6 +308,20 @@ function log_write {
# $2 messaggio
#
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=""
if [ "$1" = 'info' ]; then
file_message="$LAST_INFO_FILE.$!"
@@ -351,6 +370,7 @@ function gpio_alias2number {
log_write "ERROR solenoid alias not found: $1"
message_write "warning" "Solenoid alias not found"
mqtt_status
exit 1
}
@@ -370,6 +390,7 @@ function ev_alias2number {
log_write "ERROR solenoid alias not found: $1"
message_write "warning" "Solenoid alias not found"
mqtt_status
exit 1
}
@@ -492,6 +513,12 @@ function json_status {
local last_success=""
local with_get_cron="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=""
for i in $1 $2 $3 $4 $5 $6
@@ -516,7 +543,8 @@ function json_status {
if [ -n "$json" ]; then
json="$json,"
fi
json="$json\"$i\":{\"name\":\"$av\",\"state\":$sv}"
#json="$json\"$i\":{\"name\":\"$av\",\"state\":$sv}"
json="$json\"$av\":{\"name\":\"$av\",\"state\":$sv}"
done
json="\"zones\":{$json}"
@@ -527,15 +555,18 @@ function json_status {
if [[ ! -z "$last_weather_online" ]]; then
json_last_weather_online=$last_weather_online
fi
if [ -f "$LAST_INFO_FILE.$!" ]; then
last_info=`cat "$LAST_INFO_FILE.$!"`
fi
if [ -f "$LAST_WARNING_FILE.$!" ]; then
last_warning=`cat "$LAST_WARNING_FILE.$!"`
fi
if [ -f "$LAST_SUCCESS_FILE.$!" ]; then
last_success=`cat "$LAST_SUCCESS_FILE.$!"`
fi
#if [ -f "$LAST_INFO_FILE.$current_pid" ]; then
# last_info=`cat "$LAST_INFO_FILE.$current_pid"`
#fi
#if [ -f "$LAST_WARNING_FILE.$current_pid" ]; then
# last_warning=`cat "$LAST_WARNING_FILE.$current_pid"`
#fi
#if [ -f "$LAST_SUCCESS_FILE.$current_pid" ]; then
# last_success=`cat "$LAST_SUCCESS_FILE.$current_pid"`
#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_rain_sensor="\"last_rain_sensor\":\"$last_rain_sensor\""
local json_last_rain_online="\"last_rain_online\":\"$last_rain_online\""
@@ -607,9 +638,10 @@ function json_status {
json_get_cron_open_in="\"open_in\": {$values_open_in},\"open_in_stop\": {$values_open_in_stop}"
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"
@@ -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
#
@@ -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_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 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_sensor check rain from hardware sensor"
echo -e "\t$NAME_SCRIPT close_all_for_rain close all solenoid if it's raining"
@@ -880,7 +933,7 @@ function debug2 {
VERSION=0
SUB_VERSION=5
RELEASE_VERSION=8
RELEASE_VERSION=12
DIR_SCRIPT=`dirname $0`
NAME_SCRIPT=${0##*/}
@@ -908,9 +961,17 @@ fi
. "$DIR_SCRIPT/include/rain.include.sh"
. "$DIR_SCRIPT/include/events.include.sh"
LAST_INFO_FILE="$STATUS_DIR/last_info"
LAST_WARNING_FILE="$STATUS_DIR/last_warning"
LAST_SUCCESS_FILE="$STATUS_DIR/last_success"
#LAST_INFO_FILE="$STATUS_DIR/last_info"
#LAST_WARNING_FILE="$STATUS_DIR/last_warning"
#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
LOG_OUTPUT_DRV_FILE="/dev/null"
@@ -922,7 +983,7 @@ fi
if [ -z $WEATHER_SERVICE ]; then
WEATHER_SERVICE="drv:wunderground"
else
elif [ "$WEATHER_SERVICE" != "none" ]; then
WEATHER_SERVICE="drv:$WEATHER_SERVICE"
fi
@@ -981,6 +1042,10 @@ case "$1" in
json_status $2 $3 $4 $5 $6
;;
mqtt_status)
mqtt_status $2
;;
check_rain_online)
check_rain_online
;;
@@ -1122,4 +1187,4 @@ esac
rm "$TMP_CRON_FILE" 2> /dev/null
rm "$TMP_CRON_FILE-2" 2> /dev/null
reset_messages &> /dev/null
#reset_messages &> /dev/null