10 Commits

Author SHA1 Message Date
lejubila
10045d5a11 Fix path of url weather icons 2022-07-16 16:26:38 +02:00
lejubila
3d0d36077d Update CHANGELOG 2021-10-03 10:04:30 +02:00
lejubila
a30e1cb6ef fix return value when get value of sensor 2021-08-28 12:17:22 +02:00
lejubila
81ce03e90a Add autoclose of the solenoid when the soil moisture has reached the set level 2021-08-28 11:38:05 +02:00
lejubila
2001b09937 Add support for sensor: moisture, temperature, fertility, illuminance. Add event ev_not_open_for_moisture, sensor_set_state_before, sensor_set_state_after. Added zone humidity management: when a zone has reached the humidity defined in EVx_SENSOR_MOISTURE it does not start irrigation or interrupts it if it is already active. In case of rain it does not stop irrigation if the soil humidity has not reached the configured value. 2021-08-27 22:52:01 +02:00
lejubila
c91128cbb4 Add command line: sensor_status, sensor_status_all, sensor_status_set. Add api command: sensor_status_set. 2021-08-22 15:19:34 +02:00
lejubila
7242b1c2ab Add command last_rain_sensor_timestamp, last_rain_online_timestamp, reset_last_rain_sensor_timestamp, reset_last_rain_online_timestamp. Add socket server api for reset_last_rain_sensor_timestamp, reset_last_rain_online_timestamp 2021-08-10 23:39:38 +02:00
lejubila
5152252653 Aggiornato driver rainsensorqty alla versione 0.2.5c 2021-04-24 09:55:57 +02:00
lejubila
50fc8a72b2 Change number of version 2020-09-06 08:28:04 +02:00
lejubila
9183bbcef5 Add support for send log to piGardenWeb 2020-09-06 08:24:26 +02:00
21 changed files with 697 additions and 132 deletions

View File

@@ -1,3 +1,23 @@
# 0.6.4 - 03/10/2021
- Fix path of url weather icons
# 0.6.4 - 03/10/2021
- Add support for sensor: moisture, temperature, fertility, illuminance
- Add command line: sensor_status, sensor_status_all, sensor_status_set
- Add api command: sensor_status_set
- Add event ev_not_open_for_moisture, sensor_set_state_before, sensor_set_state_after
- Added zone humidity management: when a zone has reached the humidity defined in EVx_SENSOR_MOISTURE it does not start irrigation or interrupts it if it is already active. In case of rain it does not stop irrigation if the soil humidity has not reached the configured value
# 0.6.3 - 10/08/2021
- Add command last_rain_sensor_timestamp, last_rain_online_timestamp, reset_last_rain_sensor_timestamp, reset_last_rain_online_timestamp
- Add socket server api for reset_last_rain_sensor_timestamp, reset_last_rain_online_timestamp
# 0.6.2 - 24/04/2021
- Update rainsensorqty driver to version 0.2.5c
# 0.6.1 - 06/09/2020
- Add support for send log to piGardenWeb
# 0.6.0 - 16/05/2020
- Add support for enable all cron fron api
- Update rainsensorqty driver to version 0.2.5b

View File

@@ -2,6 +2,14 @@
LOG_FILE="/home/pi/piGarden/log/piGarden.log"
LOG_FILE_MAX_SIZE=1048576 # 1MB
#
# Enable send log to piGardenWeb
#
#LOG_URL="http://url_of_your_pigardenweb/api/log"
#LOG_API_TOKEN="token_of_pigardenweb_user"
#LOG_CURL_PARAM="--data-urlencode -k"
# Log file for driver output
LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log"
@@ -99,6 +107,9 @@ 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_MONOSTABLE=1 # L'elettrovalvola è monostabile
#EV1_SENSOR_ALIAS=Mi_Flora # Nome del sensore (definito in SENSORx_ALIAS) per stabilire l'umidità del terreno
#EV1_SENSOR_MOISTURE=50 # Percentule di umidità ottimale
#EV1_SENSOR_MOISTURE_AUTOCLOSE=1 # Chiude automaticamente l'elettrovalvola quando supera l'umidità impostata in EVx_MONOSTABLE
EV2_ALIAS="2" #
EV2_GPIO=27 # Physical 13 - wPi 2
@@ -116,6 +127,16 @@ EV6_ALIAS="6" #
EV6_GPIO=24 # Physical 18 - wPi 5
# Numero di sensori
SENSOR_TOTAL=1
# Definizione sensori
SENSOR1_ALIAS=Mi_Flora
# 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"

View File

@@ -2,6 +2,14 @@
LOG_FILE="/home/pi/piGarden/log/piGarden.log"
LOG_FILE_MAX_SIZE=1048576 # 1MB
#
# Enable send log to piGardenWeb
#
#LOG_URL="http://url_of_your_pigardenweb/api/log"
#LOG_API_TOKEN="token_of_pigardenweb_user"
#LOG_CURL_PARAM="--data-urlencode -k"
# Log file for driver output
LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log"

View File

@@ -2,6 +2,14 @@
LOG_FILE="/home/pi/piGarden/log/piGarden.log"
LOG_FILE_MAX_SIZE=1048576 # 1MB
#
# Enable send log to piGardenWeb
#
#LOG_URL="http://url_of_your_pigardenweb/api/log"
#LOG_API_TOKEN="token_of_pigardenweb_user"
#LOG_CURL_PARAM="--data-urlencode -k"
# Log file for driver output
#LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log"

View File

@@ -2,6 +2,14 @@
LOG_FILE="/home/pi/piGarden/log/piGarden.log"
LOG_FILE_MAX_SIZE=1048576 # 1MB
#
# Enable send log to piGardenWeb
#
#LOG_URL="http://url_of_your_pigardenweb/api/log"
#LOG_API_TOKEN="token_of_pigardenweb_user"
#LOG_CURL_PARAM="--data-urlencode -k"
# Log file for driver output
#LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log"

View File

@@ -2,6 +2,14 @@
LOG_FILE="/home/pi/piGarden/log/piGarden.log"
LOG_FILE_MAX_SIZE=1048576 # 1MB
#
# Enable send log to piGardenWeb
#
#LOG_URL="http://url_of_your_pigardenweb/api/log"
#LOG_API_TOKEN="token_of_pigardenweb_user"
#LOG_CURL_PARAM="--data-urlencode -k"
# Log file for driver output
#LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log"

View File

@@ -91,24 +91,24 @@ function drv_openweathermap_get_ico {
declare -A w
w["01d"]="http://icons.wxug.com/i/c/k/clear.gif"
w["01n"]="http://icons.wxug.com/i/c/k/nt_clear.gif"
w["02d"]="http://icons.wxug.com/i/c/k/partlycloudy.gif"
w["02n"]="http://icons.wxug.com/i/c/k/nt_partlycloudy.gif"
w["03d"]="http://icons.wxug.com/i/c/k/cloudy.gif"
w["03n"]="http://icons.wxug.com/i/c/k/nt_cloudy.gif"
w["04d"]="http://icons.wxug.com/i/c/k/cloudy.gif"
w["04n"]="http://icons.wxug.com/i/c/k/nt_cloudy.gif"
w["09d"]="http://icons.wxug.com/i/c/k/sleet.gif"
w["09n"]="http://icons.wxug.com/i/c/k/nt_sleet.gif"
w["10d"]="http://icons.wxug.com/i/c/k/rain.gif"
w["10n"]="http://icons.wxug.com/i/c/k/nt_rain.gif"
w["11d"]="http://icons.wxug.com/i/c/k/tstorms.gif"
w["11n"]="http://icons.wxug.com/i/c/k/nt_tstorms.gif"
w["13d"]="http://icons.wxug.com/i/c/k/snow.gif"
w["13n"]="http://icons.wxug.com/i/c/k/nt_snow.gif"
w["50d"]="http://icons.wxug.com/i/c/k/fog.gif"
w["50n"]="http://icons.wxug.com/i/c/k/nt_fog.gif"
w["01d"]="http://www.wunderground.com/static/i/c/k/clear.gif"
w["01n"]="http://www.wunderground.com/static/i/c/k/nt_clear.gif"
w["02d"]="http://www.wunderground.com/static/i/c/k/partlycloudy.gif"
w["02n"]="http://www.wunderground.com/static/i/c/k/nt_partlycloudy.gif"
w["03d"]="http://www.wunderground.com/static/i/c/k/cloudy.gif"
w["03n"]="http://www.wunderground.com/static/i/c/k/nt_cloudy.gif"
w["04d"]="http://www.wunderground.com/static/i/c/k/cloudy.gif"
w["04n"]="http://www.wunderground.com/static/i/c/k/nt_cloudy.gif"
w["09d"]="http://www.wunderground.com/static/i/c/k/sleet.gif"
w["09n"]="http://www.wunderground.com/static/i/c/k/nt_sleet.gif"
w["10d"]="http://www.wunderground.com/static/i/c/k/rain.gif"
w["10n"]="http://www.wunderground.com/static/i/c/k/nt_rain.gif"
w["11d"]="http://www.wunderground.com/static/i/c/k/tstorms.gif"
w["11n"]="http://www.wunderground.com/static/i/c/k/nt_tstorms.gif"
w["13d"]="http://www.wunderground.com/static/i/c/k/snow.gif"
w["13n"]="http://www.wunderground.com/static/i/c/k/nt_snow.gif"
w["50d"]="http://www.wunderground.com/static/i/c/k/fog.gif"
w["50n"]="http://www.wunderground.com/static/i/c/k/nt_fog.gif"
local ico=${w[$1]}

View File

@@ -0,0 +1 @@
echo 1 > /tmp/tick ; sleep 0.9 ; echo 0 > /tmp/tick

View File

@@ -60,6 +60,46 @@ en_echo() # enhanched echo - check verbose variable
[[ $RAINSENSORQTY_verbose = yes ]] && echo "$(d) $*"
}
check_incomplete_loop()
{
[[ ! -f $RAINSENSORQTY_HISTORYRAW ]] && return 1
[[ ! -f $RAINSENSORQTY_HISTORY ]] && touch $RAINSENSORQTY_HISTORY
> $RAINSENSORQTY_HISTORYTMP
if lastrainevent=$( rainevents 1 ) ; then
: # done ok
else
echo "WARNING: rainevents function had errors"
return 1
fi
set -- ${lastrainevent//:/ }
local started=$1
local before=$2
local counter=$3
wrongevent=$(awk -F ":" '$1=="'$started'" && $2!="'$before'" {print $0}' $RAINSENSORQTY_HISTORY)
if [[ -n $wrongevent ]] ; then
echo "ERROR: wrong last rain event found: $wrongevent , right one should be: $lastrainevent"
return 2
fi
if grep -q ^${lastrainevent}$ $RAINSENSORQTY_HISTORY ; then
: # already present
return 0
else
: # missing and fixed
if [[ $1 == tmp ]] ; then
echo $lastrainevent > $RAINSENSORQTY_HISTORYTMP
else
echo $lastrainevent >> $RAINSENSORQTY_HISTORY
fi
return 1
fi
}
#next function is not used anymore
rain_history()
{
[[ ! -f $RAINSENSORQTY_HISTORYRAW ]] && return 1
@@ -134,7 +174,7 @@ rainevents()
newloop=no
fi
if (( sequence == 1 )) ; then
# [[ $skiplast=true ]] && { skilast=false ; continue ; }
# [[ $skiplast=true ]] && { skiplast=false ; continue ; }
echo $time:$endtime:$endsequence
newloop=yes
(( event +=1 ))

View File

@@ -4,8 +4,8 @@
# Author: androtto
# file "drv_rainsensorqty_monitor.sh"
# monitor script
# Version: 0.2.5b
# Data: 12/May/2020
# Version: 0.2.5c
# Data: 08/Dec/2020
resetcounter()
{
@@ -14,6 +14,19 @@ resetcounter()
echo "SIGUSR1 received after last PULSE - counter resetted"
}
# DEBUG FUNCTION:
testloop()
{
touch /tmp/tick
while true
do
if [[ $( < /tmp/tick ) = "1" ]] ; then
break
fi
sleep 1
done
}
###############
# MAIN #
###############
@@ -51,30 +64,41 @@ fi
echo $$ > $RAINSENSORQTY_MONPID
drv_rainsensorqty_writelog $f "NORMAL - $$ pid monitor process started - see $RAINSENSORQTY_MONPID"
echo ""
en_echo "---- NEW RUN ----"
# check if monitor script was killed before writing a complete rain event
check_incomplete_loop
case $? in
2) echo "\$RAINSENSORQTY_HISTORY - wrong entry found - no fix possible" ;;
1) echo "\$RAINSENSORQTY_HISTORY - fixed incomplete loop" ;;
0) echo "\$RAINSENSORQTY_HISTORY - no incomplete loop needed to be fixed" ;;
esac
# init variables
MMEACH="$RAINSENSORQTY_MMEACH"
(( counter=0 ))
rain_history
before="-1"
echo ""
en_echo "---- NEW RUN ----"
en_echo "WAITING FOR $RAINSENSORQTY_PULSE PULSE"
# loop forever
while true
do
before=`date +%s`
sleep $RAINSENSOR_DEBOUNCE
#DEBUG: testloop #DEBUG
$GPIO -g wfi $gpio_port $RAINSENSORQTY_PULSE
now=`date +%s`
(( elapsed = now - before ))
if (( elapsed >= RAINSENSORQTY_SECSBETWEENRAINEVENT )) ; then
last_event="$started:$before:$counter"
(( counter=0 ))
drv_rainsensorqty_writelog $f "first drops after $elapsed seconds since last rain ( greater than $RAINSENSORQTY_SECSBETWEENRAINEVENT )- new cycle - waiting for $( $JQ -n "$RAINSENSORQTY_LOOPSFORSETRAINING * $MMEACH" ) mm of rain" &
(( before > 0 )) && echo $last_event >> $RAINSENSORQTY_HISTORY
en_echo "---- NEW CYCLE ----"
rain_history &
fi
(( counter+=1 ))
(( counter == 1 )) && (( started = now ))
echo "$now:$counter" >> ${RAINSENSORQTY_HISTORYRAW} &
MMWATER=$( $JQ -n "$counter*$MMEACH" )
en_echo $( printf "%s PULSE #%d RECEIVED (%.2f mm)" $RAINSENSORQTY_PULSE $counter $MMWATER )
@@ -85,4 +109,5 @@ do
else
drv_rainsensorqty_writelog $f "now is $text" &
fi
(( before = now ))
done

View File

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

View File

@@ -35,7 +35,7 @@ function drv_sonoff_tasmota_http_rele_open {
error="${error%\"}"
error="${error#\"}"
echo "error=$error"
log_write "Remote rele open error: $error"
log_write "drv_sonoff_tasmota_http" "error" "Remote rele open error: $error"
message_write "warning" "Remote rele open error: $error"
return 1
fi
@@ -69,7 +69,7 @@ function drv_sonoff_tasmota_http_rele_close {
error="${error%\"}"
error="${error#\"}"
echo "error=$error"
log_write "Remote rele close error: $error"
log_write "drv_sonoff_tasmota_http" "error" "Remote rele close error: $error"
message_write "warning" "Remote rele close error: $error"
return 1
fi

View File

@@ -74,7 +74,7 @@ function drv_spb16ch_boards_id_load {
SPB16CH_USED_ID+=("$board_id")
done
else
log_write "spb16ch: file $SPB16CH_BOARD_ID_STORE_FILE not found: remember to run 'piGarden init' to generate the file"
log_write "drv_spb16ch" "error" "spb16ch: file $SPB16CH_BOARD_ID_STORE_FILE not found: remember to run 'piGarden init' to generate the file"
fi
}

View File

@@ -19,7 +19,7 @@ function drv_spb16ch_rele_open {
local rele_data=${SPB16CH_RELE_MAP[$rele_id]}
if [[ -z $rele_data ]]; then
local message="Error - Rele map not defined - rele_id=$rele_id - ($1)"
log_write "$message"
log_write "drv_spb16ch" "error" "$message"
message_write "warning" "$message"
fi
local address_num=${rele_data:0:2}
@@ -52,7 +52,7 @@ function drv_spb16ch_rele_close {
local rele_data=${SPB16CH_RELE_MAP[$rele_id]}
if [[ -z $rele_data ]]; then
local message="Error - Rele map not defined - rele_id=$rele_id - ($1)"
log_write "$message"
log_write "drv_spb16ch" "error" "$message"
message_write "warning" "$message"
fi
local address_num=${rele_data:0:2}

View File

@@ -10,7 +10,7 @@ function cron_del {
if [ -z "$CRON_TYPE" ]; then
echo "Cron type is empty" >&2
log_write "Cron type is empty"
log_write "cron" "error" "Cron type is empty"
return 1
fi
@@ -25,17 +25,17 @@ function cron_del {
fi
if ! [[ $START =~ $re ]] ; then
echo "Cron start don't find" >&2
log_write "Cron start don't find"
log_write "cron" "error" "Cron start don't find"
return 1
fi
if ! [[ $END =~ $re ]] ; then
echo "Cron end cron don't find" >&2
log_write "Cron end cron don't find"
log_write "cron" "error" "Cron end cron don't find"
return 1
fi
if [ "$START" -gt "$END" ]; then
echo "Wrong position for start and end in cron" >&2
log_write "Wrong position for start and end in cron"
log_write "cron" "error" "Wrong position for start and end in cron"
return 1
fi
@@ -74,7 +74,7 @@ function cron_add {
if [ -z "$CRON_TYPE" ]; then
echo "Cron type is empty" >&2
log_write "Cron type is empty"
log_write "cron" "error" "Cron type is empty"
return 1
fi
@@ -91,12 +91,12 @@ function cron_add {
else
if ! [[ $START =~ $re ]] ; then
echo "Cron start don't find" >&2
log_write "Cron start don't find"
log_write "cron" "error" "Cron start don't find"
return 1
fi
if ! [[ $END =~ $re ]] ; then
echo "Cron end cron don't find" >&2
log_write "Cron end cron don't find"
log_write "cron" "error" "Cron end cron don't find"
return 1
fi
START=$(($START + 1))
@@ -104,7 +104,7 @@ function cron_add {
if [ "$START" -gt "$END" ]; then
echo "Wrong position for start and end in cron" >&2
log_write "Wrong position for start and end in cron"
log_write "cron" "error" "Wrong position for start and end in cron"
return 1
fi
@@ -183,7 +183,7 @@ function cron_add {
*)
echo "Wrong cron type: $CRON_TYPE"
log_write "Wrong cron type: $CRON_TYPE"
log_write "cron" "error" "Wrong cron type: $CRON_TYPE"
;;
esac
@@ -225,7 +225,7 @@ function cron_get {
if [ -z "$CRON_TYPE" ]; then
echo "Cron type is empty" >&2
log_write "Cron type is empty"
log_write "cron" "error" "Cron type is empty"
return 1
fi
@@ -241,12 +241,12 @@ function cron_get {
else
if ! [[ $START =~ $re ]] ; then
echo "Cron start don't find" >&2
log_write "Cron start don't find"
log_write "cron" "error" "Cron start don't find"
return 1
fi
if ! [[ $END =~ $re ]] ; then
echo "Cron end cron don't find" >&2
log_write "Cron end cron don't find"
log_write "cron" "error" "Cron end cron don't find"
return 1
fi
START=$(($START + 1))
@@ -254,7 +254,7 @@ function cron_get {
if [ "$START" -gt "$END" ]; then
echo "Wrong position for start and end in cron" >&2
log_write "Wrong position for start and end in cron"
log_write "cron" "error" "Wrong position for start and end in cron"
return 1
fi
@@ -370,7 +370,7 @@ function add_cron_open {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi
@@ -387,7 +387,7 @@ function del_cron_open {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi
@@ -404,7 +404,7 @@ function get_cron_open {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi
@@ -421,7 +421,7 @@ function del_cron_open_in {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi
@@ -439,7 +439,7 @@ function get_cron_close {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi
@@ -462,7 +462,7 @@ function add_cron_close {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi
@@ -479,7 +479,7 @@ function del_cron_close {
local exists=`alias_exists $1`
if [ "check $exists" = "check FALSE" ]; then
log_write "Alias $1 not found"
log_write "cron" "error" "Alias $1 not found"
echo "Alias $1 not found"
return 1
fi

View File

@@ -94,7 +94,7 @@ function drv_rele_init {
$GPIO -g mode $idx out # setta il gpio nella modalita di scrittura
# Il driver definito non è stato trovato
elif [ "$fnc" == "drvnotfound" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
else
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
@@ -116,7 +116,7 @@ function drv_rele_close {
$GPIO -g write $idx $RELE_GPIO_CLOSE
# Il driver definito non è stato trovato
elif [ "$fnc" == "drvnotfound" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
return 1
else
@@ -142,7 +142,7 @@ function drv_rele_open {
$GPIO -g write $idx $RELE_GPIO_OPEN
# Il driver definito non è stato trovato
elif [ "$fnc" == "drvnotfound" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
return 1
else
@@ -172,7 +172,7 @@ function drv_supply_bistable_init {
$GPIO -g mode $idx1 out
# Il driver definito non è stato trovato
elif [ "$fnc1" == "drvnotfound" ]; then
log_write "Driver not found: $idx1"
log_write "drv" "error" "Driver not found: $idx1"
message_write "warning" "Driver not found: $idx1"
return
else
@@ -186,7 +186,7 @@ function drv_supply_bistable_init {
$GPIO -g mode $idx2 out
# Il driver definito non è stato trovato
elif [ "$fnc2" == "drvnotfound" ]; then
log_write "Driver not found: $idx2"
log_write "drv" "error" "Driver not found: $idx2"
message_write "warning" "Driver not found: $idx2"
else
echo "$(date) $fnc2 arg:$idx2" >> "$LOG_OUTPUT_DRV_FILE"
@@ -212,7 +212,7 @@ function drv_supply_positive {
$GPIO -g write $idx1 $SUPPLY_GPIO_POS
# Il driver definito non è stato trovato
elif [ "$fnc1" == "drvnotfound" ]; then
log_write "Driver not found: $idx1"
log_write "drv" "error" "Driver not found: $idx1"
message_write "warning" "Driver not found: $idx1"
return
else
@@ -225,7 +225,7 @@ function drv_supply_positive {
$GPIO -g write $idx2 $SUPPLY_GPIO_POS
# Il driver definito non è stato trovato
elif [ "$fnc2" == "drvnotfound" ]; then
log_write "Driver not found: $idx2"
log_write "drv" "error" "Driver not found: $idx2"
message_write "warning" "Driver not found: $idx2"
else
echo "$(date) $fnc2 arg:$idx2" >> "$LOG_OUTPUT_DRV_FILE"
@@ -251,7 +251,7 @@ function drv_supply_negative {
$GPIO -g write $idx1 $SUPPLY_GPIO_NEG
# Il driver definito non è stato trovato
elif [ "$fnc1" == "drvnotfound" ]; then
log_write "Driver not found: $idx1"
log_write "drv" "error" "Driver not found: $idx1"
message_write "warning" "Driver not found: $idx1"
return
else
@@ -264,7 +264,7 @@ function drv_supply_negative {
$GPIO -g write $idx2 $SUPPLY_GPIO_NEG
# Il driver definito non è stato trovato
elif [ "$fnc2" == "drvnotfound" ]; then
log_write "Driver not found: $idx2"
log_write "drv" "error" "Driver not found: $idx2"
message_write "warning" "Driver not found: $idx2"
else
echo "$(date) $fnc2 arg:$idx2" >> "$LOG_OUTPUT_DRV_FILE"
@@ -288,7 +288,7 @@ function drv_rain_sensor_init {
$GPIO -g mode $idx in
# Il driver definito non è stato trovato
elif [ "$fnc" == "drvnotfound" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
else
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
@@ -312,7 +312,7 @@ function drv_rain_sensor_get {
vret=`$GPIO -g read $idx`
# Il driver definito non è stato trovato
elif [ "$fnc" == "drvnotfound" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
else
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
@@ -335,11 +335,11 @@ function drv_rain_online_get {
# Nessun driver definito, esegue la lettura del sensore tramite gpio del raspberry
if [ -z "$fnc" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
# Il driver definito non è stato trovato
elif [ "$fnc" == "drvnotfound" ]; then
log_write "Driver not found: $idx"
log_write "drv" "error" "Driver not found: $idx"
message_write "warning" "Driver not found: $idx"
else
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"

View File

@@ -4,7 +4,7 @@
function check_rain_online {
if [ "$WEATHER_SERVICE" == "none" ]; then
log_write "check_rain_online - online service is disable"
log_write "rain" "warning" "check_rain_online - online service is disabled"
return
fi
@@ -17,7 +17,7 @@ function check_rain_online {
if [[ $local_epoch =~ ^-?[0-9]+$ ]]; then
if [ $local_epoch -eq 0 ]; then
log_write "check_rain_online - failed read online data"
log_write "rain" "error" "check_rain_online - failed read online data"
else
if [ $local_epoch -gt 0 ]; then
current_state_rain_online='rain'
@@ -27,14 +27,14 @@ function check_rain_online {
fi
weather=$(cat "$STATUS_DIR/last_weather_online" | $JQ -M ".weather")
log_write "check_rain_online - weather=$weather, local_epoch=$local_epoch"
log_write "rain" "info" "check_rain_online - weather=$weather, local_epoch=$local_epoch"
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
else
log_write "check_rain_online - failed read online data"
log_write "rain" "error" "check_rain_online - failed read online data"
fi
trigger_event "check_rain_online_after" "$current_state_rain_online" "$weather"
@@ -57,11 +57,11 @@ function check_rain_sensor {
current_state_rain_sensor='rain'
local local_epoch=`date +%s`
echo $local_epoch > "$STATUS_DIR/last_rain_sensor"
log_write "check_rain_sensor - now it's raining ($local_epoch)"
log_write "rain" "info" "check_rain_sensor - now it's raining ($local_epoch)"
#return $local_epoch
else
current_state_rain_sensor='norain'
log_write "check_rain_sensor - now is not raining"
log_write "rain" "info" "check_rain_sensor - now is not raining"
fi
if [ "$current_state_rain_sensor" != "$last_state_rain_sensor" ]; then
echo "$current_state_rain_sensor" > "$STATUS_DIR/last_state_rain_sensor"
@@ -69,17 +69,38 @@ function check_rain_sensor {
fi
trigger_event "check_rain_sensor_after" "$current_state_rain_sensor"
else
log_write "Rain sensor not present"
log_write "rain" "warning" "Rain sensor not present"
fi
}
#
# Chiude tutte le elettrovalvole se sta piovendo
# Chiude tutte le elettrovalvole se sta piovendo oppure chiude quelle che hanno raggiunto l'mudità massima impostata
# Eseguie il controllo in tempo reale sul sensore hardware e sui dati dell'ultima chiamata eseguita online
#
function close_all_for_rain {
#
# Chiude le elettrovalvole che hanno raggiunto l'umidità del terreno impostata in EVx_SENSOR_MOISTURE
#
for i in $(seq $EV_TOTAL)
do
local a=EV"$i"_ALIAS
local al=${!a}
ev_status $al
local state=$?
local moisture=$(ev_check_moisture_autoclose $i)
if [ "$state" = "1" ] && [ "$moisture" -gt 0 ]; then
ev_close $al
log_write "irrigate" "warning" "close_all_for_rain - Close solenoid '$al' because maximum soil moisture has been reached"
fi
done
#
# Chiude le elettrovalvole in caso di pioggia
#
local close_all=0
local now=`date +%s`
@@ -102,6 +123,12 @@ function close_all_for_rain {
fi
if [ "$close_all" = "1" ]; then
#
# PIOVE
# Valuta se la sciare aperte le elettrovalvole in caso l'umidità del sensore non sia stata raggiunta
#
for i in $(seq $EV_TOTAL)
do
local a=EV"$i"_ALIAS
@@ -110,14 +137,51 @@ function close_all_for_rain {
local evnorain=${!a}
ev_status $al
local state=$?
local moisture=$(ev_check_moisture $i)
#echo "$al = $state"
if [ "$state" = "1" ] && [ "$evnorain" != "1" ]; then
if [ "$state" = "1" ] && [ "$evnorain" != "1" ] && [ "$moisture" -ne 0 ]; then
ev_close $al
log_write "close_all_for_rain - Close solenoid '$al' for rain"
log_write "irrigate" "warning" "close_all_for_rain - Close solenoid '$al' for rain"
fi
done
fi
}
#
# Mostra il timestamp dell'ultima pioggia rilevato dal sensore
#
function last_rain_sensor_timestamp {
cat "$STATUS_DIR/last_rain_sensor" 2> /dev/null
}
#
# Mostra il timestamp dell'ultima pioggia rilevato dal servizio online
#
function last_rain_online_timestamp {
cat "$STATUS_DIR/last_rain_online" 2> /dev/null
}
#
# Resetta il timestamp dell'ultima pioggia rilevato dal sensore
#
function reset_last_rain_sensor_timestamp {
trigger_event "reset_last_rain_sensor_timestamp_before" ""
rm "$STATUS_DIR/last_rain_sensor" 2> /dev/null
trigger_event "reset_last_rain_sensor_timestamp_after" ""
log_write "rain" "info" "reset_last_rain_sensor_timestamp"
}
#
# Resetta mostra il timestamp dell'ultima pioggia rilevato dal servizio online
#
function reset_last_rain_online_timestamp {
trigger_event "reset_last_rain_online_timestamp_before" ""
rm "$STATUS_DIR/last_rain_online" 2> /dev/null
trigger_event "reset_last_rain_online_timestamp_before" ""
log_write "rain" "info" "reset_last_rain_online_timestamp"
}

249
include/sensor.include.sh Normal file
View File

@@ -0,0 +1,249 @@
#
# Imposta lo stato di una elettrovalvola
# $1 numero del sensore
# $2 tipologia dello stato
# $3 stato da scrivere
#
function sensor_set_state {
trigger_event "sensor_set_state_before" $1 $2 $3
echo "$3" > "$STATUS_DIR/sensor$1_$2"
trigger_event "sensor_set_state_after" $1 $2 $3
}
#
# Legge lo stato di un sensore
# $1 numero del sensore
# $2 tipologia dello stato
#
function sensor_get_state {
if [ ! -f "$STATUS_DIR/sensor$1_$2" ]; then
sensor_set_state $1 $2 ""
fi
local state=$(cat "$STATUS_DIR/sensor$1_$2" 2> /dev/null)
echo $state
}
#
# Recupera il numero di un sensore in base all'alias
# $1 alias del sensore
#
function sensor_alias2number {
for i in $(seq $EV_TOTAL)
do
a=SENSOR"$i"_ALIAS
av=${!a}
if [ "$av" == "$1" ]; then
return $i
fi
done
log_write "general" "error" "ERROR sensor alias not found: $1"
message_write "warning" "Sensor alias not found"
mqtt_status
exit 1
}
#
# Verifica se un alias di un sensore esiste
# $1 alias dell'elettrovalvola
#
function sensor_alias_exists {
local vret='FALSE'
for i in $(seq $EV_TOTAL)
do
a=SENSOR"$i"_ALIAS
av=${!a}
if [ "$av" == "$1" ]; then
vret='TRUE'
fi
done
echo $vret
}
#
# Mostra lo stato di tutte le elettrovalvole
#
function sensor_status_all {
for i in $(seq $SENSOR_TOTAL)
do
a=SENSOR"$i"_ALIAS
av=${!a}
for t in $SENSOR_STATE_TYPE
do
local state=$(sensor_get_state $i $t)
echo -e "$av: $t $state"
done
done
}
#
# Mostra lo stato di un sensore
# $1 alias sensore
# $2 tipologia dello stato
#
function sensor_status {
sensor_alias2number $1
i=$?
if [ -z "$2" ]; then
for t in $SENSOR_STATE_TYPE
do
local state=$(sensor_get_state $i $t)
echo -e "$av: $t $state"
done
else
local state=$(sensor_get_state $i $2)
echo -e "$state"
fi
}
#
# Imposta lo stato di un sensore per alias
# $1 alias sensore
# $2 tipologia dello stato
# $3 stato da imopostare
#
function sensor_status_set {
sensor_alias2number $1
i=$?
sensor_set_state $i $2 $3
mqtt_status
}
#
# Stampa la lista degli alias dei sensori
#
function list_alias_sensor {
for i in $(seq $SENSOR_TOTAL)
do
local a=SENSOR"$i"_ALIAS
local al=${!a}
echo $al
done
}
#
# Stampa lo stato di tutti i sensori in formato json
#
function json_sensor_status_all {
local js=""
local js_item=""
local js_type=""
for i in $(seq $SENSOR_TOTAL)
do
a=SENSOR"$i"_ALIAS
av=${!a}
js_type=""
for t in $SENSOR_STATE_TYPE
do
local state=$(sensor_get_state $i $t)
js_type="$js_type \"$t\": \"$state\", "
done
js_type="${js_type::-2}"
js_item="$js_item \"$av\":{$js_type}, ";
done
if [[ ! -z $js_item ]]; then
js_item="${js_item::-2}"
fi
js="\"sensor\": {$js_item}"
echo $js
}
#
# Controlla se la zona comandata da un elettrovalvola ha raggiunto l'umidità necessaria per non fare partire l'irrigazione,
# faerla chiudere in caso di pioggia.
# Se è stata superata l'umidità indicata in EVx_SENSOR_MOISTURE ritorna l'umidità attuale del sensore relativo all'elettrovalvola
# in caso contrario ritorna 0, se no è impostato il parametro EV_xSENSOR_ALIAS o EVxSENSOR?MOISTURE ritorna il valore -1
#
# $1 numero elettrovalvola da controllare
#
function ev_check_moisture {
local s=EV"$1"_SENSOR_ALIAS
local sa=${!s}
if [[ -z $sa ]]; then
echo -1
return
fi
local moisture=$(sensor_status $sa moisture)
local s=EV"$1"_SENSOR_MOISTURE
local max_moisture=${!s}
if [ -z $max_moisture ]; then
echo -1
return
fi
if [ $moisture -gt $max_moisture ]; then
log_write "sensor" "info" "ev_check_moisture_autoclose: humidity of the \"$sa\" sensor reached: $moisture%"
echo $moisture
return $moisture
fi
echo 0
return 0
}
#
# Controlla se la zona comandata da un elettrovalvola ha raggiunto l'umidità necessaria per essere chiusa in automatico
# Se è stata superata l'umidità indicata in EVx_SENSOR_MOISTURE ritorna l'umidità attuale del sensore relativo all'elettrovalvola
# in caso contrario ritorna 0, se no è impostato il parametro EV_xSENSOR_ALIAS, EVxSENSOR_MOISTURE o
# EVxSENSOR_MOISTURE_AUTOCLOSE ritorna il valore -1
#
# $1 numero elettrovalvola da controllare
#
function ev_check_moisture_autoclose {
local s=EV"$1"_SENSOR_ALIAS
local sa=${!s}
if [[ -z $sa ]]; then
echo -1
return
fi
local moisture=$(sensor_status $sa moisture)
local s=EV"$1"_SENSOR_MOISTURE
local max_moisture=${!s}
if [ -z $max_moisture ]; then
echo -1
return
fi
local s=EV"$1"_SENSOR_MOISTURE_AUTOCLOSE
local autoclose=${!s}
if [ -z $autoclose ]; then
echo -1
return
fi
if [ $autoclose -ne 1 ]; then
echo -1
return
fi
if [ $moisture -gt $max_moisture ]; then
log_write "sensor" "info" "ev_check_moisture_autoclose: humidity of the \"$sa\" sensor reached: $moisture%"
echo $moisture
return $moisture
fi
echo 0
return 0
}

View File

@@ -19,7 +19,7 @@ function stop_socket_server {
exit 1
fi
log_write "stop socket server"
log_write "socket_server" "info" "stop socket server"
kill -9 $(list_descendants `cat "$TCPSERVER_PID_FILE"`) 2> /dev/null
kill -9 `cat "$TCPSERVER_PID_FILE"` 2> /dev/null
@@ -44,7 +44,7 @@ function socket_server_command {
user=$(echo "$user" | $TR -d '[\r\n]')
password=$(echo "$password" | $TR -d '[\r\n]')
if [ "$user" != "$TCPSERVER_USER" ] || [ "$password" != "$TCPSERVER_PWD" ]; then
log_write "socket connection from: $TCPREMOTEIP - Bad socket server credentials - user:$user"
log_write "socket_server" "warning" "socket connection from: $TCPREMOTEIP - Bad socket server credentials - user:$user"
json_error 0 "Bad socket server credentials"
return
fi
@@ -61,7 +61,7 @@ function socket_server_command {
arg7=$(echo "$line " | $CUT -d ' ' -f7)
arg8=$(echo "$line " | $CUT -d ' ' -f8)
log_write "socket connection from: $TCPREMOTEIP - command: $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8"
log_write "socket_server" "info" "socket connection from: $TCPREMOTEIP - command: $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8"
#reset_messages &> /dev/null
@@ -127,7 +127,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "Cron set failed"
log_write "Cron set failed: $vret"
log_write "socket_server" "error" "Cron set failed: $vret"
else
message_write "success" "Cron set successfull"
json_status
@@ -142,7 +142,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "Cron set failed"
log_write "Cron del failed: $vret"
log_write "socket_server" "error" "Cron del failed: $vret"
else
message_write "success" "Cron set successfull"
json_status
@@ -157,7 +157,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "Cron del failed"
log_write "Cron del failed: $vret"
log_write "socket_server" "error" "Cron del failed: $vret"
else
message_write "success" "Scheduled start successfully deleted"
json_status "get_cron_open_in:$arg2"
@@ -173,7 +173,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "Cron set failed"
log_write "Cron set failed: $vret"
log_write "socket_server" "error" "Cron set failed: $vret"
else
message_write "success" "Cron set successfull"
json_status
@@ -188,7 +188,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "Cron set failed"
log_write "Cron set failed: $vret"
log_write "socket_server" "error" "Cron set failed: $vret"
else
message_write "success" "Cron set successfull"
json_status
@@ -203,7 +203,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "Cron set failed"
log_write "Cron set failed: $vret"
log_write "socket_server" "error" "Cron set failed: $vret"
else
message_write "success" "Cron set successfull"
json_status
@@ -218,7 +218,7 @@ function socket_server_command {
if [[ ! -z $vret ]]; then
json_error 0 "piGardenSched command failed"
log_write "piGardenSched command failed: $vret"
log_write "socket_server" "error" "piGardenSched command failed: $vret"
else
message_write "success" "Schedule set successfull"
json_status
@@ -240,6 +240,27 @@ function socket_server_command {
nohup $PATH_SCRIPT poweroff > /dev/null 2>&1 &
;;
reset_last_rain_sensor_timestamp)
reset_last_rain_sensor_timestamp
message_write "success" "Timestamp of last sensor rain successfull reset"
json_status
;;
reset_last_rain_online_timestamp)
reset_last_rain_online_timestamp
message_write "success" "Timestamp of last online rain successfull reset"
json_status
;;
sensor_status_set)
if [ "empty$arg2" == "empty" ]; then
json_error 0 "Alias sensor not specified"
else
sensor_status_set $arg2 $arg3 $arg4 &> /dev/null
json_status
fi
;;
*)
json_error 0 "invalid command"
;;

View File

@@ -10,7 +10,7 @@
#
function initialize {
log_write "Run initialize"
log_write "general" "info" "Run initialize"
unlock
@@ -50,13 +50,13 @@ function initialize {
# Inizializza il sensore di rilevamento pioggia
if [ -n "$RAIN_GPIO" ]; then
drv_rain_sensor_init "$RAIN_GPIO"
log_write "Rain sensor initialized"
log_write "rain" "info" "Rain sensor initialized"
else
log_write "Rain sensor not present"
log_write "rain" "info" "Rain sensor not present"
fi
trigger_event "init_after" ""
log_write "End initialize"
log_write "general" "info" "End initialize"
}
@@ -88,35 +88,48 @@ function ev_open {
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
local last_rain=`cat $STATUS_DIR/last_rain_online`
local now=`date +%s`
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)"
return
if [ ! "$2" = "force" ]; then
local moisture=$(ev_check_moisture $EVNUM)
if [ $moisture -gt 0 ]; then
message_write "warning" "solenoid not open because maximum soil moisture has been reached"
trigger_event "ev_not_open_for_moisture" "$1"
log_write "irrigate" "warning" "Solenoid '$1' not open because maximum soil moisture has been reached"
return
fi
if [ "$EVNORAIN" != "1" ]; then
if [[ "$NOT_IRRIGATE_IF_RAIN_ONLINE" -gt 0 && -f $STATUS_DIR/last_rain_online ]]; then
local last_rain=`cat $STATUS_DIR/last_rain_online`
local now=`date +%s`
local dif=0
let "dif = now - last_rain"
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_ONLINE ] && [ $moisture -ne 0 ]; 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 "irrigate" "warning" "Solenoid '$1' not open for rain (online check)"
return
fi
fi
check_rain_sensor
if [[ "$NOT_IRRIGATE_IF_RAIN_SENSOR" -gt 0 && -f $STATUS_DIR/last_rain_sensor && $moisture -ne 0 ]]; then
local last_rain=`cat $STATUS_DIR/last_rain_sensor`
local now=`date +%s`
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 "irrigate" "warning" "Solenoid '$1' not open for rain (sensor check)"
return
fi
fi
fi
check_rain_sensor
if [[ "$NOT_IRRIGATE_IF_RAIN_SENSOR" -gt 0 && -f $STATUS_DIR/last_rain_sensor ]]; then
local last_rain=`cat $STATUS_DIR/last_rain_sensor`
local now=`date +%s`
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)"
return
fi
fi
fi
local state=1
@@ -126,7 +139,7 @@ function ev_open {
trigger_event "ev_open_before" "$1" "$2"
if [ $? -ne 0 ]; then
log_write "Solenoid '$1' not open due to external event"
log_write "irrigate" "warning" "Solenoid '$1' not open due to external event"
message_write 'warning' "Solenoid not open due to external event"
mqtt_status
return
@@ -150,7 +163,7 @@ function ev_open {
ev_set_state $EVNUM $state
log_write "Solenoid '$1' open"
log_write "irrigate" "info" "Solenoid '$1' open"
message_write "success" "Solenoid open"
trigger_event "ev_open_after" "$1" "$2"
@@ -259,7 +272,7 @@ function ev_close {
ev_set_state $EVNUM 0
log_write "Solenoid '$1' close"
log_write "irrigate" "info" "Solenoid '$1' close"
message_write "success" "Solenoid close"
trigger_event "ev_close_after" "$1"
@@ -285,7 +298,9 @@ function supply_negative {
#
# Scrive un messaggio nel file di log
# $1 log da scrivere
# $1 type
# $2 level
# $3 log da scrivere
#
function log_write {
if [ -e "$LOG_FILE" ]; then
@@ -304,7 +319,25 @@ function log_write {
fi
fi
echo -e "`date`\t\t$1" >> $LOG_FILE
echo -e "`date`\t\t$1\t$2\t$3" >> $LOG_FILE
log_send "$1" "$2" "`date '+%Y-%m-%d %H:%M:%S'`" "$3"
}
#
# Invia un log verso piGardenWeb
# $1 type
# $2 level
# $3 date time
# $4 messaggio
#
function log_send {
if [[ ! -z "$LOG_URL" ]]; then
$CURL $LOG_CURL_PARAM "$LOG_URL" -d "api_token=$LOG_API_TOKEN&type=$1&level=$2&datetime_log=$3&message=$4" &> /dev/null &
fi
}
#
@@ -373,7 +406,7 @@ function gpio_alias2number {
fi
done
log_write "ERROR solenoid alias not found: $1"
log_write "general" "error" "ERROR solenoid alias not found: $1"
message_write "warning" "Solenoid alias not found"
mqtt_status
exit 1
@@ -393,7 +426,7 @@ function ev_alias2number {
fi
done
log_write "ERROR solenoid alias not found: $1"
log_write "general" "error" "ERROR solenoid alias not found: $1"
message_write "warning" "Solenoid alias not found"
mqtt_status
exit 1
@@ -480,7 +513,7 @@ function close_all {
#echo "$al = $state"
if [[ "$state" -gt "0" || "$1" = "force" ]]; then
ev_close $al
log_write "close_all - Close solenoid '$al' for rain"
log_write "irrigate" "info" "close_all - Close solenoid '$al' for rain"
fi
done
@@ -664,8 +697,9 @@ function json_status {
fi
local json_cron_open_in="\"cron_open_in\":{$json_get_cron_open_in}"
local json_timestamp="\"timestamp\": $(date +%s)"
local json_sensor="$(json_sensor_status_all)"
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 $json_schedule}"
json="{$json_version,$json_timestamp,$json_event,$json,$json_sensor,$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_schedule}"
echo "$json"
@@ -707,10 +741,25 @@ function show_usage {
echo -e "\t$NAME_SCRIPT list_alias view list of aliases 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 "\n"
echo -e "\t$NAME_SCRIPT list_alias_sensor view list of aliases sensor"
echo -e "\t$NAME_SCRIPT sensor_status alias [type] show status sensor (type: $SENSOR_STATE_TYPE)"
echo -e "\t$NAME_SCRIPT sensor_status_set alias type value set status of sensor (type: $SENSOR_STATE_TYPE)"
echo -e "\t$NAME_SCRIPT sensor_status_all show status of all sensors"
echo -e "\n"
echo -e "\t$NAME_SCRIPT last_rain_sensor_timestamp show timestamp of last rain sensor"
echo -e "\t$NAME_SCRIPT last_rain_online_timestamp show timestamp of last rain online"
echo -e "\t$NAME_SCRIPT reset_last_rain_sensor_timestamp show timestamp of last rain sensor"
echo -e "\t$NAME_SCRIPT reset_last_rain_online_timestamp show timestamp of last rain online"
echo -e "\n"
echo -e "\t$NAME_SCRIPT json_status [get_cron|get_cron_open_in|get_schedule] 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 "\n"
echo -e "\t$NAME_SCRIPT check_rain_online check rain from online api service"
echo -e "\t$NAME_SCRIPT check_rain_sensor check rain from hardware sensor"
echo -e "\n"
echo -e "\t$NAME_SCRIPT close_all_for_rain close all solenoid if it's raining"
echo -e "\t$NAME_SCRIPT close_all [force] close all solenoid"
echo -e "\n"
@@ -779,12 +828,12 @@ function lock {
local foo=bar
else
if [ "$current_time" -gt "$max_time" ]; then
log_write "Maximum locked time reached"
log_write "general" "error" "Maximum locked time reached"
sleep $max_time
unlock
exit 1
fi
log_write "Sleep 1 second for locked state"
log_write "general" "info" "Sleep 1 second for locked state"
sleep 1
lock $current_time
return
@@ -833,7 +882,7 @@ function send_identifier {
fi
echo "$ID" > "$FILE_ID"
log_write "Send installation identifier to collect usage"
log_write "general" "info" "Send installation identifier to collect usage"
$CURL https://www.lejubila.net/statistic/collect_usage/piGarden/$ID/$VERSION/$SUB_VERSION/$RELEASE_VERSION > /dev/null 2>&1
@@ -875,7 +924,7 @@ function cmd_pigardensched {
if [ $PIGARDENSCHED == 0 ]; then
echo "piGardenSched not configured in piGarden" >&2
log_write "piGardenSched not configured in piGarden"
log_write "piGardenSched" "error" "piGardenSched not configured in piGarden"
return
fi
@@ -984,7 +1033,7 @@ function debug2 {
VERSION=0
SUB_VERSION=6
RELEASE_VERSION=0
RELEASE_VERSION=5
DIR_SCRIPT=`dirname $0`
NAME_SCRIPT=${0##*/}
@@ -1010,6 +1059,7 @@ fi
. "$DIR_SCRIPT/include/cron.include.sh"
. "$DIR_SCRIPT/include/socket.include.sh"
. "$DIR_SCRIPT/include/rain.include.sh"
. "$DIR_SCRIPT/include/sensor.include.sh"
. "$DIR_SCRIPT/include/events.include.sh"
MESSAGE_INFO=""
@@ -1019,8 +1069,14 @@ MESSAGE_SUCCESS=""
CURRENT_EVENT=""
CURRENT_EVENT_ALIAS=""
SENSOR_STATE_TYPE="moisture temperature fertility illuminance"
PARENT_PID=0
if [ -z $SENSOR_TOTAL ]; then
SENSOR_TOTAL=0
fi
if [ -z $LOG_OUTPUT_DRV_FILE ]; then
LOG_OUTPUT_DRV_FILE="/dev/null"
fi
@@ -1091,6 +1147,26 @@ case "$1" in
ev_status_all
;;
list_alias_sensor)
list_alias_sensor
;;
sensor_status)
sensor_status $2 $3
;;
sensor_status_all)
sensor_status_all
;;
sensor_status_set)
sensor_status_set $2 $3 $4
;;
json_sensor_status_all)
json_sensor_status_all
;;
json_status)
json_status $2 $3 $4 $5 $6
;;
@@ -1099,6 +1175,22 @@ case "$1" in
mqtt_status $2
;;
last_rain_sensor_timestamp)
last_rain_sensor_timestamp
;;
last_rain_online_timestamp)
last_rain_online_timestamp
;;
reset_last_rain_sensor_timestamp)
reset_last_rain_sensor_timestamp
;;
reset_last_rain_online_timestamp)
reset_last_rain_online_timestamp
;;
check_rain_online)
check_rain_online
;;
@@ -1130,7 +1222,7 @@ case "$1" in
nohup $0 start_socket_server_daemon > /dev/null 2>&1 &
echo "Daemon is started widh pid $!"
log_write "start socket server with pid $!"
log_write "socket_server" "info" "start socket server with pid $!"
;;
start_socket_server_daemon)