Modificato gestione di invio messaggi tramite socket server
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
76
piGarden.sh
76
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.$!"
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,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.$current_pid" ]; then
|
#if [ -f "$LAST_INFO_FILE.$current_pid" ]; then
|
||||||
last_info=`cat "$LAST_INFO_FILE.$current_pid"`
|
# last_info=`cat "$LAST_INFO_FILE.$current_pid"`
|
||||||
fi
|
#fi
|
||||||
if [ -f "$LAST_WARNING_FILE.$current_pid" ]; then
|
#if [ -f "$LAST_WARNING_FILE.$current_pid" ]; then
|
||||||
last_warning=`cat "$LAST_WARNING_FILE.$current_pid"`
|
# last_warning=`cat "$LAST_WARNING_FILE.$current_pid"`
|
||||||
fi
|
#fi
|
||||||
if [ -f "$LAST_SUCCESS_FILE.$current_pid" ]; then
|
#if [ -f "$LAST_SUCCESS_FILE.$current_pid" ]; then
|
||||||
last_success=`cat "$LAST_SUCCESS_FILE.$current_pid"`
|
# 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\""
|
||||||
@@ -614,9 +638,10 @@ 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_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}"
|
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"
|
||||||
|
|
||||||
@@ -936,9 +961,12 @@ 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=""
|
||||||
CURRENT_EVENT_ALIAS=""
|
CURRENT_EVENT_ALIAS=""
|
||||||
@@ -1159,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