Spostato diverse parti dello script in file di inclusione, completato driver di esempio
This commit is contained in:
23
drv/sample/rainsensor.include.sh
Normal file
23
drv/sample/rainsensor.include.sh
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#
|
||||||
|
# Inizializza il sensore di rilevamento pioggia
|
||||||
|
#
|
||||||
|
# $i identificativo gpio del sensore di pioggia
|
||||||
|
#
|
||||||
|
function drv_sample_rain_sensor_init {
|
||||||
|
|
||||||
|
echo "$(date) drv_sample_rain_sensor_init $1" >> /tmp/piGarden.drv.sample
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Ritorna lo stato del sensore di rilevamento pioggia
|
||||||
|
#
|
||||||
|
# $i identificativo gpio del sensore di pioggia
|
||||||
|
#
|
||||||
|
function drv_sample_rain_sensor_get {
|
||||||
|
|
||||||
|
echo "$(date) drv_sample_rain_sensor_get $1" >> /tmp/piGarden.drv.sample
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,3 +1,14 @@
|
|||||||
|
#
|
||||||
|
# Inizializzazione rele
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da inizializzare
|
||||||
|
#
|
||||||
|
function drv_sample_rele_init {
|
||||||
|
|
||||||
|
echo "$(date) drv_sample_rele_init $1" >> /tmp/piGarden.drv.sample
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Apertura rele
|
# Apertura rele
|
||||||
#
|
#
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#
|
|
||||||
# Questa funzione viene richiamata da "ev_get_status" di piGarden
|
|
||||||
#
|
|
||||||
# $1 identificativo relè di cui repereire lo stato
|
|
||||||
#
|
|
||||||
function drv_sample_status {
|
|
||||||
|
|
||||||
echo "$(date) drv_sample_status $1" >> /tmp/piGarden.drv.sample
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
36
drv/sample/supply.include.sh
Normal file
36
drv/sample/supply.include.sh
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#
|
||||||
|
# Inizializza i rele che gestiscono l'alimentazione per le valvole bistabili
|
||||||
|
#
|
||||||
|
# $1 identificativo relè 1
|
||||||
|
# $2 identificativo relè 2
|
||||||
|
#
|
||||||
|
function drv_sample_supply_bistable_init {
|
||||||
|
|
||||||
|
echo "$(date) drv_sample_supply_bistable_init $1 $2" >> /tmp/piGarden.drv.sample
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta l'alimentazione delle elettrovalvole con voltaggio positivo
|
||||||
|
#
|
||||||
|
# $1 identificativo relè 1
|
||||||
|
# $2 identificativo relè 2
|
||||||
|
#
|
||||||
|
function drv_sample_supply_positive {
|
||||||
|
|
||||||
|
echo "$(date) drv_sample_supply_positive $1 $2" >> /tmp/piGarden.drv.sample
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta l'alimentazione delle elettrovalvole con voltaggio negativo
|
||||||
|
#
|
||||||
|
# $1 identificativo relè 1
|
||||||
|
# $2 identificativo relè 2
|
||||||
|
#
|
||||||
|
function drv_sample_supply_negative {
|
||||||
|
|
||||||
|
echo "$(date) drv_sample_supply_negative $1 $2" >> /tmp/piGarden.drv.sample
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
491
include/cron.include.sh
Normal file
491
include/cron.include.sh
Normal file
@@ -0,0 +1,491 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Elimina una tipoliga di schedulazione dal crontab dell'utente
|
||||||
|
# $1 tipologia del crontab
|
||||||
|
# $2 argomento della tipologia
|
||||||
|
#
|
||||||
|
function cron_del {
|
||||||
|
|
||||||
|
local CRON_TYPE=$1
|
||||||
|
local CRON_ARG=$2
|
||||||
|
|
||||||
|
if [ -z "$CRON_TYPE" ]; then
|
||||||
|
echo "Cron type is empty" >&2
|
||||||
|
log_write "Cron type is empty"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
$CRONTAB -l > "$TMP_CRON_FILE"
|
||||||
|
local START=`$GREP -n "# START cron $CRON_TYPE $CRON_ARG" "$TMP_CRON_FILE"| $CUT -d : -f 1`
|
||||||
|
local END=`$GREP -n "# END cron $CRON_TYPE $CRON_ARG" "$TMP_CRON_FILE"| $CUT -d : -f 1`
|
||||||
|
local re='^[0-9]+$'
|
||||||
|
|
||||||
|
if ! [[ "$START" =~ $re ]] && ! [[ "$END" =~ $re ]] ; then
|
||||||
|
echo "$1 $2 cron is not present" >&2
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if ! [[ $START =~ $re ]] ; then
|
||||||
|
echo "Cron start don't find" >&2
|
||||||
|
log_write "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"
|
||||||
|
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"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
$SED "$START,${END}d" "$TMP_CRON_FILE" | $SED '$!N; /^\(.*\)\n\1$/!P; D' | $CRONTAB -
|
||||||
|
#$CRONTAB "$TMP_CRON_FILE"
|
||||||
|
rm "$TMP_CRON_FILE"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Aggiunge una schedulazione nel crontab dell'utente
|
||||||
|
# $1 tipologia del crontab
|
||||||
|
# $2 minuto
|
||||||
|
# $3 ora
|
||||||
|
# $4 giorno del mese
|
||||||
|
# $5 mese
|
||||||
|
# $6 giorno della settimana
|
||||||
|
# $7 argomento della tipologia
|
||||||
|
# $8 secondo argomento della tipologia
|
||||||
|
#
|
||||||
|
function cron_add {
|
||||||
|
|
||||||
|
local CRON_TYPE=$1
|
||||||
|
local CRON_M=$2
|
||||||
|
local CRON_H=$3
|
||||||
|
local CRON_DOM=$4
|
||||||
|
local CRON_MON=$5
|
||||||
|
local CRON_DOW=$6
|
||||||
|
local CRON_ARG=$7
|
||||||
|
local CRON_ARG2=$8
|
||||||
|
local CRON_COMMAND=""
|
||||||
|
local CRON_DISABLED=""
|
||||||
|
local PATH_SCRIPT=`$READLINK -f "$DIR_SCRIPT/$NAME_SCRIPT"`
|
||||||
|
local TMP_CRON_FILE2="$TMP_CRON_FILE-2"
|
||||||
|
|
||||||
|
if [ -z "$CRON_TYPE" ]; then
|
||||||
|
echo "Cron type is empty" >&2
|
||||||
|
log_write "Cron type is empty"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
$CRONTAB -l > "$TMP_CRON_FILE"
|
||||||
|
local START=`$GREP -n "# START cron $CRON_TYPE $CRON_ARG" "$TMP_CRON_FILE"| $CUT -d : -f 1`
|
||||||
|
local END=`$GREP -n "# END cron $CRON_TYPE $CRON_ARG" "$TMP_CRON_FILE"| $CUT -d : -f 1`
|
||||||
|
local re='^[0-9]+$'
|
||||||
|
|
||||||
|
local NEW_CRON=0
|
||||||
|
local PREVIUS_CONTENT=""
|
||||||
|
|
||||||
|
if ! [[ $START =~ $re ]] && ! [[ $END =~ $re ]] ; then
|
||||||
|
NEW_CRON=1
|
||||||
|
else
|
||||||
|
if ! [[ $START =~ $re ]] ; then
|
||||||
|
echo "Cron start don't find" >&2
|
||||||
|
log_write "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"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
START=$(($START + 1))
|
||||||
|
END=$(($END - 1))
|
||||||
|
|
||||||
|
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"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
PREVIOUS_CONTENT=`$SED -n "$START,${END}p" "$TMP_CRON_FILE"`
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$CRON_TYPE" in
|
||||||
|
|
||||||
|
init)
|
||||||
|
CRON_M="@reboot"
|
||||||
|
CRON_H=""
|
||||||
|
CRON_DOM=""
|
||||||
|
CRON_MON=""
|
||||||
|
CRON_DOW=""
|
||||||
|
CRON_COMMAND="$PATH_SCRIPT init"
|
||||||
|
;;
|
||||||
|
|
||||||
|
start_socket_server)
|
||||||
|
CRON_M="@reboot"
|
||||||
|
CRON_H=""
|
||||||
|
CRON_DOM=""
|
||||||
|
CRON_MON=""
|
||||||
|
CRON_DOW=""
|
||||||
|
CRON_COMMAND="$PATH_SCRIPT start_socket_server force"
|
||||||
|
;;
|
||||||
|
|
||||||
|
check_rain_online)
|
||||||
|
CRON_M="*/3"
|
||||||
|
CRON_H="*"
|
||||||
|
CRON_DOM="*"
|
||||||
|
CRON_MON="*"
|
||||||
|
CRON_DOW="*"
|
||||||
|
CRON_COMMAND="$PATH_SCRIPT check_rain_online 2> /tmp/check_rain_online.err"
|
||||||
|
;;
|
||||||
|
|
||||||
|
check_rain_sensor)
|
||||||
|
CRON_M="*"
|
||||||
|
CRON_H="*"
|
||||||
|
CRON_DOM="*"
|
||||||
|
CRON_MON="*"
|
||||||
|
CRON_DOW="*"
|
||||||
|
CRON_COMMAND="$PATH_SCRIPT check_rain_sensor 2> /tmp/check_rain_sensor.err"
|
||||||
|
;;
|
||||||
|
|
||||||
|
close_all_for_rain)
|
||||||
|
CRON_M="*/5"
|
||||||
|
CRON_H="*"
|
||||||
|
CRON_DOM="*"
|
||||||
|
CRON_MON="*"
|
||||||
|
CRON_DOW="*"
|
||||||
|
CRON_COMMAND="$PATH_SCRIPT close_all_for_rain 2> /tmp/close_all_for_rain.err 1> /dev/null"
|
||||||
|
;;
|
||||||
|
|
||||||
|
open)
|
||||||
|
CRON_COMMAND="$PATH_SCRIPT open $CRON_ARG"
|
||||||
|
if [ "$CRON_ARG2" == "disabled" ]; then
|
||||||
|
CRON_DISABLED="#"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
open_in)
|
||||||
|
CRON_COMMAND="$PATH_SCRIPT open $CRON_ARG $CRON_ARG2"
|
||||||
|
;;
|
||||||
|
|
||||||
|
open_in_stop)
|
||||||
|
CRON_COMMAND="$PATH_SCRIPT close $CRON_ARG"
|
||||||
|
;;
|
||||||
|
|
||||||
|
close)
|
||||||
|
CRON_COMMAND="$PATH_SCRIPT close $CRON_ARG"
|
||||||
|
if [ "$CRON_ARG2" == "disabled" ]; then
|
||||||
|
CRON_DISABLED="#"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Wrong cron type: $CRON_TYPE"
|
||||||
|
log_write "Wrong cron type: $CRON_TYPE"
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ "$NEW_CRON" -eq "0" ]; then
|
||||||
|
START=$(($START - 1))
|
||||||
|
END=$(($END + 1))
|
||||||
|
$SED "$START,${END}d" "$TMP_CRON_FILE" > "$TMP_CRON_FILE2"
|
||||||
|
else
|
||||||
|
cat "$TMP_CRON_FILE" > "$TMP_CRON_FILE2"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$NEW_CRON" -eq "1" ]; then
|
||||||
|
echo "" >> "$TMP_CRON_FILE2"
|
||||||
|
fi
|
||||||
|
echo "# START cron $CRON_TYPE $CRON_ARG" >> "$TMP_CRON_FILE2"
|
||||||
|
if [ "$NEW_CRON" -eq "0" ]; then
|
||||||
|
echo "$PREVIOUS_CONTENT" >> "$TMP_CRON_FILE2"
|
||||||
|
fi
|
||||||
|
echo "$CRON_DISABLED$CRON_M $CRON_H $CRON_DOM $CRON_MON $CRON_DOW $CRON_COMMAND" >> "$TMP_CRON_FILE2"
|
||||||
|
echo "# END cron $CRON_TYPE $CRON_ARG" >> "$TMP_CRON_FILE2"
|
||||||
|
|
||||||
|
$CRONTAB "$TMP_CRON_FILE2"
|
||||||
|
rm "$TMP_CRON_FILE" "$TMP_CRON_FILE2"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Legge una tipoliga di schedulazione dal crontab dell'utente
|
||||||
|
# $1 tipologia del crontab
|
||||||
|
# $2 argomento della tipologia
|
||||||
|
#
|
||||||
|
function cron_get {
|
||||||
|
|
||||||
|
local CRON_TYPE=$1
|
||||||
|
local CRON_ARG=$2
|
||||||
|
|
||||||
|
if [ -z "$CRON_TYPE" ]; then
|
||||||
|
echo "Cron type is empty" >&2
|
||||||
|
log_write "Cron type is empty"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
$CRONTAB -l > "$TMP_CRON_FILE"
|
||||||
|
local START=`$GREP -n "# START cron $CRON_TYPE $CRON_ARG" "$TMP_CRON_FILE"| $CUT -d : -f 1`
|
||||||
|
local END=`$GREP -n "# END cron $CRON_TYPE $CRON_ARG" "$TMP_CRON_FILE"| $CUT -d : -f 1`
|
||||||
|
local re='^[0-9]+$'
|
||||||
|
|
||||||
|
local PREVIUS_CONTENT=""
|
||||||
|
|
||||||
|
if ! [[ $START =~ $re ]] && ! [[ $END =~ $re ]] ; then
|
||||||
|
PREVIUS_CONTENT=""
|
||||||
|
else
|
||||||
|
if ! [[ $START =~ $re ]] ; then
|
||||||
|
echo "Cron start don't find" >&2
|
||||||
|
log_write "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"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
START=$(($START + 1))
|
||||||
|
END=$(($END - 1))
|
||||||
|
|
||||||
|
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"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
PREVIOUS_CONTENT=`$SED -n "$START,${END}p" "$TMP_CRON_FILE"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$PREVIOUS_CONTENT"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta il cron di inizializzazione della centralina
|
||||||
|
#
|
||||||
|
function set_cron_init {
|
||||||
|
|
||||||
|
cron_del "init" 2> /dev/null
|
||||||
|
cron_add "init"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Elimina il cron di inizializzazione della centralina
|
||||||
|
#
|
||||||
|
function del_cron_init {
|
||||||
|
|
||||||
|
cron_del "init"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta il cron per l'avvio del socket server
|
||||||
|
#
|
||||||
|
function set_cron_start_socket_server {
|
||||||
|
|
||||||
|
cron_del "start_socket_server" 2> /dev/null
|
||||||
|
cron_add "start_socket_server"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Elimina il cron per l'avvio del socket server
|
||||||
|
#
|
||||||
|
function del_cron_start_socket_server {
|
||||||
|
|
||||||
|
cron_del "start_socket_server"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta il cron che esegue il controllo di presenza pioggia tramite sensore
|
||||||
|
#
|
||||||
|
function set_cron_check_rain_sensor {
|
||||||
|
|
||||||
|
cron_del "check_rain_sensor" 2> /dev/null
|
||||||
|
cron_add "check_rain_sensor"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Elimina il cron che esegue il controllo di presenza pioggia tramite sensore
|
||||||
|
#
|
||||||
|
function del_cron_check_rain_sensor {
|
||||||
|
|
||||||
|
cron_del "check_rain_sensor"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta il cron che esegue il controllo di presenza pioggia tramite servizio online
|
||||||
|
#
|
||||||
|
function set_cron_check_rain_online {
|
||||||
|
|
||||||
|
cron_del "check_rain_online" 2> /dev/null
|
||||||
|
cron_add "check_rain_online"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Elimina il cron che esegue il controllo di presenza pioggia tramite servizio online
|
||||||
|
#
|
||||||
|
function del_cron_check_rain_online {
|
||||||
|
|
||||||
|
cron_del "check_rain_online"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta il cron che gestisce la chiusura delle elettrovalvole in caso di pioggia
|
||||||
|
#
|
||||||
|
function set_cron_close_all_for_rain {
|
||||||
|
|
||||||
|
cron_del "close_all_for_rain" 2> /dev/null
|
||||||
|
cron_add "close_all_for_rain"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Elimina il cron che gestisce la chiusura delle elettrovalvole in caso di pioggia
|
||||||
|
#
|
||||||
|
function del_cron_close_all_for_rain {
|
||||||
|
|
||||||
|
cron_del "close_all_for_rain"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Aggiunge una schedulazione cron per aprire una elettrovalvola
|
||||||
|
# $1 alias elettrovalvola
|
||||||
|
# $2 minuto cron
|
||||||
|
# $3 ora cron
|
||||||
|
# $4 giorno del mese cron
|
||||||
|
# $5 mese cron
|
||||||
|
# $6 giorno della settimana cron
|
||||||
|
# $7 disabled
|
||||||
|
#
|
||||||
|
function add_cron_open {
|
||||||
|
|
||||||
|
local exists=`alias_exists $1`
|
||||||
|
if [ "check $exists" = "check FALSE" ]; then
|
||||||
|
log_write "Alias $1 not found"
|
||||||
|
echo "Alias $1 not found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cron_add "open" "$2" "$3" "$4" "$5" "$6" "$1" "$7"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Cancella tutte le schedulazioni cron per aprire una elettrovalvola
|
||||||
|
# $1 alias elettrovalvola
|
||||||
|
#
|
||||||
|
function del_cron_open {
|
||||||
|
|
||||||
|
local exists=`alias_exists $1`
|
||||||
|
if [ "check $exists" = "check FALSE" ]; then
|
||||||
|
log_write "Alias $1 not found"
|
||||||
|
echo "Alias $1 not found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cron_del "open" $1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Legge tutte le schedulazioni cron per aprire una elettrovalvola
|
||||||
|
# $1 alias elettrovalvola
|
||||||
|
#
|
||||||
|
function get_cron_open {
|
||||||
|
|
||||||
|
local exists=`alias_exists $1`
|
||||||
|
if [ "check $exists" = "check FALSE" ]; then
|
||||||
|
log_write "Alias $1 not found"
|
||||||
|
echo "Alias $1 not found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cron_get "open" $1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Cancella tutte le schedulazioni cron per aprire/chiudere una elettrovalvola in modo ritardato
|
||||||
|
# $1 alias elettrovalvola
|
||||||
|
#
|
||||||
|
function del_cron_open_in {
|
||||||
|
|
||||||
|
local exists=`alias_exists $1`
|
||||||
|
if [ "check $exists" = "check FALSE" ]; then
|
||||||
|
log_write "Alias $1 not found"
|
||||||
|
echo "Alias $1 not found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cron_del "open_in" $1
|
||||||
|
cron_del "open_in_stop" $1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Legge tutte le schedulazioni cron per chiudere una elettrovalvola
|
||||||
|
# $1 alias elettrovalvola
|
||||||
|
#
|
||||||
|
function get_cron_close {
|
||||||
|
|
||||||
|
local exists=`alias_exists $1`
|
||||||
|
if [ "check $exists" = "check FALSE" ]; then
|
||||||
|
log_write "Alias $1 not found"
|
||||||
|
echo "Alias $1 not found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cron_get "close" $1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Aggiunge una schedulazione cron per chiudere una elettrovalvola
|
||||||
|
# $1 alias elettrovalvola
|
||||||
|
# $2 minuto cron
|
||||||
|
# $3 ora cron
|
||||||
|
# $4 giorno del mese cron
|
||||||
|
# $5 mese cron
|
||||||
|
# $6 giorno della settimana cron
|
||||||
|
# $7 disabled
|
||||||
|
#
|
||||||
|
function add_cron_close {
|
||||||
|
|
||||||
|
local exists=`alias_exists $1`
|
||||||
|
if [ "check $exists" = "check FALSE" ]; then
|
||||||
|
log_write "Alias $1 not found"
|
||||||
|
echo "Alias $1 not found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cron_add "close" "$2" "$3" "$4" "$5" "$6" "$1" "$7"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Cancella tutte le schedulazioni cron per chiudere una elettrovalvola
|
||||||
|
# $1 alias elettrovalvola
|
||||||
|
#
|
||||||
|
function del_cron_close {
|
||||||
|
|
||||||
|
local exists=`alias_exists $1`
|
||||||
|
if [ "check $exists" = "check FALSE" ]; then
|
||||||
|
log_write "Alias $1 not found"
|
||||||
|
echo "Alias $1 not found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cron_del "close" $1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
declare -A drv_avalible
|
#declare -A drv_avalible
|
||||||
|
declare -a list_drv
|
||||||
|
|
||||||
function setup_drv {
|
function setup_drv {
|
||||||
|
|
||||||
declare -a list_drv
|
#declare -a list_drv
|
||||||
list_drv=()
|
list_drv=()
|
||||||
|
|
||||||
# Inizializza i driver per le elettrovalvole
|
# Inizializza i driver per le elettrovalvole
|
||||||
@@ -18,16 +19,25 @@ function setup_drv {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Inizializza i driver per gli altri gpio
|
||||||
|
for gpio in "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2" "$RAIN_GPIO"
|
||||||
|
do
|
||||||
|
if [[ "$gpio" == drv:* ]]; then
|
||||||
|
local drv=`echo $gpio | $CUT -d':' -f2,2`
|
||||||
|
if [[ ! " ${list_drv[@]} " =~ " ${drv} " ]]; then
|
||||||
|
list_drv+=("$drv")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
local file_drv
|
local file_drv
|
||||||
for drv in "${list_drv[@]}"
|
for drv in "${list_drv[@]}"
|
||||||
do
|
do
|
||||||
for callback in init releopenclose status
|
for callback in init rele supply rainsensor
|
||||||
do
|
do
|
||||||
file_drv="$DIR_SCRIPT/drv/$drv/$callback.include.sh"
|
file_drv="$DIR_SCRIPT/drv/$drv/$callback.include.sh"
|
||||||
if [ -f "$file_drv" ]; then
|
if [ -f "$file_drv" ]; then
|
||||||
drv_avalible[$drv]="${drv_avalible[$drv]}#$callback#"
|
#drv_avalible[$drv]="${drv_avalible[$drv]}#$callback#"
|
||||||
#echo ${drv_avalible[$drv]}
|
#echo ${drv_avalible[$drv]}
|
||||||
. "$file_drv"
|
. "$file_drv"
|
||||||
fi
|
fi
|
||||||
@@ -35,3 +45,249 @@ function setup_drv {
|
|||||||
done
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Restituisce in output il nome del driver callback function da richiamare per una specifica funzione
|
||||||
|
#
|
||||||
|
# $1 nome della funzione per il quale si vuore recuperare la callback
|
||||||
|
# $2 idetificativo del driver
|
||||||
|
function get_driver_callback {
|
||||||
|
local fnc="$1"
|
||||||
|
local idx="$2"
|
||||||
|
local ret=""
|
||||||
|
|
||||||
|
if [[ "$idx" == drv:* ]]; then
|
||||||
|
local drv=`echo $idx | $CUT -d':' -f2,2`
|
||||||
|
if [[ ! " ${list_drv[@]} " =~ " ${drv} " ]]; then
|
||||||
|
ret="drvnotfound"
|
||||||
|
else
|
||||||
|
ret="drv_${drv}_${fnc}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "$ret"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Inizializza un relè e lo porta nello stato aperto
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da inizializzare
|
||||||
|
#
|
||||||
|
function drv_rele_init {
|
||||||
|
local idx="$1"
|
||||||
|
local fnc=`get_driver_callback "rele_init" "$idx"`
|
||||||
|
|
||||||
|
# Nessun driver definito, esegue la chiusura del relè tramite gpio del raspberry
|
||||||
|
if [ -z "$fnc" ]; then
|
||||||
|
$GPIO -g write $idx RELE_GPIO_OPEN # chiude l'alimentazione all'elettrovalvole
|
||||||
|
$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"
|
||||||
|
message_write "warning" "Driver not found: $idx"
|
||||||
|
else
|
||||||
|
$fnc "$idx"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Chiude un relè
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da chiudere
|
||||||
|
#
|
||||||
|
function drv_rele_close {
|
||||||
|
local idx="$1"
|
||||||
|
local fnc=`get_driver_callback "rele_close" "$idx"`
|
||||||
|
|
||||||
|
# Nessun driver definito, esegue la chiusura del relè tramite gpio del raspberry
|
||||||
|
if [ -z "$fnc" ]; then
|
||||||
|
$GPIO -g write $idx $RELE_GPIO_CLOSE
|
||||||
|
# Il driver definito non è stato trovato
|
||||||
|
elif [ "$fnc" == "drvnotfound" ]; then
|
||||||
|
log_write "Driver not found: $idx"
|
||||||
|
message_write "warning" "Driver not found: $idx"
|
||||||
|
else
|
||||||
|
$fnc "$idx"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Apre un relè
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da aprire
|
||||||
|
#
|
||||||
|
function drv_rele_open {
|
||||||
|
local idx="$1"
|
||||||
|
local fnc=`get_driver_callback "rele_open" "$idx"`
|
||||||
|
|
||||||
|
# Nessun driver definito, esegue la chiusura del relè tramite gpio del raspberry
|
||||||
|
if [ -z "$fnc" ]; then
|
||||||
|
$GPIO -g write $idx $RELE_GPIO_OPEN
|
||||||
|
# Il driver definito non è stato trovato
|
||||||
|
elif [ "$fnc" == "drvnotfound" ]; then
|
||||||
|
log_write "Driver not found: $idx"
|
||||||
|
message_write "warning" "Driver not found: $idx"
|
||||||
|
else
|
||||||
|
$fnc "$idx"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Inizializza i rele che gestiscono l'alimentazione per le valvole bistabili
|
||||||
|
#
|
||||||
|
# $1 identificativo relè 1
|
||||||
|
# $2 identificativo relè 2
|
||||||
|
#
|
||||||
|
function drv_supply_bistable_init {
|
||||||
|
local idx1=$1
|
||||||
|
local idx2=$2
|
||||||
|
local fnc1=`get_driver_callback "supply_bistable_init" "$idx1"`
|
||||||
|
local fnc2=`get_driver_callback "supply_bistable_init" "$idx2"`
|
||||||
|
|
||||||
|
# Nessun driver definito, esegue l'operazione tramite gpio del raspberry
|
||||||
|
if [ -z "$fnc1" ]; then
|
||||||
|
$GPIO -g write $idx1 0
|
||||||
|
$GPIO -g mode $idx1 out
|
||||||
|
# Il driver definito non è stato trovato
|
||||||
|
elif [ "$fnc1" == "drvnotfound" ]; then
|
||||||
|
log_write "Driver not found: $idx1"
|
||||||
|
message_write "warning" "Driver not found: $idx1"
|
||||||
|
return
|
||||||
|
else
|
||||||
|
$fnc1 "$idx1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Nessun driver definito, esegue l'operazione tramite gpio del raspberry
|
||||||
|
if [ -z "$fnc2" ]; then
|
||||||
|
$GPIO -g write $idx2 0
|
||||||
|
$GPIO -g mode $idx2 out
|
||||||
|
# Il driver definito non è stato trovato
|
||||||
|
elif [ "$fnc2" == "drvnotfound" ]; then
|
||||||
|
log_write "Driver not found: $idx2"
|
||||||
|
message_write "warning" "Driver not found: $idx2"
|
||||||
|
else
|
||||||
|
$fnc2 "$idx2"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta la tensine positiva per le elettrovalvole bistabili
|
||||||
|
#
|
||||||
|
# $1 identificativo rele 1
|
||||||
|
# $2 identificativo rele 2
|
||||||
|
#
|
||||||
|
function drv_supply_positive {
|
||||||
|
local idx1=$1
|
||||||
|
local idx2=$2
|
||||||
|
local fnc1=`get_driver_callback "supply_positive" "$idx1"`
|
||||||
|
local fnc2=`get_driver_callback "supply_positive" "$idx2"`
|
||||||
|
|
||||||
|
# Nessun driver definito, esegue l'operazione tramite gpio del raspberry
|
||||||
|
if [ -z "$fnc1" ]; then
|
||||||
|
$GPIO -g write $idx1 $SUPPLY_GPIO_POS
|
||||||
|
# Il driver definito non è stato trovato
|
||||||
|
elif [ "$fnc1" == "drvnotfound" ]; then
|
||||||
|
log_write "Driver not found: $idx1"
|
||||||
|
message_write "warning" "Driver not found: $idx1"
|
||||||
|
return
|
||||||
|
else
|
||||||
|
$fnc1 "$idx1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Nessun driver definito, esegue l'operazione tramite gpio del raspberry
|
||||||
|
if [ -z "$fnc2" ]; then
|
||||||
|
$GPIO -g write $idx2 $SUPPLY_GPIO_POS
|
||||||
|
# Il driver definito non è stato trovato
|
||||||
|
elif [ "$fnc2" == "drvnotfound" ]; then
|
||||||
|
log_write "Driver not found: $idx2"
|
||||||
|
message_write "warning" "Driver not found: $idx2"
|
||||||
|
else
|
||||||
|
$fnc2 "$idx2"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta la tensine neagativa per le elettrovalvole bistabili
|
||||||
|
#
|
||||||
|
# $1 identificativo rele 1
|
||||||
|
# $2 identificativo rele 2
|
||||||
|
#
|
||||||
|
function drv_supply_negative {
|
||||||
|
local idx1=$1
|
||||||
|
local idx2=$2
|
||||||
|
local fnc1=`get_driver_callback "supply_negative" "$idx1"`
|
||||||
|
local fnc2=`get_driver_callback "supply_negative" "$idx2"`
|
||||||
|
|
||||||
|
# Nessun driver definito, esegue l'operazione tramite gpio del raspberry
|
||||||
|
if [ -z "$fnc1" ]; then
|
||||||
|
$GPIO -g write $idx1 $SUPPLY_GPIO_NEG
|
||||||
|
# Il driver definito non è stato trovato
|
||||||
|
elif [ "$fnc1" == "drvnotfound" ]; then
|
||||||
|
log_write "Driver not found: $idx1"
|
||||||
|
message_write "warning" "Driver not found: $idx1"
|
||||||
|
return
|
||||||
|
else
|
||||||
|
$fnc1 "$idx1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Nessun driver definito, esegue l'operazione tramite gpio del raspberry
|
||||||
|
if [ -z "$fnc2" ]; then
|
||||||
|
$GPIO -g write $idx2 $SUPPLY_GPIO_NEG
|
||||||
|
# Il driver definito non è stato trovato
|
||||||
|
elif [ "$fnc2" == "drvnotfound" ]; then
|
||||||
|
log_write "Driver not found: $idx2"
|
||||||
|
message_write "warning" "Driver not found: $idx2"
|
||||||
|
else
|
||||||
|
$fnc2 "$idx2"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Inizializza il sensore della pioggia
|
||||||
|
#
|
||||||
|
# $1 identificativo gpio sensore pioggia
|
||||||
|
#
|
||||||
|
function drv_rain_sensor_init {
|
||||||
|
local idx="$1"
|
||||||
|
local fnc=`get_driver_callback "rain_sensor_init" "$idx"`
|
||||||
|
local vret=""
|
||||||
|
|
||||||
|
# Nessun driver definito, esegue la lettura del sensore tramite gpio del raspberry
|
||||||
|
if [ -z "$fnc" ]; then
|
||||||
|
$GPIO -g mode $idx in
|
||||||
|
# Il driver definito non è stato trovato
|
||||||
|
elif [ "$fnc" == "drvnotfound" ]; then
|
||||||
|
log_write "Driver not found: $idx"
|
||||||
|
message_write "warning" "Driver not found: $idx"
|
||||||
|
else
|
||||||
|
$fnc "$idx"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Legge lo stato del sensore della pioggia
|
||||||
|
#
|
||||||
|
# $1 identificativo gpio sensore pioggia
|
||||||
|
#
|
||||||
|
function drv_rain_sensor_get {
|
||||||
|
local idx="$1"
|
||||||
|
local fnc=`get_driver_callback "rain_sensor_get" "$idx"`
|
||||||
|
local vret=""
|
||||||
|
|
||||||
|
# Nessun driver definito, esegue la lettura del sensore tramite gpio del raspberry
|
||||||
|
if [ -z "$fnc" ]; then
|
||||||
|
val=`$GPIO -g read $idx`
|
||||||
|
# Il driver definito non è stato trovato
|
||||||
|
elif [ "$fnc" == "drvnotfound" ]; then
|
||||||
|
log_write "Driver not found: $idx"
|
||||||
|
message_write "warning" "Driver not found: $idx"
|
||||||
|
else
|
||||||
|
vret=`$fnc "$idx"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$vret"
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
211
include/socket.include.sh
Normal file
211
include/socket.include.sh
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Avvia il socket server
|
||||||
|
#
|
||||||
|
function start_socket_server {
|
||||||
|
|
||||||
|
rm -f "$TCPSERVER_PID_FILE"
|
||||||
|
echo $TCPSERVER_PID_SCRIPT > "$TCPSERVER_PID_FILE"
|
||||||
|
$TCPSERVER -v -RHl0 $TCPSERVER_IP $TCPSERVER_PORT $0 socket_server_command
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Ferma il socket server
|
||||||
|
#
|
||||||
|
function stop_socket_server {
|
||||||
|
|
||||||
|
if [ ! -f "$TCPSERVER_PID_FILE" ]; then
|
||||||
|
echo "Daemon is not running"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_write "stop socket server"
|
||||||
|
|
||||||
|
kill -9 $(list_descendants `cat "$TCPSERVER_PID_FILE"`) 2> /dev/null
|
||||||
|
kill -9 `cat "$TCPSERVER_PID_FILE"` 2> /dev/null
|
||||||
|
rm -f "$TCPSERVER_PID_FILE"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Esegue un comando ricevuto dal socket server
|
||||||
|
#
|
||||||
|
function socket_server_command {
|
||||||
|
|
||||||
|
RUN_FROM_TCPSERVER=1
|
||||||
|
|
||||||
|
local line=""
|
||||||
|
|
||||||
|
if [ ! -z "$TCPSERVER_USER" ] && [ ! -z "$TCPSERVER_PWD" ]; then
|
||||||
|
local user=""
|
||||||
|
local password=""
|
||||||
|
read -t 3 user
|
||||||
|
read -t 3 password
|
||||||
|
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"
|
||||||
|
json_error 0 "Bad socket server credentials"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
read line
|
||||||
|
line=$(echo "$line " | $TR -d '[\r\n]')
|
||||||
|
arg1=$(echo "$line " | $CUT -d ' ' -f1)
|
||||||
|
arg2=$(echo "$line " | $CUT -d ' ' -f2)
|
||||||
|
arg3=$(echo "$line " | $CUT -d ' ' -f3)
|
||||||
|
arg4=$(echo "$line " | $CUT -d ' ' -f4)
|
||||||
|
arg5=$(echo "$line " | $CUT -d ' ' -f5)
|
||||||
|
arg6=$(echo "$line " | $CUT -d ' ' -f6)
|
||||||
|
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"
|
||||||
|
|
||||||
|
reset_messages &> /dev/null
|
||||||
|
|
||||||
|
case "$arg1" in
|
||||||
|
status)
|
||||||
|
json_status $arg2 $arg3 $arg4 $arg5 $arg6 $arg7
|
||||||
|
;;
|
||||||
|
|
||||||
|
open)
|
||||||
|
if [ "empty$arg2" == "empty" ]; then
|
||||||
|
json_error 0 "Alias solenoid not specified"
|
||||||
|
else
|
||||||
|
ev_open $arg2 $arg3 &> /dev/null
|
||||||
|
json_status "get_cron_open_in"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
open_in)
|
||||||
|
ev_open_in $arg2 $arg3 $arg4 $arg5 &> /dev/null
|
||||||
|
json_status "get_cron_open_in"
|
||||||
|
;;
|
||||||
|
|
||||||
|
close)
|
||||||
|
if [ "empty$arg2" == "empty" ]; then
|
||||||
|
json_error 0 "Alias solenoid not specified"
|
||||||
|
else
|
||||||
|
ev_close $arg2 &> /dev/null
|
||||||
|
json_status "get_cron_open_in"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
set_general_cron)
|
||||||
|
local vret=""
|
||||||
|
for i in $arg2 $arg3 $arg4 $arg5 $arg6 $arg7
|
||||||
|
do
|
||||||
|
if [ $i = "set_cron_init" ]; then
|
||||||
|
vret="$(vret)`set_cron_init`"
|
||||||
|
elif [ $i = "set_cron_start_socket_server" ]; then
|
||||||
|
vret="$(vret)`set_cron_start_socket_server`"
|
||||||
|
elif [ $i = "set_cron_check_rain_sensor" ]; then
|
||||||
|
vret="$(vret)`set_cron_check_rain_sensor`"
|
||||||
|
elif [ $i = "set_cron_check_rain_online" ]; then
|
||||||
|
vret="$(vret)`set_cron_check_rain_online`"
|
||||||
|
elif [ $i = "set_cron_close_all_for_rain" ]; then
|
||||||
|
vret="$(vret)`set_cron_close_all_for_rain`"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ! -z $vret ]]; then
|
||||||
|
json_error 0 "Cron set failed"
|
||||||
|
log_write "Cron set failed: $vret"
|
||||||
|
else
|
||||||
|
message_write "success" "Cron set successfull"
|
||||||
|
json_status
|
||||||
|
fi
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
|
del_cron_open)
|
||||||
|
local vret=""
|
||||||
|
|
||||||
|
vret=`del_cron_open $arg2`
|
||||||
|
|
||||||
|
if [[ ! -z $vret ]]; then
|
||||||
|
json_error 0 "Cron set failed"
|
||||||
|
log_write "Cron del failed: $vret"
|
||||||
|
else
|
||||||
|
message_write "success" "Cron set successfull"
|
||||||
|
json_status
|
||||||
|
fi
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
|
del_cron_open_in)
|
||||||
|
local vret=""
|
||||||
|
|
||||||
|
vret=`del_cron_open_in $arg2`
|
||||||
|
|
||||||
|
if [[ ! -z $vret ]]; then
|
||||||
|
json_error 0 "Cron del failed"
|
||||||
|
log_write "Cron del failed: $vret"
|
||||||
|
else
|
||||||
|
message_write "success" "Scheduled start successfully deleted"
|
||||||
|
json_status "get_cron_open_in"
|
||||||
|
fi
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
|
|
||||||
|
del_cron_close)
|
||||||
|
local vret=""
|
||||||
|
|
||||||
|
vret=`del_cron_close $arg2`
|
||||||
|
|
||||||
|
if [[ ! -z $vret ]]; then
|
||||||
|
json_error 0 "Cron set failed"
|
||||||
|
log_write "Cron set failed: $vret"
|
||||||
|
else
|
||||||
|
message_write "success" "Cron set successfull"
|
||||||
|
json_status
|
||||||
|
fi
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
|
add_cron_open)
|
||||||
|
local vret=""
|
||||||
|
|
||||||
|
vret=`add_cron_open "$arg2" "$arg3" "$arg4" "$arg5" "$arg6" "$arg7" $arg8`
|
||||||
|
|
||||||
|
if [[ ! -z $vret ]]; then
|
||||||
|
json_error 0 "Cron set failed"
|
||||||
|
log_write "Cron set failed: $vret"
|
||||||
|
else
|
||||||
|
message_write "success" "Cron set successfull"
|
||||||
|
json_status
|
||||||
|
fi
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
|
add_cron_close)
|
||||||
|
local vret=""
|
||||||
|
|
||||||
|
vret=`add_cron_close "$arg2" "$arg3" "$arg4" "$arg5" "$arg6" "$arg7" $arg8`
|
||||||
|
|
||||||
|
if [[ ! -z $vret ]]; then
|
||||||
|
json_error 0 "Cron set failed"
|
||||||
|
log_write "Cron set failed: $vret"
|
||||||
|
else
|
||||||
|
message_write "success" "Cron set successfull"
|
||||||
|
json_status
|
||||||
|
fi
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
json_error 0 "invalid command"
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
|
||||||
|
reset_messages &> /dev/null
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
761
piGarden.sh
761
piGarden.sh
@@ -14,12 +14,19 @@ function initialize {
|
|||||||
|
|
||||||
log_write "Run initialize"
|
log_write "Run initialize"
|
||||||
|
|
||||||
|
# Iniziazlizza i driver gpio
|
||||||
|
for drv in "${list_drv[@]}"
|
||||||
|
do
|
||||||
|
drv_${drv}_init
|
||||||
|
done
|
||||||
|
|
||||||
# Imposta l'alimentazione con voltaggio negativo e setta i gpio in scrittura per le elettrovalvole bistabili
|
# Imposta l'alimentazione con voltaggio negativo e setta i gpio in scrittura per le elettrovalvole bistabili
|
||||||
if [ "$EV_MONOSTABLE" != "1" ]; then
|
if [ "$EV_MONOSTABLE" != "1" ]; then
|
||||||
$GPIO -g write $SUPPLY_GPIO_1 0
|
drv_supply_bistable_init "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2"
|
||||||
$GPIO -g write $SUPPLY_GPIO_2 0
|
#$GPIO -g write $SUPPLY_GPIO_1 0
|
||||||
$GPIO -g mode $SUPPLY_GPIO_1 out
|
#$GPIO -g write $SUPPLY_GPIO_2 0
|
||||||
$GPIO -g mode $SUPPLY_GPIO_2 out
|
#$GPIO -g mode $SUPPLY_GPIO_1 out
|
||||||
|
#$GPIO -g mode $SUPPLY_GPIO_2 out
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Elimina tutti gli stati delle elettrovalvole preesistenti
|
# Elimina tutti gli stati delle elettrovalvole preesistenti
|
||||||
@@ -29,8 +36,9 @@ function initialize {
|
|||||||
for i in $(seq $EV_TOTAL)
|
for i in $(seq $EV_TOTAL)
|
||||||
do
|
do
|
||||||
g=EV"$i"_GPIO
|
g=EV"$i"_GPIO
|
||||||
$GPIO -g write ${!g} RELE_GPIO_OPEN # chiude l'alimentazione all'elettrovalvole
|
drv_rele_init "${!g}"
|
||||||
$GPIO -g mode ${!g} out # setta il gpio nella modalita di scrittura
|
#$GPIO -g write ${!g} RELE_GPIO_OPEN # chiude l'alimentazione all'elettrovalvole
|
||||||
|
#$GPIO -g mode ${!g} out # setta il gpio nella modalita di scrittura
|
||||||
ev_set_state $i 0
|
ev_set_state $i 0
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -44,7 +52,8 @@ function initialize {
|
|||||||
|
|
||||||
# Inizializza il sensore di rilevamento pioggia
|
# Inizializza il sensore di rilevamento pioggia
|
||||||
if [ -n "$RAIN_GPIO" ]; then
|
if [ -n "$RAIN_GPIO" ]; then
|
||||||
$GPIO -g mode $RAIN_GPIO in
|
drv_rain_sensor_init "$RAIN_GPIO"
|
||||||
|
#$GPIO -g mode $RAIN_GPIO in
|
||||||
log_write "Rain sensor initialized"
|
log_write "Rain sensor initialized"
|
||||||
else
|
else
|
||||||
log_write "Rain sensor not present"
|
log_write "Rain sensor not present"
|
||||||
@@ -109,19 +118,21 @@ function ev_open {
|
|||||||
# Dall'alias dell'elettrovalvola recupero il numero e dal numero recupero gpio da usare
|
# Dall'alias dell'elettrovalvola recupero il numero e dal numero recupero gpio da usare
|
||||||
ev_alias2number $1
|
ev_alias2number $1
|
||||||
EVNUM=$?
|
EVNUM=$?
|
||||||
ev_number2gpio $EVNUM
|
g=`ev_number2gpio $EVNUM`
|
||||||
g=$?
|
|
||||||
|
|
||||||
lock
|
lock
|
||||||
|
|
||||||
# Gestisce l'apertura dell'elettrovalvola in base alla tipologia (monostabile / bistabile)
|
# Gestisce l'apertura dell'elettrovalvola in base alla tipologia (monostabile / bistabile)
|
||||||
if [ "$EV_MONOSTABLE" == "1" ]; then
|
if [ "$EV_MONOSTABLE" == "1" ]; then
|
||||||
$GPIO -g write $g $RELE_GPIO_CLOSE
|
#$GPIO -g write $g $RELE_GPIO_CLOSE
|
||||||
|
drv_rele_close "$g"
|
||||||
else
|
else
|
||||||
supply_positive
|
supply_positive
|
||||||
$GPIO -g write $g $RELE_GPIO_CLOSE
|
#$GPIO -g write $g $RELE_GPIO_CLOSE
|
||||||
|
drv_rele_close "$g"
|
||||||
sleep 1
|
sleep 1
|
||||||
$GPIO -g write $g $RELE_GPIO_OPEN
|
#$GPIO -g write $g $RELE_GPIO_OPEN
|
||||||
|
drv_rele_open "$g"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ev_set_state $EVNUM $state
|
ev_set_state $EVNUM $state
|
||||||
@@ -202,19 +213,21 @@ function ev_close {
|
|||||||
# Dall'alias dell'elettrovalvola recupero il numero e dal numero recupero gpio da usare
|
# Dall'alias dell'elettrovalvola recupero il numero e dal numero recupero gpio da usare
|
||||||
ev_alias2number $1
|
ev_alias2number $1
|
||||||
EVNUM=$?
|
EVNUM=$?
|
||||||
ev_number2gpio $EVNUM
|
g=`ev_number2gpio $EVNUM`
|
||||||
g=$?
|
|
||||||
|
|
||||||
lock
|
lock
|
||||||
|
|
||||||
# Gestisce l'apertura dell'elettrovalvola in base alla tipologia (monostabile / bistabile)
|
# Gestisce l'apertura dell'elettrovalvola in base alla tipologia (monostabile / bistabile)
|
||||||
if [ "$EV_MONOSTABLE" == "1" ]; then
|
if [ "$EV_MONOSTABLE" == "1" ]; then
|
||||||
$GPIO -g write $g $RELE_GPIO_OPEN
|
#$GPIO -g write $g $RELE_GPIO_OPEN
|
||||||
|
drv_rele_open "$g"
|
||||||
else
|
else
|
||||||
supply_negative
|
supply_negative
|
||||||
$GPIO -g write $g $RELE_GPIO_CLOSE
|
#$GPIO -g write $g $RELE_GPIO_CLOSE
|
||||||
|
drv_rele_close "$g"
|
||||||
sleep 1
|
sleep 1
|
||||||
$GPIO -g write $g $RELE_GPIO_OPEN
|
#$GPIO -g write $g $RELE_GPIO_OPEN
|
||||||
|
drv_rele_open "$g"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ev_set_state $EVNUM 0
|
ev_set_state $EVNUM 0
|
||||||
@@ -231,16 +244,18 @@ function ev_close {
|
|||||||
# Imposta l'alimentazione delle elettrovalvole con voltaggio positivo
|
# Imposta l'alimentazione delle elettrovalvole con voltaggio positivo
|
||||||
#
|
#
|
||||||
function supply_positive {
|
function supply_positive {
|
||||||
$GPIO -g write $SUPPLY_GPIO_1 $SUPPLY_GPIO_POS
|
drv_supply_positive "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2"
|
||||||
$GPIO -g write $SUPPLY_GPIO_2 $SUPPLY_GPIO_POS
|
#$GPIO -g write $SUPPLY_GPIO_1 $SUPPLY_GPIO_POS
|
||||||
|
#$GPIO -g write $SUPPLY_GPIO_2 $SUPPLY_GPIO_POS
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Imposta l'alimentazione delle elettrovalvole con voltaggio negativo
|
# Imposta l'alimentazione delle elettrovalvole con voltaggio negativo
|
||||||
#
|
#
|
||||||
function supply_negative {
|
function supply_negative {
|
||||||
$GPIO -g write $SUPPLY_GPIO_1 $SUPPLY_GPIO_NEG
|
drv_supply_negative "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2"
|
||||||
$GPIO -g write $SUPPLY_GPIO_2 $SUPPLY_GPIO_NEG
|
#$GPIO -g write $SUPPLY_GPIO_1 $SUPPLY_GPIO_NEG
|
||||||
|
#$GPIO -g write $SUPPLY_GPIO_2 $SUPPLY_GPIO_NEG
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -363,7 +378,7 @@ function ev_number2gpio {
|
|||||||
g=EV"$i"_GPIO
|
g=EV"$i"_GPIO
|
||||||
gv=${!g}
|
gv=${!g}
|
||||||
# echo "gv = $gv"
|
# echo "gv = $gv"
|
||||||
return $gv
|
echo "$gv"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -430,7 +445,8 @@ function check_rain_online {
|
|||||||
function check_rain_sensor {
|
function check_rain_sensor {
|
||||||
|
|
||||||
if [ -n "$RAIN_GPIO" ]; then
|
if [ -n "$RAIN_GPIO" ]; then
|
||||||
local s=`$GPIO -g read $RAIN_GPIO`
|
#local s=`$GPIO -g read $RAIN_GPIO`
|
||||||
|
local s=`drv_rain_sensor_get $RAIN_GPIO`
|
||||||
if [ "$s" = "$RAIN_GPIO_STATE" ]; then
|
if [ "$s" = "$RAIN_GPIO_STATE" ]; then
|
||||||
local local_epoch=`date +%s`
|
local local_epoch=`date +%s`
|
||||||
echo $local_epoch > "$STATUS_DIR/last_rain_sensor"
|
echo $local_epoch > "$STATUS_DIR/last_rain_sensor"
|
||||||
@@ -650,494 +666,6 @@ function json_status {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
|
||||||
# Elimina una tipoliga di schedulazione dal crontab dell'utente
|
|
||||||
# $1 tipologia del crontab
|
|
||||||
# $2 argomento della tipologia
|
|
||||||
#
|
|
||||||
function cron_del {
|
|
||||||
|
|
||||||
local CRON_TYPE=$1
|
|
||||||
local CRON_ARG=$2
|
|
||||||
|
|
||||||
if [ -z "$CRON_TYPE" ]; then
|
|
||||||
echo "Cron type is empty" >&2
|
|
||||||
log_write "Cron type is empty"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
$CRONTAB -l > "$TMP_CRON_FILE"
|
|
||||||
local START=`$GREP -n "# START cron $CRON_TYPE $CRON_ARG" "$TMP_CRON_FILE"| $CUT -d : -f 1`
|
|
||||||
local END=`$GREP -n "# END cron $CRON_TYPE $CRON_ARG" "$TMP_CRON_FILE"| $CUT -d : -f 1`
|
|
||||||
local re='^[0-9]+$'
|
|
||||||
|
|
||||||
if ! [[ "$START" =~ $re ]] && ! [[ "$END" =~ $re ]] ; then
|
|
||||||
echo "$1 $2 cron is not present" >&2
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
if ! [[ $START =~ $re ]] ; then
|
|
||||||
echo "Cron start don't find" >&2
|
|
||||||
log_write "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"
|
|
||||||
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"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
$SED "$START,${END}d" "$TMP_CRON_FILE" | $SED '$!N; /^\(.*\)\n\1$/!P; D' | $CRONTAB -
|
|
||||||
#$CRONTAB "$TMP_CRON_FILE"
|
|
||||||
rm "$TMP_CRON_FILE"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Aggiunge una schedulazione nel crontab dell'utente
|
|
||||||
# $1 tipologia del crontab
|
|
||||||
# $2 minuto
|
|
||||||
# $3 ora
|
|
||||||
# $4 giorno del mese
|
|
||||||
# $5 mese
|
|
||||||
# $6 giorno della settimana
|
|
||||||
# $7 argomento della tipologia
|
|
||||||
# $8 secondo argomento della tipologia
|
|
||||||
#
|
|
||||||
function cron_add {
|
|
||||||
|
|
||||||
local CRON_TYPE=$1
|
|
||||||
local CRON_M=$2
|
|
||||||
local CRON_H=$3
|
|
||||||
local CRON_DOM=$4
|
|
||||||
local CRON_MON=$5
|
|
||||||
local CRON_DOW=$6
|
|
||||||
local CRON_ARG=$7
|
|
||||||
local CRON_ARG2=$8
|
|
||||||
local CRON_COMMAND=""
|
|
||||||
local CRON_DISABLED=""
|
|
||||||
local PATH_SCRIPT=`$READLINK -f "$DIR_SCRIPT/$NAME_SCRIPT"`
|
|
||||||
local TMP_CRON_FILE2="$TMP_CRON_FILE-2"
|
|
||||||
|
|
||||||
if [ -z "$CRON_TYPE" ]; then
|
|
||||||
echo "Cron type is empty" >&2
|
|
||||||
log_write "Cron type is empty"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
$CRONTAB -l > "$TMP_CRON_FILE"
|
|
||||||
local START=`$GREP -n "# START cron $CRON_TYPE $CRON_ARG" "$TMP_CRON_FILE"| $CUT -d : -f 1`
|
|
||||||
local END=`$GREP -n "# END cron $CRON_TYPE $CRON_ARG" "$TMP_CRON_FILE"| $CUT -d : -f 1`
|
|
||||||
local re='^[0-9]+$'
|
|
||||||
|
|
||||||
local NEW_CRON=0
|
|
||||||
local PREVIUS_CONTENT=""
|
|
||||||
|
|
||||||
if ! [[ $START =~ $re ]] && ! [[ $END =~ $re ]] ; then
|
|
||||||
NEW_CRON=1
|
|
||||||
else
|
|
||||||
if ! [[ $START =~ $re ]] ; then
|
|
||||||
echo "Cron start don't find" >&2
|
|
||||||
log_write "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"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
START=$(($START + 1))
|
|
||||||
END=$(($END - 1))
|
|
||||||
|
|
||||||
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"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
PREVIOUS_CONTENT=`$SED -n "$START,${END}p" "$TMP_CRON_FILE"`
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$CRON_TYPE" in
|
|
||||||
|
|
||||||
init)
|
|
||||||
CRON_M="@reboot"
|
|
||||||
CRON_H=""
|
|
||||||
CRON_DOM=""
|
|
||||||
CRON_MON=""
|
|
||||||
CRON_DOW=""
|
|
||||||
CRON_COMMAND="$PATH_SCRIPT init"
|
|
||||||
;;
|
|
||||||
|
|
||||||
start_socket_server)
|
|
||||||
CRON_M="@reboot"
|
|
||||||
CRON_H=""
|
|
||||||
CRON_DOM=""
|
|
||||||
CRON_MON=""
|
|
||||||
CRON_DOW=""
|
|
||||||
CRON_COMMAND="$PATH_SCRIPT start_socket_server force"
|
|
||||||
;;
|
|
||||||
|
|
||||||
check_rain_online)
|
|
||||||
CRON_M="*/3"
|
|
||||||
CRON_H="*"
|
|
||||||
CRON_DOM="*"
|
|
||||||
CRON_MON="*"
|
|
||||||
CRON_DOW="*"
|
|
||||||
CRON_COMMAND="$PATH_SCRIPT check_rain_online 2> /tmp/check_rain_online.err"
|
|
||||||
;;
|
|
||||||
|
|
||||||
check_rain_sensor)
|
|
||||||
CRON_M="*"
|
|
||||||
CRON_H="*"
|
|
||||||
CRON_DOM="*"
|
|
||||||
CRON_MON="*"
|
|
||||||
CRON_DOW="*"
|
|
||||||
CRON_COMMAND="$PATH_SCRIPT check_rain_sensor 2> /tmp/check_rain_sensor.err"
|
|
||||||
;;
|
|
||||||
|
|
||||||
close_all_for_rain)
|
|
||||||
CRON_M="*/5"
|
|
||||||
CRON_H="*"
|
|
||||||
CRON_DOM="*"
|
|
||||||
CRON_MON="*"
|
|
||||||
CRON_DOW="*"
|
|
||||||
CRON_COMMAND="$PATH_SCRIPT close_all_for_rain 2> /tmp/close_all_for_rain.err 1> /dev/null"
|
|
||||||
;;
|
|
||||||
|
|
||||||
open)
|
|
||||||
CRON_COMMAND="$PATH_SCRIPT open $CRON_ARG"
|
|
||||||
if [ "$CRON_ARG2" == "disabled" ]; then
|
|
||||||
CRON_DISABLED="#"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
open_in)
|
|
||||||
CRON_COMMAND="$PATH_SCRIPT open $CRON_ARG $CRON_ARG2"
|
|
||||||
;;
|
|
||||||
|
|
||||||
open_in_stop)
|
|
||||||
CRON_COMMAND="$PATH_SCRIPT close $CRON_ARG"
|
|
||||||
;;
|
|
||||||
|
|
||||||
close)
|
|
||||||
CRON_COMMAND="$PATH_SCRIPT close $CRON_ARG"
|
|
||||||
if [ "$CRON_ARG2" == "disabled" ]; then
|
|
||||||
CRON_DISABLED="#"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo "Wrong cron type: $CRON_TYPE"
|
|
||||||
log_write "Wrong cron type: $CRON_TYPE"
|
|
||||||
;;
|
|
||||||
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [ "$NEW_CRON" -eq "0" ]; then
|
|
||||||
START=$(($START - 1))
|
|
||||||
END=$(($END + 1))
|
|
||||||
$SED "$START,${END}d" "$TMP_CRON_FILE" > "$TMP_CRON_FILE2"
|
|
||||||
else
|
|
||||||
cat "$TMP_CRON_FILE" > "$TMP_CRON_FILE2"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$NEW_CRON" -eq "1" ]; then
|
|
||||||
echo "" >> "$TMP_CRON_FILE2"
|
|
||||||
fi
|
|
||||||
echo "# START cron $CRON_TYPE $CRON_ARG" >> "$TMP_CRON_FILE2"
|
|
||||||
if [ "$NEW_CRON" -eq "0" ]; then
|
|
||||||
echo "$PREVIOUS_CONTENT" >> "$TMP_CRON_FILE2"
|
|
||||||
fi
|
|
||||||
echo "$CRON_DISABLED$CRON_M $CRON_H $CRON_DOM $CRON_MON $CRON_DOW $CRON_COMMAND" >> "$TMP_CRON_FILE2"
|
|
||||||
echo "# END cron $CRON_TYPE $CRON_ARG" >> "$TMP_CRON_FILE2"
|
|
||||||
|
|
||||||
$CRONTAB "$TMP_CRON_FILE2"
|
|
||||||
rm "$TMP_CRON_FILE" "$TMP_CRON_FILE2"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Legge una tipoliga di schedulazione dal crontab dell'utente
|
|
||||||
# $1 tipologia del crontab
|
|
||||||
# $2 argomento della tipologia
|
|
||||||
#
|
|
||||||
function cron_get {
|
|
||||||
|
|
||||||
local CRON_TYPE=$1
|
|
||||||
local CRON_ARG=$2
|
|
||||||
|
|
||||||
if [ -z "$CRON_TYPE" ]; then
|
|
||||||
echo "Cron type is empty" >&2
|
|
||||||
log_write "Cron type is empty"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
$CRONTAB -l > "$TMP_CRON_FILE"
|
|
||||||
local START=`$GREP -n "# START cron $CRON_TYPE $CRON_ARG" "$TMP_CRON_FILE"| $CUT -d : -f 1`
|
|
||||||
local END=`$GREP -n "# END cron $CRON_TYPE $CRON_ARG" "$TMP_CRON_FILE"| $CUT -d : -f 1`
|
|
||||||
local re='^[0-9]+$'
|
|
||||||
|
|
||||||
local PREVIUS_CONTENT=""
|
|
||||||
|
|
||||||
if ! [[ $START =~ $re ]] && ! [[ $END =~ $re ]] ; then
|
|
||||||
PREVIUS_CONTENT=""
|
|
||||||
else
|
|
||||||
if ! [[ $START =~ $re ]] ; then
|
|
||||||
echo "Cron start don't find" >&2
|
|
||||||
log_write "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"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
START=$(($START + 1))
|
|
||||||
END=$(($END - 1))
|
|
||||||
|
|
||||||
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"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
PREVIOUS_CONTENT=`$SED -n "$START,${END}p" "$TMP_CRON_FILE"`
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$PREVIOUS_CONTENT"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Imposta il cron di inizializzazione della centralina
|
|
||||||
#
|
|
||||||
function set_cron_init {
|
|
||||||
|
|
||||||
cron_del "init" 2> /dev/null
|
|
||||||
cron_add "init"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Elimina il cron di inizializzazione della centralina
|
|
||||||
#
|
|
||||||
function del_cron_init {
|
|
||||||
|
|
||||||
cron_del "init"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Imposta il cron per l'avvio del socket server
|
|
||||||
#
|
|
||||||
function set_cron_start_socket_server {
|
|
||||||
|
|
||||||
cron_del "start_socket_server" 2> /dev/null
|
|
||||||
cron_add "start_socket_server"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Elimina il cron per l'avvio del socket server
|
|
||||||
#
|
|
||||||
function del_cron_start_socket_server {
|
|
||||||
|
|
||||||
cron_del "start_socket_server"
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Imposta il cron che esegue il controllo di presenza pioggia tramite sensore
|
|
||||||
#
|
|
||||||
function set_cron_check_rain_sensor {
|
|
||||||
|
|
||||||
cron_del "check_rain_sensor" 2> /dev/null
|
|
||||||
cron_add "check_rain_sensor"
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Elimina il cron che esegue il controllo di presenza pioggia tramite sensore
|
|
||||||
#
|
|
||||||
function del_cron_check_rain_sensor {
|
|
||||||
|
|
||||||
cron_del "check_rain_sensor"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Imposta il cron che esegue il controllo di presenza pioggia tramite servizio online
|
|
||||||
#
|
|
||||||
function set_cron_check_rain_online {
|
|
||||||
|
|
||||||
cron_del "check_rain_online" 2> /dev/null
|
|
||||||
cron_add "check_rain_online"
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Elimina il cron che esegue il controllo di presenza pioggia tramite servizio online
|
|
||||||
#
|
|
||||||
function del_cron_check_rain_online {
|
|
||||||
|
|
||||||
cron_del "check_rain_online"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Imposta il cron che gestisce la chiusura delle elettrovalvole in caso di pioggia
|
|
||||||
#
|
|
||||||
function set_cron_close_all_for_rain {
|
|
||||||
|
|
||||||
cron_del "close_all_for_rain" 2> /dev/null
|
|
||||||
cron_add "close_all_for_rain"
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Elimina il cron che gestisce la chiusura delle elettrovalvole in caso di pioggia
|
|
||||||
#
|
|
||||||
function del_cron_close_all_for_rain {
|
|
||||||
|
|
||||||
cron_del "close_all_for_rain"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Aggiunge una schedulazione cron per aprire una elettrovalvola
|
|
||||||
# $1 alias elettrovalvola
|
|
||||||
# $2 minuto cron
|
|
||||||
# $3 ora cron
|
|
||||||
# $4 giorno del mese cron
|
|
||||||
# $5 mese cron
|
|
||||||
# $6 giorno della settimana cron
|
|
||||||
# $7 disabled
|
|
||||||
#
|
|
||||||
function add_cron_open {
|
|
||||||
|
|
||||||
local exists=`alias_exists $1`
|
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
|
||||||
log_write "Alias $1 not found"
|
|
||||||
echo "Alias $1 not found"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cron_add "open" "$2" "$3" "$4" "$5" "$6" "$1" "$7"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Cancella tutte le schedulazioni cron per aprire una elettrovalvola
|
|
||||||
# $1 alias elettrovalvola
|
|
||||||
#
|
|
||||||
function del_cron_open {
|
|
||||||
|
|
||||||
local exists=`alias_exists $1`
|
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
|
||||||
log_write "Alias $1 not found"
|
|
||||||
echo "Alias $1 not found"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cron_del "open" $1
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Legge tutte le schedulazioni cron per aprire una elettrovalvola
|
|
||||||
# $1 alias elettrovalvola
|
|
||||||
#
|
|
||||||
function get_cron_open {
|
|
||||||
|
|
||||||
local exists=`alias_exists $1`
|
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
|
||||||
log_write "Alias $1 not found"
|
|
||||||
echo "Alias $1 not found"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cron_get "open" $1
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Cancella tutte le schedulazioni cron per aprire/chiudere una elettrovalvola in modo ritardato
|
|
||||||
# $1 alias elettrovalvola
|
|
||||||
#
|
|
||||||
function del_cron_open_in {
|
|
||||||
|
|
||||||
local exists=`alias_exists $1`
|
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
|
||||||
log_write "Alias $1 not found"
|
|
||||||
echo "Alias $1 not found"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cron_del "open_in" $1
|
|
||||||
cron_del "open_in_stop" $1
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Legge tutte le schedulazioni cron per chiudere una elettrovalvola
|
|
||||||
# $1 alias elettrovalvola
|
|
||||||
#
|
|
||||||
function get_cron_close {
|
|
||||||
|
|
||||||
local exists=`alias_exists $1`
|
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
|
||||||
log_write "Alias $1 not found"
|
|
||||||
echo "Alias $1 not found"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cron_get "close" $1
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Aggiunge una schedulazione cron per chiudere una elettrovalvola
|
|
||||||
# $1 alias elettrovalvola
|
|
||||||
# $2 minuto cron
|
|
||||||
# $3 ora cron
|
|
||||||
# $4 giorno del mese cron
|
|
||||||
# $5 mese cron
|
|
||||||
# $6 giorno della settimana cron
|
|
||||||
# $7 disabled
|
|
||||||
#
|
|
||||||
function add_cron_close {
|
|
||||||
|
|
||||||
local exists=`alias_exists $1`
|
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
|
||||||
log_write "Alias $1 not found"
|
|
||||||
echo "Alias $1 not found"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cron_add "close" "$2" "$3" "$4" "$5" "$6" "$1" "$7"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Cancella tutte le schedulazioni cron per chiudere una elettrovalvola
|
|
||||||
# $1 alias elettrovalvola
|
|
||||||
#
|
|
||||||
function del_cron_close {
|
|
||||||
|
|
||||||
local exists=`alias_exists $1`
|
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
|
||||||
log_write "Alias $1 not found"
|
|
||||||
echo "Alias $1 not found"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cron_del "close" $1
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Mostra il i parametri dello script
|
# Mostra il i parametri dello script
|
||||||
#
|
#
|
||||||
@@ -1183,214 +711,6 @@ function show_usage {
|
|||||||
echo -e "\t$NAME_SCRIPT debug2 [parameter]|[parameter]|..] Run debug code 2"
|
echo -e "\t$NAME_SCRIPT debug2 [parameter]|[parameter]|..] Run debug code 2"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
|
||||||
# Avvia il socket server
|
|
||||||
#
|
|
||||||
function start_socket_server {
|
|
||||||
|
|
||||||
rm -f "$TCPSERVER_PID_FILE"
|
|
||||||
echo $TCPSERVER_PID_SCRIPT > "$TCPSERVER_PID_FILE"
|
|
||||||
$TCPSERVER -v -RHl0 $TCPSERVER_IP $TCPSERVER_PORT $0 socket_server_command
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Ferma il socket server
|
|
||||||
#
|
|
||||||
function stop_socket_server {
|
|
||||||
|
|
||||||
if [ ! -f "$TCPSERVER_PID_FILE" ]; then
|
|
||||||
echo "Daemon is not running"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
log_write "stop socket server"
|
|
||||||
|
|
||||||
kill -9 $(list_descendants `cat "$TCPSERVER_PID_FILE"`) 2> /dev/null
|
|
||||||
kill -9 `cat "$TCPSERVER_PID_FILE"` 2> /dev/null
|
|
||||||
rm -f "$TCPSERVER_PID_FILE"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Esegue un comando ricevuto dal socket server
|
|
||||||
#
|
|
||||||
function socket_server_command {
|
|
||||||
|
|
||||||
RUN_FROM_TCPSERVER=1
|
|
||||||
|
|
||||||
local line=""
|
|
||||||
|
|
||||||
if [ ! -z "$TCPSERVER_USER" ] && [ ! -z "$TCPSERVER_PWD" ]; then
|
|
||||||
local user=""
|
|
||||||
local password=""
|
|
||||||
read -t 3 user
|
|
||||||
read -t 3 password
|
|
||||||
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"
|
|
||||||
json_error 0 "Bad socket server credentials"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
read line
|
|
||||||
line=$(echo "$line " | $TR -d '[\r\n]')
|
|
||||||
arg1=$(echo "$line " | $CUT -d ' ' -f1)
|
|
||||||
arg2=$(echo "$line " | $CUT -d ' ' -f2)
|
|
||||||
arg3=$(echo "$line " | $CUT -d ' ' -f3)
|
|
||||||
arg4=$(echo "$line " | $CUT -d ' ' -f4)
|
|
||||||
arg5=$(echo "$line " | $CUT -d ' ' -f5)
|
|
||||||
arg6=$(echo "$line " | $CUT -d ' ' -f6)
|
|
||||||
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"
|
|
||||||
|
|
||||||
reset_messages &> /dev/null
|
|
||||||
|
|
||||||
case "$arg1" in
|
|
||||||
status)
|
|
||||||
json_status $arg2 $arg3 $arg4 $arg5 $arg6 $arg7
|
|
||||||
;;
|
|
||||||
|
|
||||||
open)
|
|
||||||
if [ "empty$arg2" == "empty" ]; then
|
|
||||||
json_error 0 "Alias solenoid not specified"
|
|
||||||
else
|
|
||||||
ev_open $arg2 $arg3 &> /dev/null
|
|
||||||
json_status "get_cron_open_in"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
open_in)
|
|
||||||
ev_open_in $arg2 $arg3 $arg4 $arg5 &> /dev/null
|
|
||||||
json_status "get_cron_open_in"
|
|
||||||
;;
|
|
||||||
|
|
||||||
close)
|
|
||||||
if [ "empty$arg2" == "empty" ]; then
|
|
||||||
json_error 0 "Alias solenoid not specified"
|
|
||||||
else
|
|
||||||
ev_close $arg2 &> /dev/null
|
|
||||||
json_status "get_cron_open_in"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
set_general_cron)
|
|
||||||
local vret=""
|
|
||||||
for i in $arg2 $arg3 $arg4 $arg5 $arg6 $arg7
|
|
||||||
do
|
|
||||||
if [ $i = "set_cron_init" ]; then
|
|
||||||
vret="$(vret)`set_cron_init`"
|
|
||||||
elif [ $i = "set_cron_start_socket_server" ]; then
|
|
||||||
vret="$(vret)`set_cron_start_socket_server`"
|
|
||||||
elif [ $i = "set_cron_check_rain_sensor" ]; then
|
|
||||||
vret="$(vret)`set_cron_check_rain_sensor`"
|
|
||||||
elif [ $i = "set_cron_check_rain_online" ]; then
|
|
||||||
vret="$(vret)`set_cron_check_rain_online`"
|
|
||||||
elif [ $i = "set_cron_close_all_for_rain" ]; then
|
|
||||||
vret="$(vret)`set_cron_close_all_for_rain`"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ ! -z $vret ]]; then
|
|
||||||
json_error 0 "Cron set failed"
|
|
||||||
log_write "Cron set failed: $vret"
|
|
||||||
else
|
|
||||||
message_write "success" "Cron set successfull"
|
|
||||||
json_status
|
|
||||||
fi
|
|
||||||
|
|
||||||
;;
|
|
||||||
|
|
||||||
del_cron_open)
|
|
||||||
local vret=""
|
|
||||||
|
|
||||||
vret=`del_cron_open $arg2`
|
|
||||||
|
|
||||||
if [[ ! -z $vret ]]; then
|
|
||||||
json_error 0 "Cron set failed"
|
|
||||||
log_write "Cron del failed: $vret"
|
|
||||||
else
|
|
||||||
message_write "success" "Cron set successfull"
|
|
||||||
json_status
|
|
||||||
fi
|
|
||||||
|
|
||||||
;;
|
|
||||||
|
|
||||||
del_cron_open_in)
|
|
||||||
local vret=""
|
|
||||||
|
|
||||||
vret=`del_cron_open_in $arg2`
|
|
||||||
|
|
||||||
if [[ ! -z $vret ]]; then
|
|
||||||
json_error 0 "Cron del failed"
|
|
||||||
log_write "Cron del failed: $vret"
|
|
||||||
else
|
|
||||||
message_write "success" "Scheduled start successfully deleted"
|
|
||||||
json_status "get_cron_open_in"
|
|
||||||
fi
|
|
||||||
|
|
||||||
;;
|
|
||||||
|
|
||||||
|
|
||||||
del_cron_close)
|
|
||||||
local vret=""
|
|
||||||
|
|
||||||
vret=`del_cron_close $arg2`
|
|
||||||
|
|
||||||
if [[ ! -z $vret ]]; then
|
|
||||||
json_error 0 "Cron set failed"
|
|
||||||
log_write "Cron set failed: $vret"
|
|
||||||
else
|
|
||||||
message_write "success" "Cron set successfull"
|
|
||||||
json_status
|
|
||||||
fi
|
|
||||||
|
|
||||||
;;
|
|
||||||
|
|
||||||
add_cron_open)
|
|
||||||
local vret=""
|
|
||||||
|
|
||||||
vret=`add_cron_open "$arg2" "$arg3" "$arg4" "$arg5" "$arg6" "$arg7" $arg8`
|
|
||||||
|
|
||||||
if [[ ! -z $vret ]]; then
|
|
||||||
json_error 0 "Cron set failed"
|
|
||||||
log_write "Cron set failed: $vret"
|
|
||||||
else
|
|
||||||
message_write "success" "Cron set successfull"
|
|
||||||
json_status
|
|
||||||
fi
|
|
||||||
|
|
||||||
;;
|
|
||||||
|
|
||||||
add_cron_close)
|
|
||||||
local vret=""
|
|
||||||
|
|
||||||
vret=`add_cron_close "$arg2" "$arg3" "$arg4" "$arg5" "$arg6" "$arg7" $arg8`
|
|
||||||
|
|
||||||
if [[ ! -z $vret ]]; then
|
|
||||||
json_error 0 "Cron set failed"
|
|
||||||
log_write "Cron set failed: $vret"
|
|
||||||
else
|
|
||||||
message_write "success" "Cron set successfull"
|
|
||||||
json_status
|
|
||||||
fi
|
|
||||||
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
json_error 0 "invalid command"
|
|
||||||
;;
|
|
||||||
|
|
||||||
esac
|
|
||||||
|
|
||||||
reset_messages &> /dev/null
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Mostra un json per una risposta di errore
|
# Mostra un json per una risposta di errore
|
||||||
# $1 codice errore
|
# $1 codice errore
|
||||||
@@ -1519,7 +839,8 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
. "$DIR_SCRIPT/include/drv.include.sh"
|
. "$DIR_SCRIPT/include/drv.include.sh"
|
||||||
|
. "$DIR_SCRIPT/include/cron.include.sh"
|
||||||
|
. "$DIR_SCRIPT/include/socket.include.sh"
|
||||||
|
|
||||||
LAST_INFO_FILE="$STATUS_DIR/last_info"
|
LAST_INFO_FILE="$STATUS_DIR/last_info"
|
||||||
LAST_WARNING_FILE="$STATUS_DIR/last_worning"
|
LAST_WARNING_FILE="$STATUS_DIR/last_worning"
|
||||||
|
|||||||
Reference in New Issue
Block a user