Compare commits
70 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50fc8a72b2 | ||
|
|
9183bbcef5 | ||
|
|
bdab0fb6fe | ||
|
|
6ed0510c7f | ||
|
|
15e36e95a3 | ||
|
|
3a5c3ef934 | ||
|
|
f3c11a7fee | ||
|
|
ac95194b3e | ||
|
|
a125ff31d8 | ||
|
|
bb435f0ee6 | ||
|
|
b8daa7acab | ||
|
|
dd289f8b31 | ||
|
|
2add0c725f | ||
|
|
0b34b7010f | ||
|
|
c527702c72 | ||
|
|
b6de96debe | ||
|
|
ea681816fe | ||
|
|
8ca698d4ee | ||
|
|
70943c5f5e | ||
|
|
aa9799cdaf | ||
|
|
6d4f522f21 | ||
|
|
51e4391237 | ||
|
|
e2eda96f2c | ||
|
|
aa12f5a8a5 | ||
|
|
40ab2e3b25 | ||
|
|
40eb0b2429 | ||
|
|
9d9ef42679 | ||
|
|
70c4e063f8 | ||
|
|
4d4b35c3cc | ||
|
|
71e91cc861 | ||
|
|
e26292fe36 | ||
|
|
d99566ef93 | ||
|
|
a76c797b22 | ||
|
|
07a594e799 | ||
|
|
dfa68c2b83 | ||
|
|
e284bbcb25 | ||
|
|
d324faf8bb | ||
|
|
383cbc44a9 | ||
|
|
9864709b44 | ||
|
|
6d8c82f0a3 | ||
|
|
a997081aa9 | ||
|
|
c145171306 | ||
|
|
e9a676188f | ||
|
|
0d748031fd | ||
|
|
3ed46d80ad | ||
|
|
05a73720bb | ||
|
|
2ea6588c32 | ||
|
|
fc717f18a2 | ||
|
|
50117a5a96 | ||
|
|
309c209b1b | ||
|
|
9a81f0fbba | ||
|
|
419695b420 | ||
|
|
3239006922 | ||
|
|
24baa97dad | ||
|
|
c354f72c0c | ||
|
|
6f80b8ea21 | ||
|
|
87edbbbe7a | ||
|
|
3eb45fd1e9 | ||
|
|
7c96a6afd1 | ||
|
|
c664bea16a | ||
|
|
78fa176848 | ||
|
|
5c00853e39 | ||
|
|
dd3cab12c2 | ||
|
|
38ecd92d7a | ||
|
|
22ec16cc9d | ||
|
|
8d4849db75 | ||
|
|
35665c74a7 | ||
|
|
80bcbbc92a | ||
|
|
67f2d6fe7f | ||
|
|
83e23d6bad |
58
CHANGELOG.md
58
CHANGELOG.md
@@ -1,3 +1,61 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# 0.5.14 - 24/09/2019
|
||||||
|
- Updated rainsensorqty driver to version 0.2.3
|
||||||
|
- Added api and command for manage piGardenSched scheduling
|
||||||
|
|
||||||
|
# 0.5.13 - 12/08/2019
|
||||||
|
- Added driver rainsensorqty for menage rainfall detection based on quantity
|
||||||
|
|
||||||
|
# 0.5.12.1 - 23/06/2019
|
||||||
|
- Added zip log drver file when exceeding the size limit
|
||||||
|
|
||||||
|
# 0.5.12 - 13/11/2018
|
||||||
|
- Fixed a bug that prevented the publication of the mqtt topic for each event
|
||||||
|
- Fixed a bug on openweathermap driver which in some cases causes a malformation of the json status and prevented communication with piGardenWeb
|
||||||
|
|
||||||
|
# 0.5.11 - 11/11/2018
|
||||||
|
- Added ability to disable online weather service by defining WEATHER_SERVICE="none" in the configuration file
|
||||||
|
|
||||||
|
# 0.5.10 - 11/11/2018
|
||||||
|
- Fix bug in single monostable solenodid management caused from wrong variable name EV_IS_MONOSTAVLE
|
||||||
|
|
||||||
|
# 0.5.9 - 01/11/2018
|
||||||
|
- Added mqtt support for publishing status to broker
|
||||||
|
|
||||||
|
# 0.5.8 - 19/07/2018
|
||||||
|
- Added "openweathermap" driver for impement check weather condition from openweatermap api
|
||||||
|
|
||||||
|
# 0.5.7 - 01/06/2018
|
||||||
|
- Added "sonoff_tasmota_http" driver for interfacin with Sonoff module with Tasmota firmware over http protocol
|
||||||
|
|
||||||
|
# 0.5.6 - 04/05/2018
|
||||||
|
- Added events ev_not_open_for_rain, ev_not_open_for_rain_sensor, ev_not_open_for_rain_online
|
||||||
|
- Added script rpinotify.sh for notificate events to telegram
|
||||||
|
|
||||||
|
# 0.5.5 - 25/03/2018
|
||||||
|
- Added "remote" driver to control remote pigarden
|
||||||
|
|
||||||
|
# 0.5.4 - 13/11/2017
|
||||||
|
- Fix bad initialization LOG_OUTPUT_DRV_FILE variable if not defined in config file
|
||||||
|
|
||||||
|
# 0.5.3 - 19/11/2017
|
||||||
|
- Fix send parameter on event init_before and init_after
|
||||||
|
- Added WEATHER argument in check_rain_sensor_after and check_rain_sensor_change event
|
||||||
|
- Added events cron_add_before, cron_add_after, cron_del_before, cron_del_after, ev_open_in_before, ev_open_in_after, exec_poweroff_before, exec_poweroff_after, exec_reboot_before, exec_reboot_after
|
||||||
|
- Added to sendmail.sh argument passed form check_rain_sensor_after and check_rain_sensor_change event
|
||||||
|
- Added to sendmail.sh new events
|
||||||
|
- Fix wrong state on event script sendmail.sh
|
||||||
|
|
||||||
|
# 0.5.2 - 01/11/2017
|
||||||
|
- Fix problem inconsistent return value in drv_rain_sensor_get
|
||||||
|
- Fix get parameter in event script sendmail.sh
|
||||||
|
|
||||||
# 0.5.1 - 28/10/2017
|
# 0.5.1 - 28/10/2017
|
||||||
- Added events managemets
|
- Added events managemets
|
||||||
- Added support for zones not subject to rainfall (with parameter EVx_NORAIN)
|
- Added support for zones not subject to rainfall (with parameter EVx_NORAIN)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Bash script to manage an irrigation system built with a Raspberry Pi
|
|||||||
|
|
||||||
## Official documentation
|
## Official documentation
|
||||||
|
|
||||||
Documentation of piGarden and build system irrigation with Raspberry Pi can be found on the [www.lejubila.net/tag/pigarden/](http://www.lejubila.net/tag/pigarden/)
|
Documentation of piGarden and build system irrigation with Raspberry Pi can be found on the [www.lejubila.net/pigarden/](http://www.lejubila.net/pigarden/)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
@@ -41,8 +41,8 @@ sudo make install
|
|||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
cd
|
cd
|
||||||
git clone git://git.drogon.net/wiringPi
|
git clone https://github.com/WiringPi/WiringPi.git
|
||||||
cd wiringPi
|
cd WiringPi
|
||||||
git pull origin
|
git pull origin
|
||||||
./build
|
./build
|
||||||
```
|
```
|
||||||
@@ -66,5 +66,3 @@ sudo cp piGarden/conf/piGarden.conf.example /etc/piGarden.conf
|
|||||||
Customize the configuration file.
|
Customize the configuration file.
|
||||||
For more information see
|
For more information see
|
||||||
[www.lejubila.net/2015/12/impianto-di-irrigazione-con-raspberry-pi-pigarden-lo-script-di-gestione-quinta-parte/](https://www.lejubila.net/2015/12/impianto-di-irrigazione-con-raspberry-pi-pigarden-lo-script-di-gestione-quinta-parte/)
|
[www.lejubila.net/2015/12/impianto-di-irrigazione-con-raspberry-pi-pigarden-lo-script-di-gestione-quinta-parte/](https://www.lejubila.net/2015/12/impianto-di-irrigazione-con-raspberry-pi-pigarden-lo-script-di-gestione-quinta-parte/)
|
||||||
and
|
|
||||||
[www.lejubila.net/2017/04/pigarden-0-2-easter-egg/](https://www.lejubila.net/2017/04/pigarden-0-2-easter-egg/)
|
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
LOG_FILE="/home/pi/piGarden/log/piGarden.log"
|
LOG_FILE="/home/pi/piGarden/log/piGarden.log"
|
||||||
LOG_FILE_MAX_SIZE=1048576 # 1MB
|
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 file for driver output
|
||||||
LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log"
|
LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log"
|
||||||
|
|
||||||
@@ -53,8 +61,16 @@ READLINK="/bin/readlink"
|
|||||||
# Percorso stat
|
# Percorso stat
|
||||||
STAT="/usr/bin/stat"
|
STAT="/usr/bin/stat"
|
||||||
|
|
||||||
|
# Percorso mosquito_pub
|
||||||
|
# # Installare con apt install mosquitto-clients
|
||||||
|
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
|
||||||
|
|
||||||
|
# Percorso di piGardenSched, se non definito non verranno gestire le schedulazioni di piGardenSched tramite api
|
||||||
|
#PIGARDENSCHED_PATH="/home/pi/piGardenSched/piGardenSched.sh"
|
||||||
|
|
||||||
|
|
||||||
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
||||||
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
# se impostato a 0 il sistema gestirà elettrovalvole bistabili
|
||||||
EV_MONOSTABLE=0
|
EV_MONOSTABLE=0
|
||||||
|
|
||||||
# Id gpio usati per simulare il doppio deviatore con cui eseguire l'alimentazione alle elettrovalvole
|
# Id gpio usati per simulare il doppio deviatore con cui eseguire l'alimentazione alle elettrovalvole
|
||||||
@@ -90,6 +106,7 @@ EV_TOTAL=6
|
|||||||
EV1_ALIAS="1" #
|
EV1_ALIAS="1" #
|
||||||
EV1_GPIO=17 # Physical 11 - wPi 0
|
EV1_GPIO=17 # Physical 11 - wPi 0
|
||||||
#EV1_NORAIN=1 # Non interrompe l'irrigazione di questa zona in caso di pioggia
|
#EV1_NORAIN=1 # Non interrompe l'irrigazione di questa zona in caso di pioggia
|
||||||
|
#EV1_MONOSTABLE=1 # L'elettrovalvola è monostabile
|
||||||
|
|
||||||
EV2_ALIAS="2" #
|
EV2_ALIAS="2" #
|
||||||
EV2_GPIO=27 # Physical 13 - wPi 2
|
EV2_GPIO=27 # Physical 13 - wPi 2
|
||||||
@@ -106,9 +123,21 @@ EV5_GPIO=23 # Physical 16 - wPi 4
|
|||||||
EV6_ALIAS="6" #
|
EV6_ALIAS="6" #
|
||||||
EV6_GPIO=24 # Physical 18 - wPi 5
|
EV6_GPIO=24 # Physical 18 - wPi 5
|
||||||
|
|
||||||
# Definisce l'api key e il luogo per recuperare lo stato meteo online
|
|
||||||
|
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground.
|
||||||
|
# Se non vuoi configurare nessun servizio imposta il vale "none"
|
||||||
|
WEATHER_SERVICE="openweathermap"
|
||||||
|
#WEATHER_SERVICE="none" # Nessun servizio configurato
|
||||||
|
|
||||||
|
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||||
|
OPENWEATHERMAP_KEY=""
|
||||||
|
OPENWEATHERMAP_LOCATION="q=Pieve%20a%20Nievole,it" # https://openweathermap.org/current
|
||||||
|
OPENWEATHERMAP_TZ="Europe/Rome" # Time zone
|
||||||
|
|
||||||
|
# Parametri di wunderground, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||||
WUNDERGROUND_KEY=""
|
WUNDERGROUND_KEY=""
|
||||||
WUNDERGROUND_LOCATION="IY/Monsummano" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
WUNDERGROUND_LOCATION="IT/Pieve%20a%20Nievole" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||||
|
|
||||||
|
|
||||||
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
||||||
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||||
@@ -128,3 +157,12 @@ TCPSERVER_PWD=""
|
|||||||
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
||||||
NO_SEND_IDENTIFIER=0
|
NO_SEND_IDENTIFIER=0
|
||||||
|
|
||||||
|
# Parametri connessione al broker mqtt
|
||||||
|
MQTT_ENABLE=0 # set 1 to enable
|
||||||
|
MQTT_HOST=you_host_mqtt
|
||||||
|
MQTT_PORT=1883
|
||||||
|
MQTT_USER=your_user_mqtt
|
||||||
|
MQTT_PWD=yout_password_mqtt
|
||||||
|
MQTT_TOPIC="pigarden/result"
|
||||||
|
MQTT_CLIENT_ID=piGarden
|
||||||
|
|
||||||
|
|||||||
174
conf/piGarden.conf.rainsensorqty.example
Normal file
174
conf/piGarden.conf.rainsensorqty.example
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
# Log file
|
||||||
|
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"
|
||||||
|
|
||||||
|
# Status directory
|
||||||
|
STATUS_DIR="/home/pi/piGarden/state"
|
||||||
|
|
||||||
|
# Event directory
|
||||||
|
EVENT_DIR="/home/pi/piGarden/events"
|
||||||
|
|
||||||
|
# Posizione gpio
|
||||||
|
GPIO="/usr/local/bin/gpio"
|
||||||
|
|
||||||
|
# Posizione js
|
||||||
|
JQ="/usr/local/bin/jq"
|
||||||
|
|
||||||
|
# Percorso curl
|
||||||
|
CURL="/usr/bin/curl"
|
||||||
|
|
||||||
|
# Percorso wc
|
||||||
|
WC="/usr/bin/wc"
|
||||||
|
|
||||||
|
# Percorso gzip
|
||||||
|
GZIP="/bin/gzip"
|
||||||
|
|
||||||
|
# Percorso mv
|
||||||
|
MV="/bin/mv"
|
||||||
|
|
||||||
|
# Percorso di tr
|
||||||
|
TR="/usr/bin/tr"
|
||||||
|
|
||||||
|
# Percorso di cut
|
||||||
|
CUT="/usr/bin/cut"
|
||||||
|
|
||||||
|
# Percorso tcpserver
|
||||||
|
TCPSERVER="/usr/bin/tcpserver"
|
||||||
|
|
||||||
|
# Percorso cron
|
||||||
|
CRONTAB="/usr/bin/crontab"
|
||||||
|
|
||||||
|
# Percorso grep
|
||||||
|
GREP="/bin/grep"
|
||||||
|
|
||||||
|
# Percorsp sed
|
||||||
|
SED="/bin/sed"
|
||||||
|
|
||||||
|
# Percorso readlink
|
||||||
|
READLINK="/bin/readlink"
|
||||||
|
|
||||||
|
# Percorso stat
|
||||||
|
STAT="/usr/bin/stat"
|
||||||
|
|
||||||
|
# Percorso mosquito_pub
|
||||||
|
# # Installare con apt install mosquitto-clients
|
||||||
|
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
|
||||||
|
|
||||||
|
# Percorso di piGardenSched, se non definito non verranno gestire le schedulazioni di piGardenSched tramite api
|
||||||
|
#PIGARDENSCHED_PATH="/home/pi/piGardenSched/piGardenSched.sh"
|
||||||
|
|
||||||
|
|
||||||
|
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
||||||
|
# se impostato a 0 il sistema gestirà elettrovalvole bistabili
|
||||||
|
EV_MONOSTABLE=0
|
||||||
|
|
||||||
|
# Id gpio usati per simulare il doppio deviatore con cui eseguire l'alimentazione alle elettrovalvole
|
||||||
|
SUPPLY_GPIO_1=2 # Physical 3 - wPi 8
|
||||||
|
SUPPLY_GPIO_2=3 # Physical 5 - wPi 9
|
||||||
|
|
||||||
|
# Stato dei due gpio per impartire l'alimentazione positiva alle elettrovalvole (aperta)
|
||||||
|
SUPPLY_GPIO_POS=0
|
||||||
|
|
||||||
|
# Stato dei due gpio per impartire l'alimentazione negativa alle elettrovalvole (chiusa)
|
||||||
|
SUPPLY_GPIO_NEG=1
|
||||||
|
|
||||||
|
# Stato di ingresso da assegnare al gpio per chiudere il rele
|
||||||
|
RELE_GPIO_CLOSE=0
|
||||||
|
|
||||||
|
# Stato di ingresso da assegnare al gpio per aprire il rele
|
||||||
|
RELE_GPIO_OPEN=1
|
||||||
|
|
||||||
|
# Id del gpio usato per collegare il sensore di rilevamento pioggia
|
||||||
|
# attraverso il driver rainsensorqty
|
||||||
|
RAIN_GPIO="drv:rainsensorqty:25" # Physical 22 - wPi 6
|
||||||
|
|
||||||
|
# Valore in ingresso sul gpio definito in RAIN_GPIO che indica lo stato di pioggia
|
||||||
|
# variabile usata anche da drv:rainsensorqty, se e' a 1, significa che il reed contact e' collegato ad un circuito pull-down, vuol dire che attende l'impulso a 1 per contare le vaschette, normalmente e' a 0.
|
||||||
|
# se e' a 0, significa che il reed contact e' collegato ad un circuito pull-up, vuol dire che attende l'impulso a 0 per contare le vaschette, normalmente e' a 0.
|
||||||
|
RAIN_GPIO_STATE=0
|
||||||
|
|
||||||
|
RAINSENSORQTY_LOOPSFORSETRAINING=16 # dopo 16 impulsi, 16 vaschette riempite si considera pioggia
|
||||||
|
RAINSENSORQTY_SECSBETWEENRAINEVENT=10800 # =3h, significa che dopo 3 ore si resetta il numero di vaschette riempire e solo dopo un nuovo ciclo di riempimento si considera una nuova pioggia
|
||||||
|
|
||||||
|
RAINSENSORQTY_MMEACH=0.33 # see RAINSENSORQTY driver readme for details
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Numero totale di elettrovalvole
|
||||||
|
EV_TOTAL=6
|
||||||
|
|
||||||
|
# Definizione delle elettrovalvole
|
||||||
|
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
|
||||||
|
|
||||||
|
EV2_ALIAS="2" #
|
||||||
|
EV2_GPIO=27 # Physical 13 - wPi 2
|
||||||
|
|
||||||
|
EV3_ALIAS="3" #
|
||||||
|
EV3_GPIO=22 # Physical 15 - wPi 3
|
||||||
|
|
||||||
|
EV4_ALIAS="4" #
|
||||||
|
EV4_GPIO=18 # Physical 12 - wPi 1
|
||||||
|
|
||||||
|
EV5_ALIAS="5" #
|
||||||
|
EV5_GPIO=23 # Physical 16 - wPi 4
|
||||||
|
|
||||||
|
EV6_ALIAS="6" #
|
||||||
|
EV6_GPIO=24 # Physical 18 - wPi 5
|
||||||
|
|
||||||
|
|
||||||
|
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground.
|
||||||
|
# Se non vuoi configurare nessun servizio imposta il vale "none"
|
||||||
|
WEATHER_SERVICE="openweathermap"
|
||||||
|
#WEATHER_SERVICE="none" # Nessun servizio configurato
|
||||||
|
|
||||||
|
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||||
|
OPENWEATHERMAP_KEY=""
|
||||||
|
OPENWEATHERMAP_LOCATION="q=Pieve%20a%20Nievole,it" # https://openweathermap.org/current
|
||||||
|
OPENWEATHERMAP_TZ="Europe/Rome" # Time zone
|
||||||
|
|
||||||
|
# Parametri di wunderground, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||||
|
WUNDERGROUND_KEY=""
|
||||||
|
WUNDERGROUND_LOCATION="IT/Pieve%20a%20Nievole" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||||
|
|
||||||
|
|
||||||
|
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
||||||
|
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||||
|
NOT_IRRIGATE_IF_RAIN_ONLINE=86400
|
||||||
|
|
||||||
|
# Il parametro è simile a quello precedente, il controllo però anziché essere fatto attingendo a wunderground, viene eseguito direttamente sul sensore se installato. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||||
|
NOT_IRRIGATE_IF_RAIN_SENSOR=86400
|
||||||
|
|
||||||
|
# Indirizzo ip e porta di ascolto del socket server
|
||||||
|
TCPSERVER_IP="127.0.0.1"
|
||||||
|
TCPSERVER_PORT="8084"
|
||||||
|
|
||||||
|
# Utente e password che i clients devono utilizzare per stabilire una connessione tramite socket server
|
||||||
|
TCPSERVER_USER=""
|
||||||
|
TCPSERVER_PWD=""
|
||||||
|
|
||||||
|
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
||||||
|
NO_SEND_IDENTIFIER=0
|
||||||
|
|
||||||
|
# Parametri connessione al broker mqtt
|
||||||
|
MQTT_ENABLE=0 # set 1 to enable
|
||||||
|
MQTT_HOST=you_host_mqtt
|
||||||
|
MQTT_PORT=1883
|
||||||
|
MQTT_USER=your_user_mqtt
|
||||||
|
MQTT_PWD=yout_password_mqtt
|
||||||
|
MQTT_TOPIC="pigarden/result"
|
||||||
|
MQTT_CLIENT_ID=piGarden
|
||||||
|
|
||||||
177
conf/piGarden.conf.remote.example
Normal file
177
conf/piGarden.conf.remote.example
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
# Log file
|
||||||
|
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"
|
||||||
|
|
||||||
|
# Status directory
|
||||||
|
STATUS_DIR="/home/pi/piGarden/state"
|
||||||
|
|
||||||
|
# Event directory
|
||||||
|
EVENT_DIR="/home/pi/piGarden/events"
|
||||||
|
|
||||||
|
# Posizione gpio
|
||||||
|
GPIO="/usr/local/bin/gpio"
|
||||||
|
|
||||||
|
# Posizione js
|
||||||
|
JQ="/usr/local/bin/jq"
|
||||||
|
|
||||||
|
# Percorso curl
|
||||||
|
CURL="/usr/bin/curl"
|
||||||
|
|
||||||
|
# Percorso wc
|
||||||
|
WC="/usr/bin/wc"
|
||||||
|
|
||||||
|
# Percorso gzip
|
||||||
|
GZIP="/bin/gzip"
|
||||||
|
|
||||||
|
# Percorso mv
|
||||||
|
MV="/bin/mv"
|
||||||
|
|
||||||
|
# Percorso di tr
|
||||||
|
TR="/usr/bin/tr"
|
||||||
|
|
||||||
|
# Percorso di cut
|
||||||
|
CUT="/usr/bin/cut"
|
||||||
|
|
||||||
|
# Percorso tcpserver
|
||||||
|
TCPSERVER="/usr/bin/tcpserver"
|
||||||
|
|
||||||
|
# Percorso cron
|
||||||
|
CRONTAB="/usr/bin/crontab"
|
||||||
|
|
||||||
|
# Percorso grep
|
||||||
|
GREP="/bin/grep"
|
||||||
|
|
||||||
|
# Percorsp sed
|
||||||
|
SED="/bin/sed"
|
||||||
|
|
||||||
|
# Percorso readlink
|
||||||
|
READLINK="/bin/readlink"
|
||||||
|
|
||||||
|
# Percorso stat
|
||||||
|
STAT="/usr/bin/stat"
|
||||||
|
|
||||||
|
# Percorso mosquito_pub
|
||||||
|
# Installare con apt install mosquitto-clients
|
||||||
|
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
|
||||||
|
|
||||||
|
# Percorso di piGardenSched, se non definito non verranno gestire le schedulazioni di piGardenSched tramite api
|
||||||
|
#PIGARDENSCHED_PATH="/home/pi/piGardenSched/piGardenSched.sh"
|
||||||
|
|
||||||
|
|
||||||
|
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
||||||
|
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
||||||
|
EV_MONOSTABLE=0
|
||||||
|
|
||||||
|
# Id gpio usati per simulare il doppio deviatore con cui eseguire l'alimentazione alle elettrovalvole
|
||||||
|
SUPPLY_GPIO_1=2
|
||||||
|
SUPPLY_GPIO_2=3
|
||||||
|
|
||||||
|
# Stato dei due gpio per impartire l'alimentazione positiva alle elettrovalvole (aperta)
|
||||||
|
SUPPLY_GPIO_POS=0
|
||||||
|
|
||||||
|
# Stato dei due gpio per impartire l'alimentazione negativa alle elettrovalvole (chiusa)
|
||||||
|
SUPPLY_GPIO_NEG=1
|
||||||
|
|
||||||
|
# Stato di ingresso da assegnare al gpio per chiudere il rele
|
||||||
|
RELE_GPIO_CLOSE=0
|
||||||
|
|
||||||
|
# Stato di ingresso da assegnare al gpio per aprire il rele
|
||||||
|
RELE_GPIO_OPEN=1
|
||||||
|
|
||||||
|
# Id del gpio usato per collegare il sensore di rilevamento pioggia
|
||||||
|
RAIN_GPIO=25 # Physical 22 - wPi 6
|
||||||
|
|
||||||
|
# Valore in ingresso sul gpio definito in RAIN_GPIO che indica lo stato di pioggia
|
||||||
|
RAIN_GPIO_STATE=0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Numero totale di elettrovalvole
|
||||||
|
EV_TOTAL=4
|
||||||
|
|
||||||
|
# Definizione delle elettrovalvole
|
||||||
|
EV1_ALIAS="Giardino_Posteriore_DX" #
|
||||||
|
EV1_GPIO="drv:remote:PIREMOTE1:Giardino_Posteriore_DX"
|
||||||
|
#EV1_NORAIN=1 # Non interrompe l'irrigazione di questa zona in caso di pioggia
|
||||||
|
|
||||||
|
EV2_ALIAS="Giardino_Posteriore_CN" #
|
||||||
|
EV2_GPIO="drv:remote:PIREMOTE2:Giardino_Posteriore_CN"
|
||||||
|
|
||||||
|
EV3_ALIAS="Giardino_Posteriore_SX" #
|
||||||
|
EV3_GPIO="drv:remote:PIREMOTE2:Giardino_Posteriore_SX"
|
||||||
|
|
||||||
|
EV4_ALIAS="Giardino_Posteriore_GPIO" #
|
||||||
|
EV4_GPIO="18"
|
||||||
|
|
||||||
|
|
||||||
|
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground.
|
||||||
|
# Se non vuoi configurare nessun servizio imposta il vale "none"
|
||||||
|
WEATHER_SERVICE="openweathermap"
|
||||||
|
#WEATHER_SERVICE="none" # Nessun servizio configurato
|
||||||
|
|
||||||
|
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||||
|
OPENWEATHERMAP_KEY=""
|
||||||
|
OPENWEATHERMAP_LOCATION="q=Pieve%20a%20Nievole,it" # https://openweathermap.org/current
|
||||||
|
OPENWEATHERMAP_TZ="Europe/Rome" # Time zone
|
||||||
|
|
||||||
|
# Parametri di wunderground, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||||
|
WUNDERGROUND_KEY=""
|
||||||
|
WUNDERGROUND_LOCATION="IT/Pieve%20a%20Nievole" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||||
|
|
||||||
|
|
||||||
|
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
||||||
|
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||||
|
NOT_IRRIGATE_IF_RAIN_ONLINE=86400
|
||||||
|
|
||||||
|
# Il parametro è simile a quello precedente, il controllo però anziché essere fatto attingendo a wunderground, viene eseguito direttamente sul sensore se installato. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||||
|
NOT_IRRIGATE_IF_RAIN_SENSOR=86400
|
||||||
|
|
||||||
|
# Indirizzo ip e porta di ascolto del socket server
|
||||||
|
TCPSERVER_IP="127.0.0.1"
|
||||||
|
TCPSERVER_PORT="8084"
|
||||||
|
|
||||||
|
# Utente e password che i clients devono utilizzare per stabilire una connessione tramite socket server
|
||||||
|
TCPSERVER_USER=""
|
||||||
|
TCPSERVER_PWD=""
|
||||||
|
|
||||||
|
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
||||||
|
NO_SEND_IDENTIFIER=0
|
||||||
|
|
||||||
|
# Parametri connessione al broker mqtt
|
||||||
|
MQTT_ENABLE=0 # set 1 to enable
|
||||||
|
MQTT_HOST=you_host_mqtt
|
||||||
|
MQTT_PORT=1883
|
||||||
|
MQTT_USER=your_user_mqtt
|
||||||
|
MQTT_PWD=yout_password_mqtt
|
||||||
|
MQTT_TOPIC="pigarden/result"
|
||||||
|
MQTT_CLIENT_ID=piGarden
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Configurazione piGarden remoti
|
||||||
|
#
|
||||||
|
PIREMOTE1_IP="192.168.1.51"
|
||||||
|
PIREMOTE1_PORT="8084"
|
||||||
|
PIREMOTE1_USER=""
|
||||||
|
PIREMOTE1_PWD=""
|
||||||
|
|
||||||
|
PIREMOTE2_IP="192.168.1.52"
|
||||||
|
PIREMOTE2_PORT="8084"
|
||||||
|
PIREMOTE2_USER=""
|
||||||
|
PIREMOTE2_PWD=""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
177
conf/piGarden.conf.sonoff_tasmota_http.example
Normal file
177
conf/piGarden.conf.sonoff_tasmota_http.example
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
# Log file
|
||||||
|
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"
|
||||||
|
|
||||||
|
# Status directory
|
||||||
|
STATUS_DIR="/home/pi/piGarden/state"
|
||||||
|
|
||||||
|
# Event directory
|
||||||
|
EVENT_DIR="/home/pi/piGarden/events"
|
||||||
|
|
||||||
|
# Posizione gpio
|
||||||
|
GPIO="/usr/local/bin/gpio"
|
||||||
|
|
||||||
|
# Posizione js
|
||||||
|
JQ="/usr/local/bin/jq"
|
||||||
|
|
||||||
|
# Percorso curl
|
||||||
|
CURL="/usr/bin/curl"
|
||||||
|
|
||||||
|
# Percorso wc
|
||||||
|
WC="/usr/bin/wc"
|
||||||
|
|
||||||
|
# Percorso gzip
|
||||||
|
GZIP="/bin/gzip"
|
||||||
|
|
||||||
|
# Percorso mv
|
||||||
|
MV="/bin/mv"
|
||||||
|
|
||||||
|
# Percorso di tr
|
||||||
|
TR="/usr/bin/tr"
|
||||||
|
|
||||||
|
# Percorso di cut
|
||||||
|
CUT="/usr/bin/cut"
|
||||||
|
|
||||||
|
# Percorso tcpserver
|
||||||
|
TCPSERVER="/usr/bin/tcpserver"
|
||||||
|
|
||||||
|
# Percorso cron
|
||||||
|
CRONTAB="/usr/bin/crontab"
|
||||||
|
|
||||||
|
# Percorso grep
|
||||||
|
GREP="/bin/grep"
|
||||||
|
|
||||||
|
# Percorsp sed
|
||||||
|
SED="/bin/sed"
|
||||||
|
|
||||||
|
# Percorso readlink
|
||||||
|
READLINK="/bin/readlink"
|
||||||
|
|
||||||
|
# Percorso stat
|
||||||
|
STAT="/usr/bin/stat"
|
||||||
|
|
||||||
|
# Percorso mosquito_pub
|
||||||
|
# # Installare con apt install mosquitto-clients
|
||||||
|
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
|
||||||
|
|
||||||
|
# Percorso di piGardenSched, se non definito non verranno gestire le schedulazioni di piGardenSched tramite api
|
||||||
|
#PIGARDENSCHED_PATH="/home/pi/piGardenSched/piGardenSched.sh"
|
||||||
|
|
||||||
|
|
||||||
|
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
||||||
|
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
||||||
|
EV_MONOSTABLE=0
|
||||||
|
|
||||||
|
# Id gpio usati per simulare il doppio deviatore con cui eseguire l'alimentazione alle elettrovalvole
|
||||||
|
SUPPLY_GPIO_1=2
|
||||||
|
SUPPLY_GPIO_2=3
|
||||||
|
|
||||||
|
# Stato dei due gpio per impartire l'alimentazione positiva alle elettrovalvole (aperta)
|
||||||
|
SUPPLY_GPIO_POS=0
|
||||||
|
|
||||||
|
# Stato dei due gpio per impartire l'alimentazione negativa alle elettrovalvole (chiusa)
|
||||||
|
SUPPLY_GPIO_NEG=1
|
||||||
|
|
||||||
|
# Stato di ingresso da assegnare al gpio per chiudere il rele
|
||||||
|
RELE_GPIO_CLOSE=0
|
||||||
|
|
||||||
|
# Stato di ingresso da assegnare al gpio per aprire il rele
|
||||||
|
RELE_GPIO_OPEN=1
|
||||||
|
|
||||||
|
# Id del gpio usato per collegare il sensore di rilevamento pioggia
|
||||||
|
RAIN_GPIO=25 # Physical 22 - wPi 6
|
||||||
|
|
||||||
|
# Valore in ingresso sul gpio definito in RAIN_GPIO che indica lo stato di pioggia
|
||||||
|
RAIN_GPIO_STATE=0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Numero totale di elettrovalvole
|
||||||
|
EV_TOTAL=4
|
||||||
|
|
||||||
|
# Definizione delle elettrovalvole
|
||||||
|
EV1_ALIAS="Giardino_Posteriore_DX"
|
||||||
|
EV1_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power1"
|
||||||
|
EV1_MONOSTABLE=1
|
||||||
|
|
||||||
|
EV2_ALIAS="Giardino_Posteriore_CN"
|
||||||
|
EV2_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power2"
|
||||||
|
EV2_MONOSTABLE=1
|
||||||
|
|
||||||
|
EV3_ALIAS="Giardino_Posteriore_SX"
|
||||||
|
EV3_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power3"
|
||||||
|
EV3_MONOSTABLE=1
|
||||||
|
|
||||||
|
EV4_ALIAS="Giardino_Anteriore"
|
||||||
|
EV4_GPIO="drv:sonoff_tasmota_http:SONOFF2:Power1"
|
||||||
|
|
||||||
|
|
||||||
|
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground.
|
||||||
|
# Se non vuoi configurare nessun servizio imposta il vale "none"
|
||||||
|
WEATHER_SERVICE="openweathermap"
|
||||||
|
#WEATHER_SERVICE="none" # Nessun servizio configurato
|
||||||
|
|
||||||
|
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||||
|
OPENWEATHERMAP_KEY=""
|
||||||
|
OPENWEATHERMAP_LOCATION="q=Pieve%20a%20Nievole,it" # https://openweathermap.org/current
|
||||||
|
OPENWEATHERMAP_TZ="Europe/Rome" # Time zone
|
||||||
|
|
||||||
|
# Parametri di wunderground, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||||
|
WUNDERGROUND_KEY=""
|
||||||
|
WUNDERGROUND_LOCATION="IT/Pieve%20a%20Nievole" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||||
|
|
||||||
|
|
||||||
|
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
||||||
|
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||||
|
NOT_IRRIGATE_IF_RAIN_ONLINE=86400
|
||||||
|
|
||||||
|
# Il parametro è simile a quello precedente, il controllo però anziché essere fatto attingendo a wunderground, viene eseguito direttamente sul sensore se installato. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||||
|
NOT_IRRIGATE_IF_RAIN_SENSOR=86400
|
||||||
|
|
||||||
|
# Indirizzo ip e porta di ascolto del socket server
|
||||||
|
TCPSERVER_IP="127.0.0.1"
|
||||||
|
TCPSERVER_PORT="8084"
|
||||||
|
|
||||||
|
# Utente e password che i clients devono utilizzare per stabilire una connessione tramite socket server
|
||||||
|
TCPSERVER_USER=""
|
||||||
|
TCPSERVER_PWD=""
|
||||||
|
|
||||||
|
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
||||||
|
NO_SEND_IDENTIFIER=0
|
||||||
|
|
||||||
|
# Parametri connessione al broker mqtt
|
||||||
|
MQTT_ENABLE=0 # set 1 to enable
|
||||||
|
MQTT_HOST=you_host_mqtt
|
||||||
|
MQTT_PORT=1883
|
||||||
|
MQTT_USER=your_user_mqtt
|
||||||
|
MQTT_PWD=yout_password_mqtt
|
||||||
|
MQTT_TOPIC="pigarden/result"
|
||||||
|
MQTT_CLIENT_ID=piGarden
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Configurazione moduli sonoff
|
||||||
|
#
|
||||||
|
SONOFF1_IP="192.168.1.1"
|
||||||
|
SONOFF1_USER="user"
|
||||||
|
SONOFF1_PWD="pwd"
|
||||||
|
|
||||||
|
SONOFF2_IP="192.168.1.21"
|
||||||
|
SONOFF2_USER=""
|
||||||
|
SONOFF2_PWD=""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -2,6 +2,14 @@
|
|||||||
LOG_FILE="/home/pi/piGarden/log/piGarden.log"
|
LOG_FILE="/home/pi/piGarden/log/piGarden.log"
|
||||||
LOG_FILE_MAX_SIZE=1048576 # 1MB
|
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 file for driver output
|
||||||
#LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log"
|
#LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log"
|
||||||
|
|
||||||
@@ -53,6 +61,14 @@ READLINK="/bin/readlink"
|
|||||||
# Percorso stat
|
# Percorso stat
|
||||||
STAT="/usr/bin/stat"
|
STAT="/usr/bin/stat"
|
||||||
|
|
||||||
|
# Percorso mosquito_pub
|
||||||
|
# Installare con apt install mosquitto-clients
|
||||||
|
MOSQUITTO_PUB="/usr/bin/mosquitto_pub"
|
||||||
|
|
||||||
|
# Percorso di piGardenSched, se non definito non verranno gestire le schedulazioni di piGardenSched tramite api
|
||||||
|
#PIGARDENSCHED_PATH="/home/pi/piGardenSched/piGardenSched.sh"
|
||||||
|
|
||||||
|
|
||||||
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
||||||
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
||||||
EV_MONOSTABLE=1
|
EV_MONOSTABLE=1
|
||||||
@@ -472,9 +488,20 @@ EV128_ALIAS="Zona_128" #
|
|||||||
EV128_GPIO="drv:spb16ch:128"
|
EV128_GPIO="drv:spb16ch:128"
|
||||||
|
|
||||||
|
|
||||||
# Definisce l'api key e il luogo per recuperare lo stato meteo online
|
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground.
|
||||||
|
# Se non vuoi configurare nessun servizio imposta il vale "none"
|
||||||
|
WEATHER_SERVICE="openweathermap"
|
||||||
|
#WEATHER_SERVICE="none" # Nessun servizio configurato
|
||||||
|
|
||||||
|
# Parametri di openweathermap, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||||
|
OPENWEATHERMAP_KEY=""
|
||||||
|
OPENWEATHERMAP_LOCATION="q=Pieve%20a%20Nievole,it" # https://openweathermap.org/current
|
||||||
|
OPENWEATHERMAP_TZ="Europe/Rome" # Time zone
|
||||||
|
|
||||||
|
# Parametri di wunderground, definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||||
WUNDERGROUND_KEY=""
|
WUNDERGROUND_KEY=""
|
||||||
WUNDERGROUND_LOCATION="IY/Monsummano" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
WUNDERGROUND_LOCATION="IT/Pieve%20a%20Nievole" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||||
|
|
||||||
|
|
||||||
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
||||||
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||||
@@ -494,6 +521,15 @@ TCPSERVER_PWD=""
|
|||||||
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
||||||
NO_SEND_IDENTIFIER=0
|
NO_SEND_IDENTIFIER=0
|
||||||
|
|
||||||
|
# Parametri connessione al broker mqtt
|
||||||
|
MQTT_ENABLE=0 # set 1 to enable
|
||||||
|
MQTT_HOST=you_host_mqtt
|
||||||
|
MQTT_PORT=1883
|
||||||
|
MQTT_USER=your_user_mqtt
|
||||||
|
MQTT_PWD=yout_password_mqtt
|
||||||
|
MQTT_TOPIC="pigarden/result"
|
||||||
|
MQTT_CLIENT_ID=piGarden
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Configurazione schede spb16ch
|
# Configurazione schede spb16ch
|
||||||
|
|||||||
13
drv/openweathermap/README.md
Normal file
13
drv/openweathermap/README.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Driver for check wather condition with openweathermap online service
|
||||||
|
|
||||||
|
# Example of configuration in piGarden.conf
|
||||||
|
|
||||||
|
```bash
|
||||||
|
WEATHER_SERVICE="openweathermap"
|
||||||
|
|
||||||
|
OPENWEATHERMAP_KEY="d4d22ea805788420267971135563b4cc" # Set with your api key of openweathermap
|
||||||
|
OPENWEATHERMAP_LOCATION="q=Pieve%20a%20Nievole,it" # Set with location identify, see https://openweathermap.org/current
|
||||||
|
OPENWEATHERMAP_TZ="Europe/Rome" # Set with your time zone
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
123
drv/openweathermap/common.include.sh
Normal file
123
drv/openweathermap/common.include.sh
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
#
|
||||||
|
# Funzioni comuni utilizzate dal driver
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Recupera la descrizione della condizione meteo
|
||||||
|
#
|
||||||
|
# $1 condizione meteo recuperata dalle api
|
||||||
|
#
|
||||||
|
function drv_openweathermap_get_wather {
|
||||||
|
|
||||||
|
declare -A w
|
||||||
|
|
||||||
|
w["thunderstorm with light rain"]="Thunderstorms and Rain"
|
||||||
|
w["thunderstorm with rain"]="Thunderstorms and Rain"
|
||||||
|
w["thunderstorm with heavy rain"]="Thunderstorms and Rain"
|
||||||
|
w["light thunderstorm"]="Thunderstorm"
|
||||||
|
w["thunderstorm"]="Thunderstorm"
|
||||||
|
w["heavy thunderstorm"]="Thunderstorm"
|
||||||
|
w["ragged thunderstorm"]="Thunderstorm"
|
||||||
|
w["thunderstorm with light drizzle"]="Thunderstorms and Rain"
|
||||||
|
w["thunderstorm with drizzle"]="Thunderstorms and Rain"
|
||||||
|
w["thunderstorm with heavy drizzle"]="Thunderstorms and Rain"
|
||||||
|
|
||||||
|
w["light intensity drizzle"]="Drizzle"
|
||||||
|
w["drizzle"]="Drizzle"
|
||||||
|
w["heavy intensity drizzle"]="Drizzle"
|
||||||
|
w["light intensity drizzle rain"]="Drizzle"
|
||||||
|
w["drizzle rain"]="Drizzle"
|
||||||
|
w["heavy intensity drizzle rain"]="Drizzle"
|
||||||
|
w["shower rain and drizzle"]="Drizzle"
|
||||||
|
w["heavy shower rain and drizzle"]="Drizzle"
|
||||||
|
w["shower drizzle"]="Drizzle"
|
||||||
|
|
||||||
|
w["light rain"]="Rain Mist"
|
||||||
|
w["moderate rain"]="Rain"
|
||||||
|
w["heavy intensity rain"]="Rain"
|
||||||
|
w["very heavy rain"]="Rain"
|
||||||
|
w["extreme rain"]="Rain"
|
||||||
|
w["freezing rain"]="Freezing Rain"
|
||||||
|
w["light intensity shower rain"]="Rain"
|
||||||
|
w["shower rain"]="Rain"
|
||||||
|
w["heavy intensity shower rain"]="Rain"
|
||||||
|
w["ragged shower rain"]="Rain"
|
||||||
|
|
||||||
|
w["light snow"]="Snow"
|
||||||
|
w["snow"]="Snow"
|
||||||
|
w["heavy snow"]=""
|
||||||
|
w["sleet"]="Snow Grains"
|
||||||
|
w["shower sleet"]="Snow Grains"
|
||||||
|
w["light rain and snow"]="Snow"
|
||||||
|
w["rain and snow"]="Snow"
|
||||||
|
w["light shower snow"]="Snow"
|
||||||
|
w["shower snow"]="Snow"
|
||||||
|
w["heavy shower snow"]="Snow"
|
||||||
|
|
||||||
|
w["mist"]="Mist"
|
||||||
|
w["smoke"]="Smoke"
|
||||||
|
w["haze"]="Haze"
|
||||||
|
w["sand, dust whirls"]="Dust Whirls"
|
||||||
|
w["fog"]="Fog"
|
||||||
|
w["sand"]="Sand"
|
||||||
|
w["dust"]="Widespread Dust"
|
||||||
|
w["volcanic ash"]="Volcanic Ash"
|
||||||
|
w["squalls"]="Squalls"
|
||||||
|
w["tornado"]="Tornado"
|
||||||
|
|
||||||
|
w["clear sky"]="Clear"
|
||||||
|
|
||||||
|
w["few clouds"]="Partly Cloudy"
|
||||||
|
w["scattered clouds"]="Scattered Clouds"
|
||||||
|
w["broken clouds"]="Partly Cloudy"
|
||||||
|
w["overcast clouds"]="Mostly Cloudy"
|
||||||
|
|
||||||
|
local weather=${w[$1]}
|
||||||
|
|
||||||
|
if [ -z "$weather" ]; then
|
||||||
|
weather="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $weather
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Recupera la l'icona rappresentativa delle condizione meteo
|
||||||
|
#
|
||||||
|
# $1 nome dell'icona recuperato delle api weather.icon
|
||||||
|
#
|
||||||
|
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"
|
||||||
|
|
||||||
|
local ico=${w[$1]}
|
||||||
|
|
||||||
|
if [ -z "$ico" ]; then
|
||||||
|
ico="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $ico
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
74
drv/openweathermap/rainonline.include.sh
Normal file
74
drv/openweathermap/rainonline.include.sh
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#
|
||||||
|
# Ritorna lo stato delle condizioni meteo interrogando il servizio online
|
||||||
|
#
|
||||||
|
# $i identificativo gpio del sensore di pioggia
|
||||||
|
#
|
||||||
|
# return output: 0 - errore durante il recupero delle condizioni meteo
|
||||||
|
# >0 - rilevato pioggia, timestamp del rilevamento
|
||||||
|
# <0 - rilevato nessuna pioggia, timestamp del rilevamento
|
||||||
|
function drv_openweathermap_rain_online_get {
|
||||||
|
|
||||||
|
# http://www.wunderground.com/weather/api/d/docs?d=resources/phrase-glossary&MR=1
|
||||||
|
$CURL "http://api.openweathermap.org/data/2.5/weather?$OPENWEATHERMAP_LOCATION&units=metric&appid=$OPENWEATHERMAP_KEY" > $TMP_PATH/check_rain_online.openweathermap.json
|
||||||
|
local weather=`cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -M ".weather[0].main"`
|
||||||
|
|
||||||
|
local wind_deg=$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".wind.deg")
|
||||||
|
local wind_speed=$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".wind.speed")
|
||||||
|
if [ "$wind_speed" == "null" ]; then
|
||||||
|
#wind_speed=$($JQ -n $wind_speed*3600/1000)
|
||||||
|
wind_speed=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
local weather="$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".weather[0].description")"
|
||||||
|
local ico=$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".weather[0].icon")
|
||||||
|
weather=$(drv_openweathermap_get_wather "$weather")
|
||||||
|
ico=$(drv_openweathermap_get_ico "$ico")
|
||||||
|
|
||||||
|
local current_observation=$(cat <<EOF
|
||||||
|
{
|
||||||
|
"display_location": {
|
||||||
|
"city": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".name")"
|
||||||
|
},
|
||||||
|
"observation_epoch": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".dt")",
|
||||||
|
"local_epoch": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".dt")",
|
||||||
|
"local_tz_long": "$OPENWEATHERMAP_TZ",
|
||||||
|
"weather": "$weather",
|
||||||
|
"temp_c": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".main.temp")",
|
||||||
|
"relative_humidity": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".main.humidity")%",
|
||||||
|
"wind_dir": "$(deg2dir $wind_deg)",
|
||||||
|
"wind_degrees": "$wind_deg",
|
||||||
|
"wind_kph": "$wind_speed",
|
||||||
|
"wind_gust_kph": "--",
|
||||||
|
"pressure_mb": "$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".main.pressure")",
|
||||||
|
"dewpoint_c": "--",
|
||||||
|
"feelslike_c": "--",
|
||||||
|
"icon_url": "$ico"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
# "icon_url": "http://openweathermap.org/img/w/$(cat $TMP_PATH/check_rain_online.openweathermap.json | $JQ -r -M ".weather[0].icon").png"
|
||||||
|
|
||||||
|
#local current_observation=`cat $TMP_PATH/check_rain_online.json | $JQ -M ".current_observation"`
|
||||||
|
|
||||||
|
if [ "$weather" = "null" ]; then
|
||||||
|
echo "0"
|
||||||
|
else
|
||||||
|
echo "$current_observation" > "$STATUS_DIR/last_weather_online"
|
||||||
|
local local_epoch=`cat $STATUS_DIR/last_weather_online | $JQ -M -r ".local_epoch"`
|
||||||
|
if [[ "$weather" == *"Rain"* ]] ||
|
||||||
|
[[ "$weather" == *"Snow"* ]] ||
|
||||||
|
[[ "$weather" == *"Hail"* ]] ||
|
||||||
|
[[ "$weather" == *"Ice"* ]] ||
|
||||||
|
[[ "$weather" == *"Thunderstorm"* ]] ||
|
||||||
|
[[ "$weather" == *"Drizzle"* ]];
|
||||||
|
then
|
||||||
|
echo $local_epoch
|
||||||
|
else
|
||||||
|
echo "-$local_epoch"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
4
drv/rainsensorqty/.gitignore
vendored
Normal file
4
drv/rainsensorqty/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
.set_var
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
124
drv/rainsensorqty/README.md
Normal file
124
drv/rainsensorqty/README.md
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
#
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file README.md
|
||||||
|
# Version: 0.2.5
|
||||||
|
# Data: 07/Apr/2020
|
||||||
|
|
||||||
|
|
||||||
|
FILE DI CONFIGURAZIONE /etc/piGarden.conf:
|
||||||
|
-----------------------------------------
|
||||||
|
NOTA: vedere nella directory conf_example il file esempio piu' aggiornato!
|
||||||
|
|
||||||
|
per attivare il driver e' necessario inserire la seguente variabile nel file di configurazion
|
||||||
|
RAIN_GPIO="drv:rainsensorqty:25" # Physical 22 - wPi 6
|
||||||
|
|
||||||
|
la variabile seguente e' impiegata anche da drv_rainsensorqty per rilevare la chiusura del contatto magnetico che, in un circuito pull-up, e' lo stato 1.
|
||||||
|
# Valore in ingresso sul gpio definito in RAIN_GPIO che indica lo stato di pioggia
|
||||||
|
RAIN_GPIO_STATE=1
|
||||||
|
le seguenti variabili controllano il driver come descritto:
|
||||||
|
RAINSENSORQTY_LOOPSFORSETRAINING=16 # dopo 16 impulsi, 16 vaschette riempite si considera pioggia
|
||||||
|
RAINSENSORQTY_SECSBETWEENRAINEVENT=10800 # =3h, significa che dopo 3 si resetta il numero di vaschette da riempire e solo dopo il riempimento del nuovo numero di vaschette si considera una nuova pioggia
|
||||||
|
infine la variabile seguente e' la quantita' di acqua espressa in mm di precipitazioni:
|
||||||
|
RAINSENSORQTY_MMEACH=0.33 # see RAINSENSORQTY driver readme for details
|
||||||
|
|
||||||
|
CALIBRAZIONE SENSORE PIOGGIA
|
||||||
|
----------------------------
|
||||||
|
secondo il seguente processo da me effettuato sul mio misuratore di pioggia:
|
||||||
|
Ho erogato 18 ml di acqua nel rain gauge che hanno prodotto 10 impulsi; pertanto il riempimento di 1.8 ml ha causato un impulso, 1 ml = 1000 mmc (mm cubici),
|
||||||
|
1.8 ml sono pari a 1800 mmc
|
||||||
|
la superficie della vaschetta in mmq e' pari a 110 mm x 55 mm = 5500 mmq
|
||||||
|
volume / superficie mi da' l'altezza, quindi 1800 mmc / 5500 mmq = 0.32727273 mm
|
||||||
|
se fossero stati 1.7 ml di acqua per ogni impulso/vaschetta riempita, la variabile sarebbe stata impostata a 0.30909091 mm
|
||||||
|
|
||||||
|
COMANDI SPECIALI
|
||||||
|
----------------
|
||||||
|
nella sottodirectory command sono presenti:
|
||||||
|
commands/rainsensorqty_CHECK.sh
|
||||||
|
chiama la funzione di verifica pioggia, la medesima chiamata da check_rain_sensor
|
||||||
|
commands/rainsensorqty_HISTORY.sh
|
||||||
|
visualizza lo storico della pioggia consultando il file $RAINSENSORQTY_HISTORY
|
||||||
|
puo' essere lanciato con l''opzione -force per ricostruire il file $RAINSENSORQTY_HISTORY dal $RAINSENSORQTY_HISTORYRAW
|
||||||
|
e con un argomento X, che permette di evidenziare solo gli ultimi X eventi
|
||||||
|
commands/rainsensorqty_HISTORYRAW.sh
|
||||||
|
visualizza lo storico della pioggia consultando il file $RAINSENSORQTY_HISTORYRAW
|
||||||
|
puo' essere lanciato senza argomenti per processare l'intero file, chiede conferma visto che i tempi sono potenzialmente lunghi
|
||||||
|
con un argomento X, che permette di evidenziare solo gli ultimi X eventi
|
||||||
|
commands/rainsensorqty_INIT.sh
|
||||||
|
inizializza il driver eseguendo lo script di monitoring - normalmente tale processo avviene da piGarden.sh
|
||||||
|
utile quando si vuole testare dei cambiamenti o se necessario riavviare dopo il kill del comando successivo
|
||||||
|
commands/rainsensorqty_KILL.sh
|
||||||
|
killa i processi di monitoring ed eventuali figli
|
||||||
|
commands/rainsensorqty_RAINNOW.sh
|
||||||
|
simula una pioggia registrandola in $RAINSENSORQTY_LASTRAIN $RAINSENSORQTY_HISTORY $RAINSENSORQTY_HISTORYRAW
|
||||||
|
puo' essere lanciato in 3 modi:
|
||||||
|
senza argomenti: genera una pioggia per un numero di loop pari al valore della variabile RAINSENSORQTY_LOOPSFORSETRAINING, quindi una pioggia completa
|
||||||
|
con un argomento: che indica quanti loop
|
||||||
|
con due argomenti: quanti loop e quanti secondi tra uno e l'altro
|
||||||
|
commands/rainsensorqty_REMOVELASTRAIN.sh
|
||||||
|
rimuove dai file $RAINSENSORQTY_LASTRAIN $RAINSENSORQTY_HISTORY $RAINSENSORQTY_HISTORYRAW l'ultima pioggia registrata
|
||||||
|
commands/rainsensorqty_RESET.sh
|
||||||
|
invia il SIGUSR1 al processo di monitor per resettare i cicli. Viene visualizzato il reset solo dopo il successivo PULSE, questo perche' non e' possibile per lo script ricevere il trap in quanto il processo $GPIO e' attivo in attesa del PULSE
|
||||||
|
|
||||||
|
questi i timestamps alla data del file:
|
||||||
|
-rwxr-xr-x 1 pi pi 1044 Sep 24 18:26 rainsensorqty_CHECK.sh
|
||||||
|
-rwxr-xr-x 1 pi pi 1139 Nov 28 00:17 rainsensorqty_HISTORYRAW.sh
|
||||||
|
-rwxr-xr-x 1 pi pi 1462 Nov 19 00:19 rainsensorqty_HISTORY.sh
|
||||||
|
-rwxr-xr-x 1 pi pi 596 Sep 24 18:26 rainsensorqty_INIT.sh
|
||||||
|
-rwxr-xr-x 1 pi pi 1300 Sep 24 18:26 rainsensorqty_KILL.sh
|
||||||
|
-rwxr-xr-x 1 pi pi 1111 Nov 27 00:05 rainsensorqty_RAINNOW.sh
|
||||||
|
-rwxr-xr-x 1 pi pi 1252 Nov 22 00:18 rainsensorqty_REMOVELASTRAIN.sh
|
||||||
|
-rwxr-xr-x 1 pi pi 897 Sep 24 18:26 rainsensorqty_RESET.sh
|
||||||
|
|
||||||
|
ULTERIORI VARIABILI in config.include.sh
|
||||||
|
----------------------------------------
|
||||||
|
esistono ulteriori variabili che potrebbe essere necessario variare
|
||||||
|
|
||||||
|
RAINSENSOR_DEBOUNCE=0.3 # 0.3 seconds for manage debounce of reed contact
|
||||||
|
serve per ritardare la lettura di un secondo impulso falso causato dal rimbalzo del contatto magnetico
|
||||||
|
|
||||||
|
RAINSENSORQTY_verbose="yes"
|
||||||
|
aumenta il livello di verbosita' nei file di log
|
||||||
|
|
||||||
|
RAINSENSORQTY_LASTRAIN="$STATUS_DIR/rainsensorqty_lastrain"
|
||||||
|
memorizza l'ultima pioggia
|
||||||
|
RAINSENSORQTY_HISTORY="$STATUS_DIR/rainsensorqty_history"
|
||||||
|
memorizza tutte le piogge permettendo di visualizzare lo storico (commands/rainsensorqty_HISTORY.sh)
|
||||||
|
RAINSENSORQTY_HISTORYRAW="$STATUS_DIR/rainsensorqty_history.raw"
|
||||||
|
memorizza in formato grezzo (raw) tutti gli impulsi registrati (formato: "secondi:impulsi" ) - consultabile il contenuto con commands/rainsensorqty_HISTORYRAW.sh
|
||||||
|
|
||||||
|
RAINSENSORQTY_MONITORLOG="$DIR_SCRIPT/log/rainsensorqty_monitor.log"
|
||||||
|
log dello script di monitoring, popolato solo se RAINSENSORQTY_verbose="yes"
|
||||||
|
|
||||||
|
RAINSENSORQTY_MONPID="$TMPDIR/rainsensorqty_monitor.pid"
|
||||||
|
file che viene popolato con il pid dello script di monitoring
|
||||||
|
|
||||||
|
RAINSENSORQTY_DIR="$DIR_SCRIPT/drv/rainsensorqty"
|
||||||
|
home directory del driver
|
||||||
|
|
||||||
|
monitor_sh="$RAINSENSORQTY_DIR/drv_rainsensorqty_monitor.sh"
|
||||||
|
script di monitoring
|
||||||
|
lo script eredita le variabili di ambiente da $RAINSENSORQTY_VAR ($TMPDIR/.rainsensorqty_var)
|
||||||
|
|
||||||
|
NOTA: $TMPDIR e' /tmp e lo script visualizza un warning se non e' un tmpfs
|
||||||
|
|
||||||
|
# internal gpio resistor, 3 values: pull-up, pull-down, none
|
||||||
|
# pull-up/down if rain gauge is connected directly to raspberry
|
||||||
|
# none if connected through an optocoupler circuit
|
||||||
|
GPIO_RESISTOR="none" #pull-up|pull-down|none
|
||||||
|
enable pull-up or pull-down resistor: https://raspberry-projects.com/pi/pi-hardware/raspberry-pi-model-b-plus/model-b-plus-io-pins
|
||||||
|
Pull-up is 50K min - 65K max.
|
||||||
|
Pull-down is 50K min - 60K max.
|
||||||
|
|
||||||
|
#rising means waiting for 1 status (from 0)
|
||||||
|
#falling means waiting for 0 status (from 1)
|
||||||
|
#RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
|
||||||
|
#RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
|
||||||
|
(( RAIN_GPIO_STATE == 1 )) && RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
|
||||||
|
(( RAIN_GPIO_STATE == 0 )) && RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
|
||||||
|
|
||||||
|
lo script di monitoring ascolta il cambiamento di stato da quello di riposo allo stato di impulso (chiusura del contatto reed).
|
||||||
|
dipendentemente dal circuto implementato, se lo stato di riposo e' 0, lo script attende la variazione verso 1 (rising)
|
||||||
|
se lo stato di riposo e' 1, lo script attende la variazione verso 0 (falling)
|
||||||
|
la variabile RAINSENSORQTY_PULSE viene impostata secondo il valore di RAIN_GPIO_STATE presente in /etc/piGarden.conf
|
||||||
|
cioe' il valore che ci si aspetta per registrare il riempimento della vaschetta dello stato di pioggia
|
||||||
0
drv/rainsensorqty/_version_0.2.5b
Normal file
0
drv/rainsensorqty/_version_0.2.5b
Normal file
35
drv/rainsensorqty/commands/rainsensorqty_CHECK.sh
Executable file
35
drv/rainsensorqty/commands/rainsensorqty_CHECK.sh
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "rainsensorqty_CHECK.sh"
|
||||||
|
# test script for checking rain status using drv_rainsensorqty_rain_sensor_get function
|
||||||
|
# Version: 0.2.0
|
||||||
|
# Data: 11/Aug/2019
|
||||||
|
|
||||||
|
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
|
||||||
|
SCRIPTNAME=${0##*/}
|
||||||
|
cd $SCRIPTDIR/.. # command is a subdirectory of driver
|
||||||
|
|
||||||
|
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
|
||||||
|
CONFIG_ETC="/etc/piGarden.conf"
|
||||||
|
LOG_OUTPUT_DRV_FILE="$DIR_SCRIPT/log/$LOG_OUTPUT_DRV_FILE"
|
||||||
|
|
||||||
|
. $CONFIG_ETC
|
||||||
|
|
||||||
|
. ./common.include.sh
|
||||||
|
. ./config.include.sh
|
||||||
|
. ./init.include.sh
|
||||||
|
. ./rainsensor.include.sh
|
||||||
|
|
||||||
|
# restituisce 0 se piove, e nell'output di testo il valore di "$RAIN_GPIO_STATE"
|
||||||
|
# restituisce 99 se non piove, output "norain"
|
||||||
|
# esce con 1 se non c'e' il monitoring, output "ERROR"
|
||||||
|
|
||||||
|
drv_rainsensorqty_rain_sensor_get
|
||||||
|
case $? in
|
||||||
|
0) echo "NORMAL: it's raining" ;;
|
||||||
|
99) echo "NORMAL: it's not raining" ;;
|
||||||
|
1) echo "ERROR: monitor process $DIR_SCRIPT/drv/rainsensorqty/drv_rainsensorqty_monitor.sh is not running" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
59
drv/rainsensorqty/commands/rainsensorqty_HISTORY.sh
Executable file
59
drv/rainsensorqty/commands/rainsensorqty_HISTORY.sh
Executable file
@@ -0,0 +1,59 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "rainsensorqty_CHECK.sh"
|
||||||
|
# test script for checking rain status using drv_rainsensorqty_rain_sensor_get function
|
||||||
|
# Version: 0.2.5
|
||||||
|
# Data: 08/Jan/2020
|
||||||
|
|
||||||
|
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
|
||||||
|
SCRIPTNAME=${0##*/}
|
||||||
|
cd $SCRIPTDIR/.. # command is a subdirectory of driver
|
||||||
|
|
||||||
|
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
|
||||||
|
CONFIG_ETC="/etc/piGarden.conf"
|
||||||
|
LOG_OUTPUT_DRV_FILE="$DIR_SCRIPT/log/$LOG_OUTPUT_DRV_FILE"
|
||||||
|
|
||||||
|
. $CONFIG_ETC
|
||||||
|
|
||||||
|
. ./common.include.sh
|
||||||
|
. ./config.include.sh
|
||||||
|
. ./init.include.sh
|
||||||
|
. ./rainsensor.include.sh
|
||||||
|
|
||||||
|
if [[ $1 = "-force" ]] ; then
|
||||||
|
if [[ -s $RAINSENSORQTY_HISTORY ]] ; then
|
||||||
|
echo backup $RAINSENSORQTY_HISTORY to ${RAINSENSORQTY_HISTORY}.old$$
|
||||||
|
cp $RAINSENSORQTY_HISTORY ${RAINSENSORQTY_HISTORY}.old$$
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "generate all rain events to $RAINSENSORQTY_HISTORY"
|
||||||
|
if ! rainevents > ${RAINSENSORQTY_HISTORY} ; then
|
||||||
|
echo "WARNING: rainevents function had error"
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! rain_history tmp ; then # update rain history with last rain if not
|
||||||
|
echo "WARNING: rain_history function had error"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cmd="cat"
|
||||||
|
if [[ $# > 0 ]] ; then
|
||||||
|
if (( $1 >= 1 )) ; then
|
||||||
|
echo "processing last $1 lines of $RAINSENSORQTY_HISTORYRAW file"
|
||||||
|
cmd="tail -$1"
|
||||||
|
else
|
||||||
|
echo "argument not recognized - exit"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo -e "\n\n"
|
||||||
|
|
||||||
|
if [[ -s $RAINSENSORQTY_HISTORY ]] ; then
|
||||||
|
echo "RAIN HISTORY"
|
||||||
|
cat $RAINSENSORQTY_HISTORY $RAINSENSORQTY_HISTORYTMP | $cmd | rain_when_amount
|
||||||
|
else
|
||||||
|
echo "WARNING: no \$RAINSENSORQTY_HISTORY file"
|
||||||
|
fi
|
||||||
50
drv/rainsensorqty/commands/rainsensorqty_HISTORYRAW.sh
Executable file
50
drv/rainsensorqty/commands/rainsensorqty_HISTORYRAW.sh
Executable file
@@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "rainsensorqty_CHECK.sh"
|
||||||
|
# test script for checking rain status using drv_rainsensorqty_rain_sensor_get function
|
||||||
|
# Version: 0.2.5
|
||||||
|
# Data: 07/Apr/2020
|
||||||
|
|
||||||
|
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
|
||||||
|
SCRIPTNAME=${0##*/}
|
||||||
|
cd $SCRIPTDIR/.. # command is a subdirectory of driver
|
||||||
|
|
||||||
|
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
|
||||||
|
CONFIG_ETC="/etc/piGarden.conf"
|
||||||
|
LOG_OUTPUT_DRV_FILE="$DIR_SCRIPT/log/$LOG_OUTPUT_DRV_FILE"
|
||||||
|
|
||||||
|
. $CONFIG_ETC
|
||||||
|
|
||||||
|
. ./common.include.sh
|
||||||
|
. ./config.include.sh
|
||||||
|
. ./init.include.sh
|
||||||
|
. ./rainsensor.include.sh
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $# = 0 ]] ; then
|
||||||
|
cmd=cat
|
||||||
|
echo "processing all entire $RAINSENSORQTY_HISTORYRAW file, will go on? (y/n)"
|
||||||
|
read answer
|
||||||
|
echo $answer
|
||||||
|
[[ $answer = [yY] ]] || exit 1
|
||||||
|
else
|
||||||
|
if (( $1 >= 1 )) ; then
|
||||||
|
echo "processing $1 lines of $RAINSENSORQTY_HISTORYRAW file"
|
||||||
|
cmd="tail -$1"
|
||||||
|
else
|
||||||
|
echo "argument not recognized - exit"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo -e "\n\n"
|
||||||
|
|
||||||
|
$cmd $RAINSENSORQTY_HISTORYRAW | while read line
|
||||||
|
do
|
||||||
|
set -- ${line//:/ }
|
||||||
|
secs=$1
|
||||||
|
counter=$2
|
||||||
|
echo "$(sec2date $1):$counter"
|
||||||
|
done
|
||||||
|
|
||||||
25
drv/rainsensorqty/commands/rainsensorqty_INIT.sh
Executable file
25
drv/rainsensorqty/commands/rainsensorqty_INIT.sh
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "rainsensorqty_INIT.sh"
|
||||||
|
# test script for initialize driver and executing monitor process
|
||||||
|
# Version: 0.2.0
|
||||||
|
# Data: 11/Aug/2019
|
||||||
|
|
||||||
|
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
|
||||||
|
SCRIPTNAME=${0##*/}
|
||||||
|
cd $SCRIPTDIR/.. # command is a subdirectory of driver
|
||||||
|
|
||||||
|
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
|
||||||
|
CONFIG_ETC="/etc/piGarden.conf"
|
||||||
|
|
||||||
|
. $CONFIG_ETC
|
||||||
|
|
||||||
|
. ./config.include.sh
|
||||||
|
. ./common.include.sh
|
||||||
|
. ./init.include.sh
|
||||||
|
. ./rainsensor.include.sh
|
||||||
|
|
||||||
|
drv_rainsensorqty_rain_sensor_init
|
||||||
|
|
||||||
|
drv_rainsensorqty_init
|
||||||
52
drv/rainsensorqty/commands/rainsensorqty_KILL.sh
Executable file
52
drv/rainsensorqty/commands/rainsensorqty_KILL.sh
Executable file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "rainsensorqty_KILL.sh"
|
||||||
|
# script for killing monitor process(es)
|
||||||
|
# Version: 0.2.0a
|
||||||
|
# Data: 29/Aug/2019
|
||||||
|
|
||||||
|
|
||||||
|
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
|
||||||
|
SCRIPTNAME=${0##*/}
|
||||||
|
cd $SCRIPTDIR/.. # command is a subdirectory of driver
|
||||||
|
|
||||||
|
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
|
||||||
|
CONFIG_ETC="/etc/piGarden.conf"
|
||||||
|
|
||||||
|
. $CONFIG_ETC
|
||||||
|
|
||||||
|
. ./config.include.sh
|
||||||
|
. ./common.include.sh
|
||||||
|
. ./init.include.sh
|
||||||
|
. ./rainsensor.include.sh
|
||||||
|
|
||||||
|
# check if rain monitor process is running...
|
||||||
|
if [[ -f "$RAINSENSORQTY_MONPID" ]] ; then
|
||||||
|
pid="$( < "$RAINSENSORQTY_MONPID" )"
|
||||||
|
if ps -fp $pid >/dev/null ; then
|
||||||
|
echo "process $pid pid and its child(ren)"
|
||||||
|
children_pid="$(ps -ef| awk "\$3==$pid {print \$2}")"
|
||||||
|
ps -fp $pid
|
||||||
|
ps -fp $children_pid | tail +2
|
||||||
|
echo -e "\nsending TERM signal to $pid and its child(ren)"
|
||||||
|
echo kill $children_pid
|
||||||
|
echo kill $pid
|
||||||
|
kill $children_pid
|
||||||
|
kill $pid
|
||||||
|
echo -e "\nchecking $pid pid and its child(ren) are still alive"
|
||||||
|
for process in $pid $children_pid
|
||||||
|
do
|
||||||
|
if ps -fp $process >/dev/null ; then
|
||||||
|
echo "$process is still alive"
|
||||||
|
else
|
||||||
|
echo "$process is dead"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo "no RAIN process alive"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "no RAIN process alive"
|
||||||
|
fi
|
||||||
|
|
||||||
67
drv/rainsensorqty/commands/rainsensorqty_RAINNOW.sh
Executable file
67
drv/rainsensorqty/commands/rainsensorqty_RAINNOW.sh
Executable file
@@ -0,0 +1,67 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "rainsensorqty_RAINNOW.sh"
|
||||||
|
# test script for simulate rain ... now!
|
||||||
|
# Version: 0.2.5
|
||||||
|
# Data: 07/Apr/2020
|
||||||
|
|
||||||
|
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
|
||||||
|
SCRIPTNAME=${0##*/}
|
||||||
|
cd $SCRIPTDIR/.. # command is a subdirectory of driver
|
||||||
|
|
||||||
|
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
|
||||||
|
CONFIG_ETC="/etc/piGarden.conf"
|
||||||
|
. $CONFIG_ETC
|
||||||
|
|
||||||
|
. ./config.include.sh
|
||||||
|
. ./common.include.sh
|
||||||
|
. ./init.include.sh
|
||||||
|
. ./rainsensor.include.sh
|
||||||
|
|
||||||
|
wait=0
|
||||||
|
timestart=$( date +%s)
|
||||||
|
if [[ $# -ne 0 ]] ; then
|
||||||
|
if [[ $# = 1 ]] ; then
|
||||||
|
howmany=$1
|
||||||
|
echo "one argument passed: rain event for $howmany loops"
|
||||||
|
(( time = timestart - howmany ))
|
||||||
|
elif [[ $# = 2 ]] ; then
|
||||||
|
howmany=$1
|
||||||
|
wait=$2
|
||||||
|
echo "two arguments passed: rain event for $howmany loops every $wait seconds"
|
||||||
|
(( time = timestart ))
|
||||||
|
else
|
||||||
|
echo "too many arguments... exit"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
howmany=$RAINSENSORQTY_LOOPSFORSETRAINING
|
||||||
|
(( time = timestart - $RAINSENSORQTY_LOOPSFORSETRAINING ))
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo "RAIN now! (for $howmany loops)"
|
||||||
|
for (( c=1; c<=$howmany; c++ ))
|
||||||
|
do
|
||||||
|
if (( wait > 0 )) ; then
|
||||||
|
time=$( date +%s)
|
||||||
|
else
|
||||||
|
(( time+= 1 ))
|
||||||
|
fi
|
||||||
|
linetoadd="$time:$c"
|
||||||
|
echo $linetoadd >> $RAINSENSORQTY_HISTORYRAW
|
||||||
|
sleep $wait
|
||||||
|
echo -e ".\c"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
|
||||||
|
if ! rain_history ; then # update rain history with last rain if not
|
||||||
|
echo "WARNING: rain_history function had error"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $linetoadd > ${RAINSENSORQTY_LASTRAIN}
|
||||||
|
echo "file ${RAINSENSORQTY_LASTRAIN} updated."
|
||||||
|
|
||||||
|
echo "last 2 rain events:"
|
||||||
|
tail -2 $RAINSENSORQTY_HISTORY | rain_when_amount
|
||||||
44
drv/rainsensorqty/commands/rainsensorqty_REMOVELASTRAIN.sh
Executable file
44
drv/rainsensorqty/commands/rainsensorqty_REMOVELASTRAIN.sh
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "test_rainsensorqty_CHECK.sh"
|
||||||
|
# test script for checking rain status using drv_rainsensorqty_rain_sensor_get function
|
||||||
|
# Version: 0.2.5
|
||||||
|
# Data: 07/Apr/2020
|
||||||
|
|
||||||
|
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
|
||||||
|
SCRIPTNAME=${0##*/}
|
||||||
|
cd $SCRIPTDIR/.. # command is a subdirectory of driver
|
||||||
|
|
||||||
|
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
|
||||||
|
CONFIG_ETC="/etc/piGarden.conf"
|
||||||
|
|
||||||
|
LOG_OUTPUT_DRV_FILE="$DIR_SCRIPT/log/$LOG_OUTPUT_DRV_FILE"
|
||||||
|
|
||||||
|
. $CONFIG_ETC
|
||||||
|
|
||||||
|
. ./common.include.sh
|
||||||
|
. ./config.include.sh
|
||||||
|
. ./init.include.sh
|
||||||
|
. ./rainsensor.include.sh
|
||||||
|
|
||||||
|
# two variables for store rain data
|
||||||
|
# RAINSENSORQTY_LASTRAIN
|
||||||
|
# RAINSENSORQTY_HISTORY
|
||||||
|
|
||||||
|
echo "RAIN HISTORY - last two events"
|
||||||
|
tail -2 $RAINSENSORQTY_HISTORY
|
||||||
|
tail -2 $RAINSENSORQTY_HISTORY | rain_when_amount
|
||||||
|
|
||||||
|
echo "...removing last event"
|
||||||
|
removelastrain
|
||||||
|
echo "...rebuilding ${RAINSENSORQTY_HISTORY} from ${RAINSENSORQTY_HISTORYRAW}"
|
||||||
|
if ! rainevents > ${RAINSENSORQTY_HISTORY} ; then
|
||||||
|
echo "WARNING: rainevents function had error"
|
||||||
|
fi
|
||||||
|
tail -1 ${RAINSENSORQTY_HISTORYRAW} > ${RAINSENSORQTY_LASTRAIN}
|
||||||
|
|
||||||
|
echo -e "\nnew RAIN HISTORY - last two events"
|
||||||
|
tail -2 $RAINSENSORQTY_HISTORY
|
||||||
|
tail -2 $RAINSENSORQTY_HISTORY | rain_when_amount
|
||||||
|
|
||||||
35
drv/rainsensorqty/commands/rainsensorqty_RESET.sh
Executable file
35
drv/rainsensorqty/commands/rainsensorqty_RESET.sh
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "rainsensorqty_RESET.sh"
|
||||||
|
# script for reset counter in monitor script
|
||||||
|
# Version: 0.2.0a
|
||||||
|
# Data: 29/Aug/2019
|
||||||
|
|
||||||
|
SCRIPTDIR="$(cd `dirname $0` ; pwd )"
|
||||||
|
SCRIPTNAME=${0##*/}
|
||||||
|
cd $SCRIPTDIR/.. # command is a subdirectory of driver
|
||||||
|
|
||||||
|
DIR_SCRIPT=/home/pi/piGarden # home directory of piGarden
|
||||||
|
CONFIG_ETC="/etc/piGarden.conf"
|
||||||
|
|
||||||
|
. $CONFIG_ETC
|
||||||
|
|
||||||
|
. ./config.include.sh
|
||||||
|
. ./common.include.sh
|
||||||
|
. ./init.include.sh
|
||||||
|
. ./rainsensor.include.sh
|
||||||
|
|
||||||
|
# check if rain monitor process is running...
|
||||||
|
if [[ -f "$RAINSENSORQTY_MONPID" ]] ; then
|
||||||
|
pid="$( < "$RAINSENSORQTY_MONPID" )"
|
||||||
|
if ps -fp $pid >/dev/null ; then
|
||||||
|
echo "sending SIGUSR1 to $pid"
|
||||||
|
kill -SIGUSR1 $pid
|
||||||
|
echo -e "sent SIGUSR1 - reset will be shown after next cycle"
|
||||||
|
else
|
||||||
|
echo "no RAIN process alive"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "no RAIN process alive"
|
||||||
|
fi
|
||||||
163
drv/rainsensorqty/common.include.sh
Normal file
163
drv/rainsensorqty/common.include.sh
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
#
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "common.include.sh"
|
||||||
|
# common functions used by driver
|
||||||
|
# Version: 0.2.5
|
||||||
|
# Data: 08/Jan/2020
|
||||||
|
|
||||||
|
|
||||||
|
#note:
|
||||||
|
#RAINSENSORQTY_MONPID="$TMPDIR/rainsensorqty_monitor.pid"
|
||||||
|
#
|
||||||
|
|
||||||
|
sec2date()
|
||||||
|
{
|
||||||
|
date --date="@$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
d() # short date & time
|
||||||
|
{
|
||||||
|
date '+%X-%x'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
drv_rainsensorqty_writelog()
|
||||||
|
{
|
||||||
|
#2 variables - $1 function, $2 message
|
||||||
|
if [[ $2 =~ ERROR || $2 =~ WARNING || $2 =~ RAIN || $RAINSENSORQTY_verbose = yes ]] ; then
|
||||||
|
echo -e "$1 - `d`\t\t$2" >> "$LOG_OUTPUT_DRV_FILE"
|
||||||
|
# if [[ $($WC -c <"$LOG_OUTPUT_DRV_FILE") > $LOG_FILE_MAX_SIZE )) ; then
|
||||||
|
# $GZIP "$LOG_OUTPUT_DRV_FILE"
|
||||||
|
# $MV "${LOG_OUTPUT_DRV_FILE}.gz" "${LOG_OUTPUT_DRV_FILE}.$(date +%Y%m%d%H%M).gz"
|
||||||
|
# fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
drv_rainsensorqty_check()
|
||||||
|
{
|
||||||
|
local f="drv_rainsensorqty_check"
|
||||||
|
|
||||||
|
if [[ -f "$RAINSENSORQTY_MONPID" ]] ; then
|
||||||
|
local pid=$( < "$RAINSENSORQTY_MONPID" )
|
||||||
|
drv_rainsensorqty_writelog $f "NORMAL: checking if $pid pid is running"
|
||||||
|
if ps -fp $pid >/dev/null ; then
|
||||||
|
drv_rainsensorqty_writelog $f "NORMAL: $pid pid is running"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
drv_rainsensorqty_writelog $f "ERROR: $pid pid monitor process NOT running - $RAINSENSORQTY_MONPID file contains $pid"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
drv_rainsensorqty_writelog $f "ERROR: no raining monitor process file \$RAINSENSORQTY_MONPID"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
en_echo() # enhanched echo - check verbose variable
|
||||||
|
{
|
||||||
|
[[ $RAINSENSORQTY_verbose = yes ]] && echo "$(d) $*"
|
||||||
|
}
|
||||||
|
|
||||||
|
rain_history()
|
||||||
|
{
|
||||||
|
[[ ! -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
|
||||||
|
|
||||||
|
#old #if grep -q ^$(<$RAINSENSORQTY_LASTRAIN)$ $RAINSENSORQTY_HISTORY ; then
|
||||||
|
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 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
rain_when_amount()
|
||||||
|
{
|
||||||
|
# from standard input
|
||||||
|
# format $time:$endtime:$endsequence
|
||||||
|
cat - | while read line
|
||||||
|
do
|
||||||
|
set -- ${line//:/ }
|
||||||
|
start=$1
|
||||||
|
stop=$2
|
||||||
|
howmuch=$3
|
||||||
|
printf "RAINED for %7.2f mm between %s and %s\n" $( $JQ -n "$howmuch * $RAINSENSORQTY_MMEACH" ) "$(date --date="@$start")" "$(date --date="@$stop")"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
check_TMPDIR()
|
||||||
|
{
|
||||||
|
if [[ $(df | awk '$NF=="/tmp" {print $1}') != "tmpfs" ]] ; then
|
||||||
|
echo "WARNING: /tmp isn't a tmp file system"
|
||||||
|
echo -e "\tplease add to your /etc/fstab file:\n\ttmpfs /tmp tmpfs defaults,noatime,nosuid 0 0"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
rainevents()
|
||||||
|
{
|
||||||
|
if [[ ! -f $RAINSENSORQTY_HISTORYRAW ]] ; then
|
||||||
|
#echo "WARNING: no \$RAINSENSORQTY_HISTORYRAW file"# cannot echo, redirected output
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
case $1 in
|
||||||
|
[0-9]|[0-9][0-9]) howmanyevent=$1 ;;
|
||||||
|
# -1) skiplast=true ;;
|
||||||
|
*) howmanyevent=-1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
newloop=yes
|
||||||
|
tac $RAINSENSORQTY_HISTORYRAW | while read line
|
||||||
|
do
|
||||||
|
set -- ${line//:/ }
|
||||||
|
time=$1
|
||||||
|
sequence=$2
|
||||||
|
if [[ $newloop == yes ]] ; then
|
||||||
|
endtime=$time
|
||||||
|
endsequence=$sequence
|
||||||
|
newloop=no
|
||||||
|
fi
|
||||||
|
if (( sequence == 1 )) ; then
|
||||||
|
# [[ $skiplast=true ]] && { skilast=false ; continue ; }
|
||||||
|
echo $time:$endtime:$endsequence
|
||||||
|
newloop=yes
|
||||||
|
(( event +=1 ))
|
||||||
|
fi
|
||||||
|
(( howmanyevent == event )) && break
|
||||||
|
done | sort -k1n
|
||||||
|
}
|
||||||
|
|
||||||
|
removelastrain()
|
||||||
|
{
|
||||||
|
if [[ ! -f $RAINSENSORQTY_HISTORYRAW ]] ; then
|
||||||
|
echo "WARNING: no \$RAINSENSORQTY_HISTORYRAW file"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
next=false
|
||||||
|
tac $RAINSENSORQTY_HISTORYRAW | while read line
|
||||||
|
do
|
||||||
|
set -- ${line//:/ }
|
||||||
|
time=$1
|
||||||
|
sequence=$2
|
||||||
|
[[ $next = true ]] && echo $line
|
||||||
|
(( sequence == 1 )) && next=true
|
||||||
|
done | tac > ${RAINSENSORQTY_HISTORYRAW}_$$
|
||||||
|
mv ${RAINSENSORQTY_HISTORYRAW}_$$ $RAINSENSORQTY_HISTORYRAW
|
||||||
|
}
|
||||||
66
drv/rainsensorqty/conf_example/config.include.sh
Normal file
66
drv/rainsensorqty/conf_example/config.include.sh
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "config.include.sh"
|
||||||
|
# specific driver config file
|
||||||
|
# Version: 0.2.5
|
||||||
|
# Data: 08/Jan/2020
|
||||||
|
|
||||||
|
export TMPDIR=/tmp
|
||||||
|
|
||||||
|
RAINSENSOR_DEBOUNCE=0.3 # 0.3 seconds for manage debounce of reed contact
|
||||||
|
|
||||||
|
RAINSENSORQTY_verbose="yes" # yes/no
|
||||||
|
|
||||||
|
RAINSENSORQTY_LASTRAIN="$STATUS_DIR/rainsensorqty_lastrain"
|
||||||
|
RAINSENSORQTY_HISTORY="$STATUS_DIR/rainsensorqty_history"
|
||||||
|
RAINSENSORQTY_HISTORYRAW="$STATUS_DIR/rainsensorqty_history.raw"
|
||||||
|
RAINSENSORQTY_HISTORYTMP="$TMPDIR/rainsensorqty_history.tmp"
|
||||||
|
|
||||||
|
RAINSENSORQTY_MONITORLOG="$DIR_SCRIPT/log/rainsensorqty_monitor.log"
|
||||||
|
|
||||||
|
RAINSENSORQTY_MONPID="$TMPDIR/rainsensorqty_monitor.pid"
|
||||||
|
RAINSENSORQTY_STATE="$TMPDIR/rainsensorqty_state"
|
||||||
|
RAINSENSORQTY_STATE_HIST="$TMPDIR/rainsensorqty_state.history"
|
||||||
|
|
||||||
|
RAINSENSORQTY_DIR="$DIR_SCRIPT/drv/rainsensorqty"
|
||||||
|
|
||||||
|
monitor_sh="$RAINSENSORQTY_DIR/drv_rainsensorqty_monitor.sh"
|
||||||
|
|
||||||
|
# internal gpio resistor, 3 values: pull-up, pull-down, none
|
||||||
|
# pull-up/down if rain gauge is connected directly to raspberry
|
||||||
|
# none if connected through an optocoupler circuit
|
||||||
|
GPIO_RESISTOR="pull-up" #pull-up|pull-down|none
|
||||||
|
|
||||||
|
#rising means waiting for 1 status (from 0)
|
||||||
|
#falling means waiting for 0 status (from 1)
|
||||||
|
#RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
|
||||||
|
#RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
|
||||||
|
(( RAIN_GPIO_STATE == 1 )) && RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
|
||||||
|
(( RAIN_GPIO_STATE == 0 )) && RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
|
||||||
|
|
||||||
|
|
||||||
|
config_check()
|
||||||
|
{
|
||||||
|
var2check="RAINSENSOR_DEBOUNCE RAINSENSORQTY_verbose RAINSENSORQTY_LASTRAIN RAINSENSORQTY_HISTORY RAINSENSORQTY_MONITORLOG RAINSENSORQTY_MONPID RAINSENSORQTY_DIR monitor_sh"
|
||||||
|
for var in $var2check
|
||||||
|
do
|
||||||
|
#${!a}
|
||||||
|
if [[ -z ${!var} ]] ; then
|
||||||
|
echo "ERROR: \$$var not set"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [[ -z $RAINSENSORQTY_PULSE ]] ; then
|
||||||
|
echo "ERROR: RAIN_GPIO_STATE not set in piGarden.conf"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
case $GPIO_RESISTOR in
|
||||||
|
pull-up|pull-down|none) return 0 ;;
|
||||||
|
*) echo "ERROR: GPIO_RESISTOR not set correctly - values are \"pull-up|pull-down|none\" "
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# cfg file version 0.2.0
|
||||||
|
# Id del gpio usato per collegare il sensore di rilevamento pioggia
|
||||||
|
# attraverso il driver rainsensorqty
|
||||||
|
RAIN_GPIO="drv:rainsensorqty:25" # Physical 22 - wPi 6
|
||||||
|
|
||||||
|
# Valore in ingresso sul gpio definito in RAIN_GPIO che indica lo stato di pioggia
|
||||||
|
# variabile usata anche da drv:rainsensorqty, se e' a 1, significa che il reed contact e' collegato ad un circuito pull-down, vuol dire che attende l'impulso a 1 per contare le vaschette, normalmente e' a 0.
|
||||||
|
# se e' a 0, significa che il reed contact e' collegato ad un circuito pull-up, vuol dire che attende l'impulso a 0 per contare le vaschette, normalmente e' a 0.
|
||||||
|
RAIN_GPIO_STATE=0
|
||||||
|
|
||||||
|
RAINSENSORQTY_LOOPSFORSETRAINING=16 # dopo 16 impulsi, 16 vaschette riempite si considera pioggia
|
||||||
|
RAINSENSORQTY_SECSBETWEENRAINEVENT=10800 # =3h, significa che dopo 3 ore si resetta il numero di vaschette riempire e solo dopo un nuovo ciclo di riempimento si considera una nuova pioggia
|
||||||
|
|
||||||
|
RAINSENSORQTY_MMEACH=0.33 # see RAINSENSORQTY driver readme for details
|
||||||
66
drv/rainsensorqty/config.include.sh
Normal file
66
drv/rainsensorqty/config.include.sh
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "config.include.sh"
|
||||||
|
# specific driver config file
|
||||||
|
# Version: 0.2.5
|
||||||
|
# Data: 08/Jan/2020
|
||||||
|
|
||||||
|
export TMPDIR=/tmp
|
||||||
|
|
||||||
|
RAINSENSOR_DEBOUNCE=0.3 # 0.3 seconds for manage debounce of reed contact
|
||||||
|
|
||||||
|
RAINSENSORQTY_verbose="yes" # yes/no
|
||||||
|
|
||||||
|
RAINSENSORQTY_LASTRAIN="$STATUS_DIR/rainsensorqty_lastrain"
|
||||||
|
RAINSENSORQTY_HISTORY="$STATUS_DIR/rainsensorqty_history"
|
||||||
|
RAINSENSORQTY_HISTORYRAW="$STATUS_DIR/rainsensorqty_history.raw"
|
||||||
|
RAINSENSORQTY_HISTORYTMP="$TMPDIR/rainsensorqty_history.tmp"
|
||||||
|
|
||||||
|
RAINSENSORQTY_MONITORLOG="$DIR_SCRIPT/log/rainsensorqty_monitor.log"
|
||||||
|
|
||||||
|
RAINSENSORQTY_MONPID="$TMPDIR/rainsensorqty_monitor.pid"
|
||||||
|
RAINSENSORQTY_STATE="$TMPDIR/rainsensorqty_state"
|
||||||
|
RAINSENSORQTY_STATE_HIST="$TMPDIR/rainsensorqty_state.history"
|
||||||
|
|
||||||
|
RAINSENSORQTY_DIR="$DIR_SCRIPT/drv/rainsensorqty"
|
||||||
|
|
||||||
|
monitor_sh="$RAINSENSORQTY_DIR/drv_rainsensorqty_monitor.sh"
|
||||||
|
|
||||||
|
# internal gpio resistor, 3 values: pull-up, pull-down, none
|
||||||
|
# pull-up/down if rain gauge is connected directly to raspberry
|
||||||
|
# none if connected through an optocoupler circuit
|
||||||
|
GPIO_RESISTOR="pull-up" #pull-up|pull-down|none
|
||||||
|
|
||||||
|
#rising means waiting for 1 status (from 0)
|
||||||
|
#falling means waiting for 0 status (from 1)
|
||||||
|
#RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
|
||||||
|
#RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
|
||||||
|
(( RAIN_GPIO_STATE == 1 )) && RAINSENSORQTY_PULSE=rising # pull-down circuit (rest status is 0)
|
||||||
|
(( RAIN_GPIO_STATE == 0 )) && RAINSENSORQTY_PULSE=falling # pull-up circuit (rest status is 1)
|
||||||
|
|
||||||
|
|
||||||
|
config_check()
|
||||||
|
{
|
||||||
|
var2check="RAINSENSOR_DEBOUNCE RAINSENSORQTY_verbose RAINSENSORQTY_LASTRAIN RAINSENSORQTY_HISTORY RAINSENSORQTY_MONITORLOG RAINSENSORQTY_MONPID RAINSENSORQTY_DIR monitor_sh"
|
||||||
|
for var in $var2check
|
||||||
|
do
|
||||||
|
#${!a}
|
||||||
|
if [[ -z ${!var} ]] ; then
|
||||||
|
echo "ERROR: \$$var not set"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [[ -z $RAINSENSORQTY_PULSE ]] ; then
|
||||||
|
echo "ERROR: RAIN_GPIO_STATE not set in piGarden.conf"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
case $GPIO_RESISTOR in
|
||||||
|
pull-up|pull-down|none) return 0 ;;
|
||||||
|
*) echo "ERROR: GPIO_RESISTOR not set correctly - values are \"pull-up|pull-down|none\" "
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
88
drv/rainsensorqty/drv_rainsensorqty_monitor.sh
Executable file
88
drv/rainsensorqty/drv_rainsensorqty_monitor.sh
Executable file
@@ -0,0 +1,88 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "drv_rainsensorqty_monitor.sh"
|
||||||
|
# monitor script
|
||||||
|
# Version: 0.2.5b
|
||||||
|
# Data: 12/May/2020
|
||||||
|
|
||||||
|
resetcounter()
|
||||||
|
{
|
||||||
|
(( counter = 0 ))
|
||||||
|
drv_rainsensorqty_writelog $f "SIGUSR1 received after last PULSE - counter resetted" &
|
||||||
|
echo "SIGUSR1 received after last PULSE - counter resetted"
|
||||||
|
}
|
||||||
|
|
||||||
|
###############
|
||||||
|
# MAIN #
|
||||||
|
###############
|
||||||
|
|
||||||
|
trap "resetcounter" SIGUSR1
|
||||||
|
|
||||||
|
|
||||||
|
DIRNAME="$( dirname $0 )"
|
||||||
|
f="$(basename $0)"
|
||||||
|
. $DIRNAME/common.include.sh
|
||||||
|
|
||||||
|
RAINSENSORQTY_VAR=$TMPDIR/.rainsensorqty_var
|
||||||
|
|
||||||
|
if [[ -f "$RAINSENSORQTY_VAR" ]] ; then
|
||||||
|
en_echo "NORMAL: file $RAINSENSORQTY_VAR found - getting variables"
|
||||||
|
. "$RAINSENSORQTY_VAR"
|
||||||
|
else
|
||||||
|
echo "ERROR: $RAINSENSORQTY_VAR not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#drvt="$( echo $RAIN_GPIO | $CUT -f 1 -d: )"
|
||||||
|
#drv="$( echo $RAIN_GPIO | $CUT -f 2 -d: )"
|
||||||
|
gpio_port="$( echo $RAIN_GPIO | $CUT -f 3 -d: )"
|
||||||
|
|
||||||
|
# check if no other rain monitor process running...
|
||||||
|
if [[ -f "$RAINSENSORQTY_MONPID" ]] ; then
|
||||||
|
pid="$( < "$RAINSENSORQTY_MONPID" )"
|
||||||
|
if ps -fp $pid >/dev/null ; then
|
||||||
|
drv_rainsensorqty_writelog $f "ERROR monitor process already running\n$( ps -fp $pid )"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $$ > $RAINSENSORQTY_MONPID
|
||||||
|
drv_rainsensorqty_writelog $f "NORMAL - $$ pid monitor process started - see $RAINSENSORQTY_MONPID"
|
||||||
|
|
||||||
|
# init variables
|
||||||
|
MMEACH="$RAINSENSORQTY_MMEACH"
|
||||||
|
(( counter=0 ))
|
||||||
|
rain_history
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
en_echo "---- NEW RUN ----"
|
||||||
|
en_echo "WAITING FOR $RAINSENSORQTY_PULSE PULSE"
|
||||||
|
|
||||||
|
# loop forever
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
before=`date +%s`
|
||||||
|
sleep $RAINSENSOR_DEBOUNCE
|
||||||
|
$GPIO -g wfi $gpio_port $RAINSENSORQTY_PULSE
|
||||||
|
now=`date +%s`
|
||||||
|
(( elapsed = now - before ))
|
||||||
|
if (( elapsed >= RAINSENSORQTY_SECSBETWEENRAINEVENT )) ; then
|
||||||
|
(( 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" &
|
||||||
|
en_echo "---- NEW CYCLE ----"
|
||||||
|
rain_history &
|
||||||
|
fi
|
||||||
|
(( counter+=1 ))
|
||||||
|
echo "$now:$counter" >> ${RAINSENSORQTY_HISTORYRAW} &
|
||||||
|
MMWATER=$( $JQ -n "$counter*$MMEACH" )
|
||||||
|
en_echo $( printf "%s PULSE #%d RECEIVED (%.2f mm)" $RAINSENSORQTY_PULSE $counter $MMWATER )
|
||||||
|
text=$(printf "%.2f mm height (#%d pulse)" $MMWATER $counter )
|
||||||
|
if (( counter >= RAINSENSORQTY_LOOPSFORSETRAINING )) ; then
|
||||||
|
drv_rainsensorqty_writelog $f "RAINING - $text" &
|
||||||
|
echo "$now:$counter" > ${RAINSENSORQTY_LASTRAIN}
|
||||||
|
else
|
||||||
|
drv_rainsensorqty_writelog $f "now is $text" &
|
||||||
|
fi
|
||||||
|
done
|
||||||
37
drv/rainsensorqty/init.include.sh
Normal file
37
drv/rainsensorqty/init.include.sh
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume
|
||||||
|
# Author: androtto
|
||||||
|
# file "init.include.sh"
|
||||||
|
# Inizializza il driver, viene richiamata nella funzione init di piGarden
|
||||||
|
# Version: 0.2.0
|
||||||
|
# Data: 11/Aug/2019
|
||||||
|
|
||||||
|
function drv_rainsensorqty_init {
|
||||||
|
local f="drv_rainsensorqty_init"
|
||||||
|
|
||||||
|
# format RAIN_GPIO="drv:rainsensorqty:25"
|
||||||
|
|
||||||
|
drv_rainsensorqty_writelog $f "NORMAL: executing $monitor_sh"
|
||||||
|
|
||||||
|
# esegue rainmonitor
|
||||||
|
if [ -x "$monitor_sh" ] ; then
|
||||||
|
nohup "$monitor_sh" >> $RAINSENSORQTY_MONITORLOG 2>&1 &
|
||||||
|
sleep 1
|
||||||
|
drv_rainsensorqty_writelog $f "NORMAL: $monitor_sh has pid $( < $RAINSENSORQTY_MONPID)"
|
||||||
|
else
|
||||||
|
drv_rainsensorqty_writelog $f "ERROR: cannot find \"\$monitor_sh \" "
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! config_check ; then
|
||||||
|
echo "ERROR in config_check function"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
: #echo "config_check ok"
|
||||||
|
fi
|
||||||
|
|
||||||
|
check_TMPDIR
|
||||||
|
|
||||||
|
RAINSENSORQTY_VAR=$TMPDIR/.rainsensorqty_var
|
||||||
|
|
||||||
|
set | $GREP -e ^GPIO -e ^LOG -e ^CUT -e ^JQ -e ^RAIN -e ^SCR -e ^TMP > $RAINSENSORQTY_VAR
|
||||||
104
drv/rainsensorqty/rainsensor.include.sh
Normal file
104
drv/rainsensorqty/rainsensor.include.sh
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
#
|
||||||
|
# Driver rainsensorqty - driver for measure the rain volume, for rain meter, for rain gauge
|
||||||
|
# Author: androtto
|
||||||
|
# file "rainsensor.include.sh"
|
||||||
|
# functions called by piGarden.sh
|
||||||
|
# Version: 0.1.2
|
||||||
|
# Data: 19/Mar/2019
|
||||||
|
# fixed output drv_rainsensorqty_rain_sensor_get
|
||||||
|
|
||||||
|
#
|
||||||
|
# Inizializza il sensore di rilevamento pioggia
|
||||||
|
#
|
||||||
|
# $1 identificativo gpio del sensore di pioggia
|
||||||
|
#
|
||||||
|
drv_rainsensorqty_rain_sensor_init()
|
||||||
|
{
|
||||||
|
local f=drv_rainsensorqty_rain_sensor_init
|
||||||
|
drv_rainsensorqty_writelog "launched: $f" $1
|
||||||
|
|
||||||
|
local drvt="$( echo $RAIN_GPIO | $CUT -f 1 -d: )"
|
||||||
|
local drv="$( echo $RAIN_GPIO | $CUT -f 2 -d: )"
|
||||||
|
local gpio_port="$( echo $RAIN_GPIO | $CUT -f 3 -d: )"
|
||||||
|
|
||||||
|
if $GPIO -g mode $gpio_port in ; then
|
||||||
|
drv_rainsensorqty_writelog $f "NORMAL: '$GPIO -g mode $gpio_port in' set correctly"
|
||||||
|
else
|
||||||
|
drv_rainsensorqty_writelog $f "ERROR: '$GPIO -g mode $gpio_port in' has an error"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $GPIO_RESISTOR in
|
||||||
|
pull-up) gpio_arg=up
|
||||||
|
message="NORMAL: '$GPIO -g mode $gpio_port up' set internal pull-up resistor"
|
||||||
|
;;
|
||||||
|
pull-down) gpio_arg=down
|
||||||
|
message="NORMAL: '$GPIO -g mode $gpio_port down' set internal pull-down resistor"
|
||||||
|
;;
|
||||||
|
none) gpio_arg=tri
|
||||||
|
message="NORMAL: '$GPIO -g mode $gpio_port tri' set none to internal resistor"
|
||||||
|
;;
|
||||||
|
*) echo "ERROR: GPIO_RESISTOR not set correctly - values are \"pull-up|pull-down|none\" "
|
||||||
|
drv_rainsensorqty_writelog "drv_rainsensorqty_rain_sensor_init" "ERROR: GPIO_RESISTOR not set correctly - values are \"pull-up|pull-down|none\" "
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
if $GPIO -g mode $gpio_port $gpio_arg ; then
|
||||||
|
drv_rainsensorqty_writelog $f "$message"
|
||||||
|
else
|
||||||
|
drv_rainsensorqty_writelog $f "ERROR: '$GPIO -g mode $gpio_port $gpio_arg' command"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Ritorna in output lo stato del sensore di rilevamento pioggia
|
||||||
|
#
|
||||||
|
# $1 identificativo gpio del sensore di pioggia
|
||||||
|
#
|
||||||
|
# restituisce 0 se piove, e nell'output di testo il valore di "$RAIN_GPIO_STATE"
|
||||||
|
# restituisce 99 se non piove, output "norain"
|
||||||
|
# esce con 1 se non c'e' il monitoring, output "ERROR"
|
||||||
|
drv_rainsensorqty_rain_sensor_get()
|
||||||
|
{
|
||||||
|
local now=$(date +%s)
|
||||||
|
local interval=60 # because check_rain_sensor is scheduled once a minute ... to changed if schedule is modified, from crontab:
|
||||||
|
#* * * * * /home/pi/piGarden/piGarden.sh check_rain_sensor 2> /tmp/check_rain_sensor.err
|
||||||
|
|
||||||
|
local f="drv_rainsensorqty_check"
|
||||||
|
|
||||||
|
# script called with:
|
||||||
|
#drv_rainsensorqty_writelog $f $1
|
||||||
|
# ignora il parametro di $1, lo recupera dal file di configurazione
|
||||||
|
|
||||||
|
# verifica se lo script di monitoring e' attivo
|
||||||
|
if drv_rainsensorqty_check ; then
|
||||||
|
drv_rainsensorqty_writelog $f "NORMAL - drv_rainsensorqty_check ok, monitor process running"
|
||||||
|
if [ -f "$RAINSENSORQTY_LASTRAIN" ] ; then
|
||||||
|
local lastrain="$( cat "$RAINSENSORQTY_LASTRAIN" | $CUT -f 1 -d: )"
|
||||||
|
local counter="$( cat "$RAINSENSORQTY_LASTRAIN" | $CUT -f 2 -d: )"
|
||||||
|
LEVEL=$( $JQ -n "$counter/$RAINSENSORQTY_LOOPSFORSETRAINING" | $JQ 'floor' )
|
||||||
|
(( diff = now - lastrain ))
|
||||||
|
drv_rainsensorqty_writelog $f "NORMAL: last rain $( date --date="@$lastrain" ) - LEVEL $LEVEL rain"
|
||||||
|
drv_rainsensorqty_writelog $f "NORMAL: check rain $( date --date="@$now" ) "
|
||||||
|
if (( diff <= interval )) ; then
|
||||||
|
drv_rainsensorqty_writelog $f "RAIN - return \$RAIN_GPIO_STATE = $RAIN_GPIO_STATE as output"
|
||||||
|
drv_rainsensorqty_writelog $f "DEBUG : check rain - diff $diff < $interval - return $RAIN_GPIO_STATE"
|
||||||
|
msg="$RAIN_GPIO_STATE"
|
||||||
|
echo $msg
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
drv_rainsensorqty_writelog $f "NO_RAIN - return \"norain\" as output"
|
||||||
|
drv_rainsensorqty_writelog $f "DEBUG : check rain - diff $diff < $interval - return 99"
|
||||||
|
msg="norain"
|
||||||
|
echo $msg
|
||||||
|
return 99
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
drv_rainsensorqty_writelog $f "ERROR: drv_rainsensorqty_check failed, no monitor process running ($monitor_sh)"
|
||||||
|
msg="ERROR"
|
||||||
|
echo $msg
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
14
drv/remote/README.md
Normal file
14
drv/remote/README.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Driver for controlling remote pigarden on the network from a pigarden master installation
|
||||||
|
|
||||||
|
For more information see https://www.lejubila.net/2018/03/pigardent-0-5-5-driver-master-per-implementare-un-architettura-master-slave/
|
||||||
|
|
||||||
|
# Example of zone configuration in piGarden.conf
|
||||||
|
```bash
|
||||||
|
EV1_ALIAS="Giarino_Posteriore_DX" #
|
||||||
|
EV1_GPIO="drv:remote:PIREMOTE1:Giardino_Posteriore_DX"
|
||||||
|
|
||||||
|
PIREMOTE1_IP="192.168.1.51"
|
||||||
|
PIREMOTE1_PORT="8084"
|
||||||
|
PIREMOTE1_USER=""
|
||||||
|
PIREMOTE1_PWD=""
|
||||||
|
```
|
||||||
38
drv/remote/common.include.sh
Normal file
38
drv/remote/common.include.sh
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#
|
||||||
|
# Funzioni comuni utilizzate dal driver
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Esegue un comando su un pigarden remoto tramite socket
|
||||||
|
#
|
||||||
|
# $1 identificativo pigarden remoto
|
||||||
|
# $2 comando da eseguire
|
||||||
|
#
|
||||||
|
function drv_remote_command {
|
||||||
|
|
||||||
|
local remote="$1"
|
||||||
|
local command="$2"
|
||||||
|
|
||||||
|
local remote_ip_var=$remote"_IP"
|
||||||
|
local remote_port_var=$remote"_PORT"
|
||||||
|
local remote_user_var=$remote"_USER"
|
||||||
|
local remote_pwd_var=$remote"_PWD"
|
||||||
|
|
||||||
|
local remote_ip="${!remote_ip_var}"
|
||||||
|
local remote_port="${!remote_port_var}"
|
||||||
|
local remote_user="${!remote_user_var}"
|
||||||
|
local remote_pwd="${!remote_pwd_var}"
|
||||||
|
|
||||||
|
exec 5<>/dev/tcp/$remote_ip/$remote_port
|
||||||
|
|
||||||
|
if [[ ! -z $remote_user ]] && [[ ! -z $remote_pwd ]]; then
|
||||||
|
command="$remote_user\n$remote_pwd\n$command"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "$command" >&5
|
||||||
|
|
||||||
|
cat <&5
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
7
drv/remote/config.include.sh
Normal file
7
drv/remote/config.include.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#
|
||||||
|
# File di configurazione del driver
|
||||||
|
#
|
||||||
|
|
||||||
|
# Dichiarazione variabile di esempio
|
||||||
|
#declare -g SAMPLE_FOO
|
||||||
|
#SAMPLE_FOO="bar"
|
||||||
9
drv/remote/init.include.sh
Normal file
9
drv/remote/init.include.sh
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#
|
||||||
|
# Questa funzione viene inviocata dalla funzione "init" di piGarden se sono presenti elettrovalvole o sensori che utilizzano questo driver
|
||||||
|
#
|
||||||
|
function drv_remote_init {
|
||||||
|
|
||||||
|
local FOO=bar
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
23
drv/remote/rainsensor.include.sh
Normal file
23
drv/remote/rainsensor.include.sh
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#
|
||||||
|
# Inizializza il sensore di rilevamento pioggia
|
||||||
|
#
|
||||||
|
# $i identificativo gpio del sensore di pioggia
|
||||||
|
#
|
||||||
|
function drv_remote_rain_sensor_init {
|
||||||
|
|
||||||
|
local FOO="bar"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Ritorna lo stato del sensore di rilevamento pioggia
|
||||||
|
#
|
||||||
|
# $i identificativo gpio del sensore di pioggia
|
||||||
|
#
|
||||||
|
function drv_remote_rain_sensor_get {
|
||||||
|
|
||||||
|
local FOO="bar"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
76
drv/remote/rele.include.sh
Normal file
76
drv/remote/rele.include.sh
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#
|
||||||
|
# Inizializzazione rele
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da inizializzare
|
||||||
|
#
|
||||||
|
function drv_remote_rele_init {
|
||||||
|
|
||||||
|
drv_remote_rele_open "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Apertura rele
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da aprire (chiude l'elettrovalvola)
|
||||||
|
#
|
||||||
|
function drv_remote_rele_open {
|
||||||
|
|
||||||
|
local remote=`echo $1 | $CUT -d':' -f3,3`
|
||||||
|
local remote_alias=`echo $1 | $CUT -d':' -f4,4`
|
||||||
|
|
||||||
|
local command="close $remote_alias"
|
||||||
|
|
||||||
|
echo "remote=$remote"
|
||||||
|
echo "remote_alias=$remote_alias"
|
||||||
|
echo "command=$command"
|
||||||
|
|
||||||
|
local response=$(drv_remote_command "$remote" "$command")
|
||||||
|
|
||||||
|
echo "response=$response"
|
||||||
|
|
||||||
|
local result=$(echo $response|$JQ -M ".error.description")
|
||||||
|
echo "result=$result"
|
||||||
|
if [[ "$result" != "\"\"" ]]; then
|
||||||
|
local error=$result
|
||||||
|
error="${error%\"}"
|
||||||
|
error="${error#\"}"
|
||||||
|
echo "error=$error"
|
||||||
|
log_write "drv_remote" "error" "Remote rele open error: $error"
|
||||||
|
message_write "warning" "Remote rele open error: $error"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Chiusura rele
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da chiudere (apre l'elettrovalvola)
|
||||||
|
#
|
||||||
|
function drv_remote_rele_close {
|
||||||
|
|
||||||
|
local remote=`echo $1 | $CUT -d':' -f3,3`
|
||||||
|
local remote_alias=`echo $1 | $CUT -d':' -f4,4`
|
||||||
|
|
||||||
|
local command="open $remote_alias force"
|
||||||
|
|
||||||
|
echo "remote=$remote"
|
||||||
|
echo "remote_alias=$remote_alias"
|
||||||
|
echo "command=$command"
|
||||||
|
|
||||||
|
local response=$(drv_remote_command "$remote" "$command")
|
||||||
|
|
||||||
|
echo "response=$response"
|
||||||
|
|
||||||
|
local result=`echo $response|$JQ -M ".error.description"`
|
||||||
|
echo "result=$result"
|
||||||
|
if [[ "$result" != "\"\"" ]]; then
|
||||||
|
local error=$result
|
||||||
|
error="${error%\"}"
|
||||||
|
error="${error#\"}"
|
||||||
|
echo "error=$error"
|
||||||
|
log_write "drv_remoter" "error" "Remote rele close error: $error"
|
||||||
|
message_write "warning" "Remote rele close error: $error"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
27
drv/remote/setup.include.sh
Normal file
27
drv/remote/setup.include.sh
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#
|
||||||
|
# Questa funzione viene invocata dalla funzione "setup_drv" di piGarden ad ogni avvio dello script
|
||||||
|
# e serve per eseguire l'eventuale setup del driver se necessario
|
||||||
|
#
|
||||||
|
function drv_remote_setup {
|
||||||
|
|
||||||
|
local all_remote=0
|
||||||
|
|
||||||
|
# Imposta le zone come remote
|
||||||
|
for i in $(seq $EV_TOTAL)
|
||||||
|
do
|
||||||
|
local a=EV"$i"_GPIO
|
||||||
|
local gpio="${!a}"
|
||||||
|
if [[ "$gpio" == drv:remote:* ]]; then
|
||||||
|
local varname=EV"$i"_REMOTE
|
||||||
|
declare -g $varname=1
|
||||||
|
all_remote=$((all_remote+1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Se tutte le zone sono remote disabilita la gestione dell'alimentazione bistabile
|
||||||
|
if [ $all_remote -eq $EV_TOTAL ]; then
|
||||||
|
EV_MONOSTABLE=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
34
drv/remote/supply.include.sh
Normal file
34
drv/remote/supply.include.sh
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#
|
||||||
|
# Inizializza i rele che gestiscono l'alimentazione per le valvole bistabili
|
||||||
|
#
|
||||||
|
# $1 identificativo relè
|
||||||
|
#
|
||||||
|
function drv_remote_supply_bistable_init {
|
||||||
|
|
||||||
|
local FOO="bar"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta l'alimentazione delle elettrovalvole con voltaggio positivo
|
||||||
|
#
|
||||||
|
# $1 identificativo relè
|
||||||
|
#
|
||||||
|
function drv_remote_supply_positive {
|
||||||
|
|
||||||
|
local FOO="bar"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta l'alimentazione delle elettrovalvole con voltaggio negativo
|
||||||
|
#
|
||||||
|
# $1 identificativo relè
|
||||||
|
#
|
||||||
|
function drv_remote_supply_negative {
|
||||||
|
|
||||||
|
local FOO="bar"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#
|
#
|
||||||
# Funzione di esempio
|
# Funzione di esempio
|
||||||
#
|
#
|
||||||
function sample_foo {
|
function drv_sample_foo {
|
||||||
|
|
||||||
echo "bar"
|
echo "bar"
|
||||||
|
|
||||||
|
|||||||
13
drv/sample/rainonline.include.sh
Normal file
13
drv/sample/rainonline.include.sh
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#
|
||||||
|
# Ritorna lo stato delle condizioni meteo interrogando il servizio online
|
||||||
|
#
|
||||||
|
# return output: 0 - errore durante il recupero delle condizioni meteo
|
||||||
|
# >0 - rilevato pioggia, timestamp del rilevamento
|
||||||
|
# <0 - rilevato nessuna pioggia, timestamp del rilevamento
|
||||||
|
function drv_sample_rain_online_get {
|
||||||
|
|
||||||
|
local FOO="bar"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Questa funzione viene invocata dalla funzione "setup_drv" di piGarden ad ogni avvio dello script
|
# Questa funzione viene invocata dalla funzione "setup_drv" di piGarden ad ogni avvio dello script
|
||||||
# e serve per eseguire l'evenutale setup del driver se necessario
|
# e serve per eseguire l'eventuale setup del driver se necessario
|
||||||
#
|
#
|
||||||
function drv_sample_setup {
|
function drv_sample_setup {
|
||||||
|
|
||||||
|
|||||||
22
drv/sonoff_tasmota_http/README.md
Normal file
22
drv/sonoff_tasmota_http/README.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Driver for controlling Sonoff remote relays with Tasmota firmware via http protocol
|
||||||
|
|
||||||
|
More information on Sonoff Tasmota firmware: https://github.com/arendst/Sonoff-Tasmota
|
||||||
|
|
||||||
|
|
||||||
|
# Example of zone configuration in piGarden.conf
|
||||||
|
|
||||||
|
```bash
|
||||||
|
EV1_ALIAS="Giardino_Posteriore_DX"
|
||||||
|
EV1_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power1"
|
||||||
|
EV1_MONOSTABLE=1
|
||||||
|
|
||||||
|
EV2_ALIAS="Giardino_Posteriore_CN"
|
||||||
|
EV2_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power2"
|
||||||
|
EV2_MONOSTABLE=1
|
||||||
|
|
||||||
|
SONOFF1_IP="192.168.1.1"
|
||||||
|
SONOFF1_USER="user"
|
||||||
|
SONOFF1_PWD="pwd"
|
||||||
|
```
|
||||||
|
More information for configuration: https://www.lejubila.net/2018/06/pigarden-0-5-7-gestisci-le-tue-elettrovalvole-con-i-moduli-sonoff-grazie-al-nuovo-driver-sonoff_tasmota_http
|
||||||
|
|
||||||
50
drv/sonoff_tasmota_http/common.include.sh
Normal file
50
drv/sonoff_tasmota_http/common.include.sh
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#
|
||||||
|
# Funzioni comuni utilizzate dal driver
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Invia un comando al modulo sonoff tramite http
|
||||||
|
#
|
||||||
|
# $1 identificativo modulo sonoff
|
||||||
|
# $2 comando da eseguire
|
||||||
|
#
|
||||||
|
function drv_sonoff_tasmota_http_command {
|
||||||
|
|
||||||
|
local remote="$1"
|
||||||
|
local command="$2"
|
||||||
|
|
||||||
|
local remote_ip_var=$remote"_IP"
|
||||||
|
local remote_user_var=$remote"_USER"
|
||||||
|
local remote_pwd_var=$remote"_PWD"
|
||||||
|
|
||||||
|
local remote_ip="${!remote_ip_var}"
|
||||||
|
local remote_user="${!remote_user_var}"
|
||||||
|
local remote_pwd="${!remote_pwd_var}"
|
||||||
|
|
||||||
|
local url="http://$remote_ip/cm"
|
||||||
|
local credentials=""
|
||||||
|
local response=""
|
||||||
|
|
||||||
|
if [[ ! -z $remote_user ]] && [[ ! -z $remote_pwd ]]; then
|
||||||
|
credentials="user=$remote_user&password=$remote_pwd&"
|
||||||
|
fi
|
||||||
|
|
||||||
|
url="$url?$credentials$command"
|
||||||
|
|
||||||
|
echo "url api sonoff: $url" >> "$LOG_OUTPUT_DRV_FILE"
|
||||||
|
|
||||||
|
$CURL --connect-timeout 5 -sb -H "$url"
|
||||||
|
|
||||||
|
local res=$?
|
||||||
|
|
||||||
|
echo "curl code response: $res" >> "$LOG_OUTPUT_DRV_FILE"
|
||||||
|
|
||||||
|
if [ "$res" != "0" ]; then
|
||||||
|
echo "The curl command failed with: $res - url: $url"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#echo "{\"POWER1\":\"ON\"}"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
7
drv/sonoff_tasmota_http/config.include.sh
Normal file
7
drv/sonoff_tasmota_http/config.include.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#
|
||||||
|
# File di configurazione del driver
|
||||||
|
#
|
||||||
|
|
||||||
|
# Dichiarazione variabile di esempio
|
||||||
|
#declare -g SAMPLE_FOO
|
||||||
|
#SAMPLE_FOO="bar"
|
||||||
9
drv/sonoff_tasmota_http/init.include.sh
Normal file
9
drv/sonoff_tasmota_http/init.include.sh
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#
|
||||||
|
# Questa funzione viene inviocata dalla funzione "init" di piGarden se sono presenti elettrovalvole o sensori che utilizzano questo driver
|
||||||
|
#
|
||||||
|
function drv_sonoff_tasmota_http_init {
|
||||||
|
|
||||||
|
local FOO=bar
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
23
drv/sonoff_tasmota_http/rainsensor.include.sh
Normal file
23
drv/sonoff_tasmota_http/rainsensor.include.sh
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#
|
||||||
|
# Inizializza il sensore di rilevamento pioggia
|
||||||
|
#
|
||||||
|
# $i identificativo gpio del sensore di pioggia
|
||||||
|
#
|
||||||
|
function drv_sonoff_tasmota_http_rain_sensor_init {
|
||||||
|
|
||||||
|
local FOO="bar"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Ritorna lo stato del sensore di rilevamento pioggia
|
||||||
|
#
|
||||||
|
# $i identificativo gpio del sensore di pioggia
|
||||||
|
#
|
||||||
|
function drv_sonoff_tasmota_http_rain_sensor_get {
|
||||||
|
|
||||||
|
local FOO="bar"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
78
drv/sonoff_tasmota_http/rele.include.sh
Normal file
78
drv/sonoff_tasmota_http/rele.include.sh
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
#
|
||||||
|
# Inizializzazione rele
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da inizializzare
|
||||||
|
#
|
||||||
|
function drv_sonoff_tasmota_http_rele_init {
|
||||||
|
drv_sonoff_tasmota_http_rele_open "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Apertura rele
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da aprire (chiude l'elettrovalvola)
|
||||||
|
#
|
||||||
|
function drv_sonoff_tasmota_http_rele_open {
|
||||||
|
|
||||||
|
local remote=`echo $1 | $CUT -d':' -f3,3`
|
||||||
|
local remote_alias=`echo $1 | $CUT -d':' -f4,4`
|
||||||
|
|
||||||
|
local command="cmnd=$remote_alias%20Off"
|
||||||
|
|
||||||
|
echo "remote=$remote"
|
||||||
|
echo "remote_alias=$remote_alias"
|
||||||
|
echo "command=$command"
|
||||||
|
|
||||||
|
local response=$(drv_sonoff_tasmota_http_command "$remote" "$command")
|
||||||
|
|
||||||
|
echo "response=$response"
|
||||||
|
local jskey=${remote_alias^^}
|
||||||
|
|
||||||
|
local result=$(echo $response|$JQ -M ".$jskey")
|
||||||
|
echo "result=$result"
|
||||||
|
if [[ "$result" != "\"OFF\"" ]]; then
|
||||||
|
local error="Command error: $response"
|
||||||
|
error="${error%\"}"
|
||||||
|
error="${error#\"}"
|
||||||
|
echo "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
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Chiusura rele
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da chiudere (apre l'elettrovalvola)
|
||||||
|
#
|
||||||
|
function drv_sonoff_tasmota_http_rele_close {
|
||||||
|
|
||||||
|
local remote=`echo $1 | $CUT -d':' -f3,3`
|
||||||
|
local remote_alias=`echo $1 | $CUT -d':' -f4,4`
|
||||||
|
|
||||||
|
local command="cmnd=$remote_alias%20On"
|
||||||
|
|
||||||
|
echo "remote=$remote"
|
||||||
|
echo "remote_alias=$remote_alias"
|
||||||
|
echo "command=$command"
|
||||||
|
|
||||||
|
local response=$(drv_sonoff_tasmota_http_command "$remote" "$command")
|
||||||
|
|
||||||
|
echo "response=$response"
|
||||||
|
local jskey=${remote_alias^^}
|
||||||
|
|
||||||
|
local result=$(echo $response|$JQ -M ".$jskey")
|
||||||
|
echo "result=$result"
|
||||||
|
if [[ "$result" != "\"ON\"" ]]; then
|
||||||
|
local error="Command error: $response"
|
||||||
|
error="${error%\"}"
|
||||||
|
error="${error#\"}"
|
||||||
|
echo "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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
10
drv/sonoff_tasmota_http/setup.include.sh
Normal file
10
drv/sonoff_tasmota_http/setup.include.sh
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#
|
||||||
|
# Questa funzione viene invocata dalla funzione "setup_drv" di piGarden ad ogni avvio dello script
|
||||||
|
# e serve per eseguire l'eventuale setup del driver se necessario
|
||||||
|
#
|
||||||
|
function drv_sonoff_tasmota_http_setup {
|
||||||
|
|
||||||
|
local FOO="bar"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
34
drv/sonoff_tasmota_http/supply.include.sh
Normal file
34
drv/sonoff_tasmota_http/supply.include.sh
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#
|
||||||
|
# Inizializza i rele che gestiscono l'alimentazione per le valvole bistabili
|
||||||
|
#
|
||||||
|
# $1 identificativo relè
|
||||||
|
#
|
||||||
|
function drv_sonoff_tasmota_http_supply_bistable_init {
|
||||||
|
|
||||||
|
drv_sonoff_tasmota_http_supply_negative "$1"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta l'alimentazione delle elettrovalvole con voltaggio positivo
|
||||||
|
#
|
||||||
|
# $1 identificativo relè
|
||||||
|
#
|
||||||
|
function drv_sonoff_tasmota_http_supply_positive {
|
||||||
|
|
||||||
|
drv_sonoff_tasmota_http_rele_open "$1"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta l'alimentazione delle elettrovalvole con voltaggio negativo
|
||||||
|
#
|
||||||
|
# $1 identificativo relè
|
||||||
|
#
|
||||||
|
function drv_sonoff_tasmota_http_supply_negative {
|
||||||
|
|
||||||
|
drv_sonoff_tasmota_http_rele_close "$1"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ function drv_spb16ch_boards_id_load {
|
|||||||
SPB16CH_USED_ID+=("$board_id")
|
SPB16CH_USED_ID+=("$board_id")
|
||||||
done
|
done
|
||||||
else
|
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
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function drv_spb16ch_rele_open {
|
|||||||
local rele_data=${SPB16CH_RELE_MAP[$rele_id]}
|
local rele_data=${SPB16CH_RELE_MAP[$rele_id]}
|
||||||
if [[ -z $rele_data ]]; then
|
if [[ -z $rele_data ]]; then
|
||||||
local message="Error - Rele map not defined - rele_id=$rele_id - ($1)"
|
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"
|
message_write "warning" "$message"
|
||||||
fi
|
fi
|
||||||
local address_num=${rele_data:0:2}
|
local address_num=${rele_data:0:2}
|
||||||
@@ -52,7 +52,7 @@ function drv_spb16ch_rele_close {
|
|||||||
local rele_data=${SPB16CH_RELE_MAP[$rele_id]}
|
local rele_data=${SPB16CH_RELE_MAP[$rele_id]}
|
||||||
if [[ -z $rele_data ]]; then
|
if [[ -z $rele_data ]]; then
|
||||||
local message="Error - Rele map not defined - rele_id=$rele_id - ($1)"
|
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"
|
message_write "warning" "$message"
|
||||||
fi
|
fi
|
||||||
local address_num=${rele_data:0:2}
|
local address_num=${rele_data:0:2}
|
||||||
|
|||||||
12
drv/wunderground/README.md
Normal file
12
drv/wunderground/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Driver for check wather condition with wunderground online service
|
||||||
|
|
||||||
|
# Example of configuration in piGarden.conf
|
||||||
|
|
||||||
|
```bash
|
||||||
|
WEATHER_SERVICE="wunderground"
|
||||||
|
|
||||||
|
WUNDERGROUND_KEY="" # Set with your api key of wunderground
|
||||||
|
WUNDERGROUND_LOCATION="IY/Monsummano" # Set with your location indentify, see http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
12
drv/wunderground/common.include.sh
Normal file
12
drv/wunderground/common.include.sh
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#
|
||||||
|
# Funzioni comuni utilizzate dal driver
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Funzione di esempio
|
||||||
|
#
|
||||||
|
function sample_foo {
|
||||||
|
|
||||||
|
echo "bar"
|
||||||
|
|
||||||
|
}
|
||||||
36
drv/wunderground/rainonline.include.sh
Normal file
36
drv/wunderground/rainonline.include.sh
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#
|
||||||
|
# Ritorna lo stato delle condizioni meteo interrogando il servizio online
|
||||||
|
#
|
||||||
|
# $i identificativo gpio del sensore di pioggia
|
||||||
|
#
|
||||||
|
# return output: 0 - errore durante il recupero delle condizioni meteo
|
||||||
|
# >0 - rilevato pioggia, timestamp del rilevamento
|
||||||
|
# <0 - rilevato nessuna pioggia, timestamp del rilevamento
|
||||||
|
function drv_wunderground_rain_online_get {
|
||||||
|
|
||||||
|
# http://www.wunderground.com/weather/api/d/docs?d=resources/phrase-glossary&MR=1
|
||||||
|
$CURL http://api.wunderground.com/api/$WUNDERGROUND_KEY/conditions/q/$WUNDERGROUND_LOCATION.json > $TMP_PATH/check_rain_online.json
|
||||||
|
local weather=`cat $TMP_PATH/check_rain_online.json | $JQ -M ".current_observation.weather"`
|
||||||
|
local current_observation=`cat $TMP_PATH/check_rain_online.json | $JQ -M ".current_observation"`
|
||||||
|
local local_epoch=`cat $TMP_PATH/check_rain_online.json | $JQ -M -r ".current_observation.local_epoch"`
|
||||||
|
|
||||||
|
if [ "$weather" = "null" ]; then
|
||||||
|
echo "0"
|
||||||
|
else
|
||||||
|
if [[ "$weather" == *"Rain"* ]] ||
|
||||||
|
[[ "$weather" == *"Snow"* ]] ||
|
||||||
|
[[ "$weather" == *"Hail"* ]] ||
|
||||||
|
[[ "$weather" == *"Ice"* ]] ||
|
||||||
|
[[ "$weather" == *"Thunderstorm"* ]] ||
|
||||||
|
[[ "$weather" == *"Drizzle"* ]];
|
||||||
|
then
|
||||||
|
echo $local_epoch
|
||||||
|
else
|
||||||
|
echo "-$local_epoch"
|
||||||
|
fi
|
||||||
|
echo "$current_observation" > "$STATUS_DIR/last_weather_online"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
4
events/cron_add_after/.gitignore
vendored
Normal file
4
events/cron_add_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/cron_add_before/.gitignore
vendored
Normal file
4
events/cron_add_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/cron_del_after/.gitignore
vendored
Normal file
4
events/cron_del_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/cron_del_before/.gitignore
vendored
Normal file
4
events/cron_del_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/ev_not_open_for_rain/.gitignore
vendored
Normal file
4
events/ev_not_open_for_rain/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/ev_not_open_for_rain_online/.gitignore
vendored
Normal file
4
events/ev_not_open_for_rain_online/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/ev_not_open_for_rain_sensor/.gitignore
vendored
Normal file
4
events/ev_not_open_for_rain_sensor/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/ev_open_in_after/.gitignore
vendored
Normal file
4
events/ev_open_in_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/ev_open_in_before/.gitignore
vendored
Normal file
4
events/ev_open_in_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/exec_poweroff_after/.gitignore
vendored
Normal file
4
events/exec_poweroff_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/exec_poweroff_before/.gitignore
vendored
Normal file
4
events/exec_poweroff_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/exec_reboot_after/.gitignore
vendored
Normal file
4
events/exec_reboot_after/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
4
events/exec_reboot_before/.gitignore
vendored
Normal file
4
events/exec_reboot_before/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
||||||
111
events/scripts/rpinotify.sh
Executable file
111
events/scripts/rpinotify.sh
Executable file
@@ -0,0 +1,111 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Send telegram notificacion on triggered event
|
||||||
|
#
|
||||||
|
# $1 = event
|
||||||
|
# $2 = cause
|
||||||
|
# $3 = time
|
||||||
|
#
|
||||||
|
# To use this script, you must get your hash. Register for the rpinotify service. Get the hash and enter it below
|
||||||
|
#
|
||||||
|
|
||||||
|
# rpinotify token
|
||||||
|
TOKEN=""
|
||||||
|
|
||||||
|
EVENT="$1"
|
||||||
|
|
||||||
|
TO="mail@destination.com"
|
||||||
|
FROM="piGarden@your_domain.com"
|
||||||
|
SUBJECT="[piGarden notification mail] event $EVENT"
|
||||||
|
BODY=""
|
||||||
|
|
||||||
|
case "$EVENT" in
|
||||||
|
"init_before" | "init_after")
|
||||||
|
TIME=$2
|
||||||
|
BODY="PiGarden triggered new event --- EVENT: $EVENT --- TIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"ev_open_before" | "ev_open_after")
|
||||||
|
ALIAS="$2"
|
||||||
|
FORCE="$3"
|
||||||
|
TIME=$4
|
||||||
|
BODY="PiGarden triggered new event --- EVENT: $EVENT --- ZONE: $ALIAS --- FORCED IRRIGATION: $FORCE --- TIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"ev_open_in_before")
|
||||||
|
ALIAS="$2"
|
||||||
|
FORCE="$3"
|
||||||
|
MINUTE_START="$4"
|
||||||
|
MINUTE_STOP="$5"
|
||||||
|
TIME=$6
|
||||||
|
BODY="PiGarden triggered new event --- EVENT: $EVENT --- ZONE: $ALIAS --- FORCED IRRIGATION: $FORCE --- MINUTE START: $MINUTE_START --- MINUTE STOP: $MINUTE_STOP --- TIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"ev_open_in_after")
|
||||||
|
ALIAS="$2"
|
||||||
|
FORCE="$3"
|
||||||
|
CRON_START="$4"
|
||||||
|
CRON_STOP="$5"
|
||||||
|
TIME=$6
|
||||||
|
BODY="PiGarden triggered new event --- EVENT: $EVENT --- ZONE: $ALIAS --- FORCED IRRIGATION: $FORCE --- CRON START: $CRON_START --- CRON STOP: $CRON_STOP --- TIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
|
||||||
|
"ev_close_before" | "ev_close_after")
|
||||||
|
ALIAS="$2"
|
||||||
|
TIME=$3
|
||||||
|
BODY="PiGarden triggered new event --- EVENT: $EVENT --- ZONE: $ALIAS --- TIME: $(/bin/date -d@$TIME);"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"ev_not_open_for_rain" | "ev_not_open_for_rain_online" | "ev_not_open_for_rain_sensor")
|
||||||
|
ALIAS="$2"
|
||||||
|
TIME=$3
|
||||||
|
BODY="PiGarden triggered new event --- EVENT: $EVENT --- ZONE: $ALIAS --- TIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"check_rain_sensor_before" | "check_rain_sensor_after" | "check_rain_sensor_change")
|
||||||
|
STATE="$2"
|
||||||
|
TIME=$3
|
||||||
|
BODY="PiGarden triggered new event --- EVENT: $EVENT --- STATE: $STATE --- TIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"check_rain_online_before")
|
||||||
|
STATE="$2"
|
||||||
|
TIME=$3
|
||||||
|
BODY="PiGarden triggered new event --- EVENT: $EVENT --- STATE: $STATE --- TIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"check_rain_online_after" | "check_rain_online_change")
|
||||||
|
STATE="$2"
|
||||||
|
WEATHER="$3"
|
||||||
|
TIME=$4
|
||||||
|
BODY="PiGarden triggered new event --- EVENT: $EVENT --- STATE: $STATE --- WEATHER: $WEARTHER --- TIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"cron_add_before" | "cron_add_after")
|
||||||
|
CRON_TYPE="$2"
|
||||||
|
CRON_ARG="$3"
|
||||||
|
CRON_ELEMENT="$4"
|
||||||
|
TIME=$5
|
||||||
|
BODY="PiGarden triggered new event --- EVENT: $EVENT --- CRON TYPE: $CRON_TYPE --- CRON ARG: $CRON_ARG --- CRON ELEMENT: $CRON_ELEMENT\nTIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"cron_del_before" | "cron_del_after")
|
||||||
|
CRON_TYPE="$2"
|
||||||
|
CRON_ARG="$3"
|
||||||
|
TIME=$4
|
||||||
|
BODY="PiGarden triggered new event --- EVENT: $EVENT --- CRON TYPE: $CRON_TYPE --- CRON ARG: $CRON_ARG --- TIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"exec_poweroff_before" | "exec_poweroff_after" | "exec_reboot_before" | "exec_reboot_after")
|
||||||
|
TIME=$2
|
||||||
|
BODY="PiGarden triggered new event --- EVENT: $EVENT --- TIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
|
||||||
|
curl -X POST -F "text=$BODY" https://api.rpinotify.it/message/$TOKEN/
|
||||||
@@ -24,13 +24,12 @@ EVENT="$1"
|
|||||||
|
|
||||||
TO="mail@destination.com"
|
TO="mail@destination.com"
|
||||||
FROM="piGarden@your_domain.com"
|
FROM="piGarden@your_domain.com"
|
||||||
SUBJECT="piGarden notification mail: event $EVENT"
|
SUBJECT="[piGarden notification mail] event $EVENT"
|
||||||
BODY=""
|
BODY=""
|
||||||
|
|
||||||
case "$EVENT" in
|
case "$EVENT" in
|
||||||
"init_before" | "init_after")
|
"init_before" | "init_after")
|
||||||
STATE="$2"
|
TIME=$2
|
||||||
TIME=$3
|
|
||||||
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nTIME: $(/bin/date -d@$TIME)"
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nTIME: $(/bin/date -d@$TIME)"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -41,22 +40,74 @@ case "$EVENT" in
|
|||||||
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nZONE: $ALIAS\nFORCED IRRIGATION: $FORCE\nTIME: $(/bin/date -d@$TIME)"
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nZONE: $ALIAS\nFORCED IRRIGATION: $FORCE\nTIME: $(/bin/date -d@$TIME)"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
"ev_open_in_before")
|
||||||
|
ALIAS="$2"
|
||||||
|
FORCE="$3"
|
||||||
|
MINUTE_START="$4"
|
||||||
|
MINUTE_STOP="$5"
|
||||||
|
TIME=$6
|
||||||
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nZONE: $ALIAS\nFORCED IRRIGATION: $FORCE\nMINUTE START: $MINUTE_START\nMINUTE STOP: $MINUTE_STOP\nTIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"ev_open_in_after")
|
||||||
|
ALIAS="$2"
|
||||||
|
FORCE="$3"
|
||||||
|
CRON_START="$4"
|
||||||
|
CRON_STOP="$5"
|
||||||
|
TIME=$6
|
||||||
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nZONE: $ALIAS\nFORCED IRRIGATION: $FORCE\nCRON START: $CRON_START\nCRON STOP: $CRON_STOP\nTIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
|
||||||
"ev_close_before" | "ev_close_after")
|
"ev_close_before" | "ev_close_after")
|
||||||
ALIAS="$2"
|
ALIAS="$2"
|
||||||
TIME=$3
|
TIME=$3
|
||||||
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nZONE: $ALIAS\nTIME: $(/bin/date -d@$TIME)"
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nZONE: $ALIAS\nTIME: $(/bin/date -d@$TIME)"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
"ev_not_open_for_rain" | "ev_not_open_for_rain_online" | "ev_not_open_for_rain_sensor")
|
||||||
|
ALIAS="$2"
|
||||||
|
TIME=$3
|
||||||
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nZONE: $ALIAS\nTIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
"check_rain_sensor_before" | "check_rain_sensor_after" | "check_rain_sensor_change")
|
"check_rain_sensor_before" | "check_rain_sensor_after" | "check_rain_sensor_change")
|
||||||
STATE="$2"
|
STATE="$2"
|
||||||
TIME=$3
|
TIME=$3
|
||||||
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nSTATE: $ALIAS\nTIME: $(/bin/date -d@$TIME)"
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nSTATE: $STATE\nTIME: $(/bin/date -d@$TIME)"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"check_rain_online_before" | "check_rain_online_after" | "check_rain_online_change")
|
"check_rain_online_before")
|
||||||
STATE="$2"
|
STATE="$2"
|
||||||
TIME=$3
|
TIME=$3
|
||||||
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nSTATE: $ALIAS\nTIME: $(/bin/date -d@$TIME)"
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nSTATE: $STATE\nTIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"check_rain_online_after" | "check_rain_online_change")
|
||||||
|
STATE="$2"
|
||||||
|
WEATHER="$3"
|
||||||
|
TIME=$4
|
||||||
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nSTATE: $STATE\nWEATHER: $WEARTHER\nTIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"cron_add_before" | "cron_add_after")
|
||||||
|
CRON_TYPE="$2"
|
||||||
|
CRON_ARG="$3"
|
||||||
|
CRON_ELEMENT="$4"
|
||||||
|
TIME=$5
|
||||||
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nCRON TYPE: $CRON_TYPE\nCRON ARG: $CRON_ARG\nCRON ELEMENT: $CRON_ELEMENT\nTIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"cron_del_before" | "cron_del_after")
|
||||||
|
CRON_TYPE="$2"
|
||||||
|
CRON_ARG="$3"
|
||||||
|
TIME=$4
|
||||||
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nCRON TYPE: $CRON_TYPE\nCRON ARG: $CRON_ARG\nTIME: $(/bin/date -d@$TIME)"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"exec_poweroff_before" | "exec_poweroff_after" | "exec_reboot_before" | "exec_reboot_after")
|
||||||
|
TIME=$2
|
||||||
|
BODY="PiGarden triggered new event\n\nEVENT: $EVENT\nTIME: $(/bin/date -d@$TIME)"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ function cron_del {
|
|||||||
|
|
||||||
if [ -z "$CRON_TYPE" ]; then
|
if [ -z "$CRON_TYPE" ]; then
|
||||||
echo "Cron type is empty" >&2
|
echo "Cron type is empty" >&2
|
||||||
log_write "Cron type is empty"
|
log_write "cron" "error" "Cron type is empty"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -25,24 +25,24 @@ function cron_del {
|
|||||||
fi
|
fi
|
||||||
if ! [[ $START =~ $re ]] ; then
|
if ! [[ $START =~ $re ]] ; then
|
||||||
echo "Cron start don't find" >&2
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
if ! [[ $END =~ $re ]] ; then
|
if ! [[ $END =~ $re ]] ; then
|
||||||
echo "Cron end cron don't find" >&2
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
if [ "$START" -gt "$END" ]; then
|
if [ "$START" -gt "$END" ]; then
|
||||||
echo "Wrong position for start and end in cron" >&2
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
trigger_event "cron_del_before" "$1" "$2"
|
||||||
$SED "$START,${END}d" "$TMP_CRON_FILE" | $SED '$!N; /^\(.*\)\n\1$/!P; D' | $CRONTAB -
|
$SED "$START,${END}d" "$TMP_CRON_FILE" | $SED '$!N; /^\(.*\)\n\1$/!P; D' | $CRONTAB -
|
||||||
#$CRONTAB "$TMP_CRON_FILE"
|
|
||||||
rm "$TMP_CRON_FILE"
|
rm "$TMP_CRON_FILE"
|
||||||
|
trigger_event "cron_del_after" "$1" "$2"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ function cron_add {
|
|||||||
|
|
||||||
if [ -z "$CRON_TYPE" ]; then
|
if [ -z "$CRON_TYPE" ]; then
|
||||||
echo "Cron type is empty" >&2
|
echo "Cron type is empty" >&2
|
||||||
log_write "Cron type is empty"
|
log_write "cron" "error" "Cron type is empty"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -91,12 +91,12 @@ function cron_add {
|
|||||||
else
|
else
|
||||||
if ! [[ $START =~ $re ]] ; then
|
if ! [[ $START =~ $re ]] ; then
|
||||||
echo "Cron start don't find" >&2
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
if ! [[ $END =~ $re ]] ; then
|
if ! [[ $END =~ $re ]] ; then
|
||||||
echo "Cron end cron don't find" >&2
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
START=$(($START + 1))
|
START=$(($START + 1))
|
||||||
@@ -104,7 +104,7 @@ function cron_add {
|
|||||||
|
|
||||||
if [ "$START" -gt "$END" ]; then
|
if [ "$START" -gt "$END" ]; then
|
||||||
echo "Wrong position for start and end in cron" >&2
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ function cron_add {
|
|||||||
|
|
||||||
*)
|
*)
|
||||||
echo "Wrong cron type: $CRON_TYPE"
|
echo "Wrong cron type: $CRON_TYPE"
|
||||||
log_write "Wrong cron type: $CRON_TYPE"
|
log_write "cron" "error" "Wrong cron type: $CRON_TYPE"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
@@ -206,8 +206,10 @@ function cron_add {
|
|||||||
echo "$CRON_DISABLED$CRON_M $CRON_H $CRON_DOM $CRON_MON $CRON_DOW $CRON_COMMAND" >> "$TMP_CRON_FILE2"
|
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"
|
echo "# END cron $CRON_TYPE $CRON_ARG" >> "$TMP_CRON_FILE2"
|
||||||
|
|
||||||
|
trigger_event "cron_add_before" "$CRON_TYPE" "$CRON_ARG" "$CRON_DISABLED$CRON_M $CRON_H $CRON_DOM $CRON_MON $CRON_DOW $CRON_COMMAND"
|
||||||
$CRONTAB "$TMP_CRON_FILE2"
|
$CRONTAB "$TMP_CRON_FILE2"
|
||||||
rm "$TMP_CRON_FILE" "$TMP_CRON_FILE2"
|
rm "$TMP_CRON_FILE" "$TMP_CRON_FILE2"
|
||||||
|
trigger_event "cron_add_after" "$CRON_TYPE" "$CRON_ARG" "$CRON_DISABLED$CRON_M $CRON_H $CRON_DOM $CRON_MON $CRON_DOW $CRON_COMMAND"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +225,7 @@ function cron_get {
|
|||||||
|
|
||||||
if [ -z "$CRON_TYPE" ]; then
|
if [ -z "$CRON_TYPE" ]; then
|
||||||
echo "Cron type is empty" >&2
|
echo "Cron type is empty" >&2
|
||||||
log_write "Cron type is empty"
|
log_write "cron" "error" "Cron type is empty"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -239,12 +241,12 @@ function cron_get {
|
|||||||
else
|
else
|
||||||
if ! [[ $START =~ $re ]] ; then
|
if ! [[ $START =~ $re ]] ; then
|
||||||
echo "Cron start don't find" >&2
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
if ! [[ $END =~ $re ]] ; then
|
if ! [[ $END =~ $re ]] ; then
|
||||||
echo "Cron end cron don't find" >&2
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
START=$(($START + 1))
|
START=$(($START + 1))
|
||||||
@@ -252,7 +254,7 @@ function cron_get {
|
|||||||
|
|
||||||
if [ "$START" -gt "$END" ]; then
|
if [ "$START" -gt "$END" ]; then
|
||||||
echo "Wrong position for start and end in cron" >&2
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -368,7 +370,7 @@ function add_cron_open {
|
|||||||
|
|
||||||
local exists=`alias_exists $1`
|
local exists=`alias_exists $1`
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
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"
|
echo "Alias $1 not found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -385,7 +387,7 @@ function del_cron_open {
|
|||||||
|
|
||||||
local exists=`alias_exists $1`
|
local exists=`alias_exists $1`
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
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"
|
echo "Alias $1 not found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -402,7 +404,7 @@ function get_cron_open {
|
|||||||
|
|
||||||
local exists=`alias_exists $1`
|
local exists=`alias_exists $1`
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
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"
|
echo "Alias $1 not found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -419,7 +421,7 @@ function del_cron_open_in {
|
|||||||
|
|
||||||
local exists=`alias_exists $1`
|
local exists=`alias_exists $1`
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
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"
|
echo "Alias $1 not found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -437,7 +439,7 @@ function get_cron_close {
|
|||||||
|
|
||||||
local exists=`alias_exists $1`
|
local exists=`alias_exists $1`
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
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"
|
echo "Alias $1 not found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -460,7 +462,7 @@ function add_cron_close {
|
|||||||
|
|
||||||
local exists=`alias_exists $1`
|
local exists=`alias_exists $1`
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
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"
|
echo "Alias $1 not found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -477,7 +479,7 @@ function del_cron_close {
|
|||||||
|
|
||||||
local exists=`alias_exists $1`
|
local exists=`alias_exists $1`
|
||||||
if [ "check $exists" = "check FALSE" ]; then
|
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"
|
echo "Alias $1 not found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -557,7 +559,79 @@ function cron_disable_all_open_close {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Attiva tutte le schedulazioni di apertura e chiusura elettrovalvole
|
||||||
|
#
|
||||||
|
function cron_enable_all_open_close {
|
||||||
|
|
||||||
|
local a=""
|
||||||
|
local al=""
|
||||||
|
local cron=""
|
||||||
|
|
||||||
|
#
|
||||||
|
# Disabilita tutte le schedulazioni di apertura
|
||||||
|
#
|
||||||
|
for i in $(seq $EV_TOTAL)
|
||||||
|
do
|
||||||
|
a=EV"$i"_ALIAS
|
||||||
|
al=${!a}
|
||||||
|
local crons=`get_cron_open $al`
|
||||||
|
if [[ ! -z "$crons" ]]; then
|
||||||
|
del_cron_open $al
|
||||||
|
IFS=$'\n' # make newlines the only separator
|
||||||
|
for cron in $crons
|
||||||
|
do
|
||||||
|
#echo "-- $cron --"
|
||||||
|
CRON_M=`echo $cron | $CUT -d' ' -f1,1`
|
||||||
|
CRON_H=`echo $cron | $CUT -d' ' -f2,2`
|
||||||
|
CRON_DOM=`echo $cron | $CUT -d' ' -f3,3`
|
||||||
|
CRON_MON=`echo $cron | $CUT -d' ' -f4,4`
|
||||||
|
CRON_DOW=`echo $cron | $CUT -d' ' -f5,5`
|
||||||
|
|
||||||
|
if [[ ${CRON_M:0:1} == "#" ]]; then
|
||||||
|
CRON_M=${CRON_M:1:${#CRON_M}}
|
||||||
|
fi
|
||||||
|
#echo "++ $CRON_M $CRON_H $CRON_DOM $CRON_MON $CRON_DOW ++"
|
||||||
|
|
||||||
|
add_cron_open $al "$CRON_M" "$CRON_H" "$CRON_DOM" "$CRON_MON" "$CRON_DOW"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Disabilita tutte le schedulazioni di chiusura
|
||||||
|
#
|
||||||
|
for i in $(seq $EV_TOTAL)
|
||||||
|
do
|
||||||
|
a=EV"$i"_ALIAS
|
||||||
|
al=${!a}
|
||||||
|
local crons=`get_cron_close $al`
|
||||||
|
if [[ ! -z "$crons" ]]; then
|
||||||
|
del_cron_close $al
|
||||||
|
IFS=$'\n' # make newlines the only separator
|
||||||
|
for cron in $crons
|
||||||
|
do
|
||||||
|
#echo "-- $cron --"
|
||||||
|
CRON_M=`echo $cron | $CUT -d' ' -f1,1`
|
||||||
|
CRON_H=`echo $cron | $CUT -d' ' -f2,2`
|
||||||
|
CRON_DOM=`echo $cron | $CUT -d' ' -f3,3`
|
||||||
|
CRON_MON=`echo $cron | $CUT -d' ' -f4,4`
|
||||||
|
CRON_DOW=`echo $cron | $CUT -d' ' -f5,5`
|
||||||
|
|
||||||
|
if [[ ${CRON_M:0:1} == "#" ]]; then
|
||||||
|
CRON_M=${CRON_M:1:${#CRON_M}}
|
||||||
|
fi
|
||||||
|
#echo "++ $CRON_M $CRON_H $CRON_DOM $CRON_MON $CRON_DOW ++"
|
||||||
|
|
||||||
|
add_cron_close $al "$CRON_M" "$CRON_H" "$CRON_DOM" "$CRON_MON" "$CRON_DOW"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
declare -a list_drv
|
declare -a list_drv
|
||||||
|
|
||||||
|
#
|
||||||
|
# Funzione eseguita ad ogni avvio di piGarden.sh, si occupa includere tutti i file dei driver utilizzati e di lanciare
|
||||||
|
# la funzione di setup di ogni driver se esistente
|
||||||
|
#
|
||||||
function setup_drv {
|
function setup_drv {
|
||||||
|
|
||||||
#declare -a list_drv
|
#declare -a list_drv
|
||||||
list_drv=()
|
list_drv=()
|
||||||
|
|
||||||
# Inizializza i driver per le elettrovalvole
|
# Raccoglie i nomi dei driver utilizzati per le elettrovalvole
|
||||||
for i in $(seq $EV_TOTAL)
|
for i in $(seq $EV_TOTAL)
|
||||||
do
|
do
|
||||||
local a=EV"$i"_GPIO
|
local a=EV"$i"_GPIO
|
||||||
@@ -18,8 +22,8 @@ function setup_drv {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Inizializza i driver per gli altri gpio
|
# Raccoglie i nomi dei driver utilizzati per gli altri gpio
|
||||||
for gpio in "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2" "$RAIN_GPIO"
|
for gpio in "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2" "$RAIN_GPIO" "$WEATHER_SERVICE"
|
||||||
do
|
do
|
||||||
if [[ "$gpio" == drv:* ]]; then
|
if [[ "$gpio" == drv:* ]]; then
|
||||||
local drv=`echo $gpio | $CUT -d':' -f2,2`
|
local drv=`echo $gpio | $CUT -d':' -f2,2`
|
||||||
@@ -29,10 +33,13 @@ function setup_drv {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
#
|
||||||
|
# Esegue l'unclusione dei file dei driver e per ognuno lancia l'eventuale funzione di setup
|
||||||
|
#
|
||||||
local file_drv
|
local file_drv
|
||||||
for drv in "${list_drv[@]}"
|
for drv in "${list_drv[@]}"
|
||||||
do
|
do
|
||||||
for callback in config common init rele supply rainsensor setup
|
for callback in config common init rele supply rainsensor rainonline setup
|
||||||
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
|
||||||
@@ -87,7 +94,7 @@ function drv_rele_init {
|
|||||||
$GPIO -g mode $idx out # setta il gpio nella modalita di scrittura
|
$GPIO -g mode $idx out # setta il gpio nella modalita di scrittura
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc" == "drvnotfound" ]; then
|
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"
|
message_write "warning" "Driver not found: $idx"
|
||||||
else
|
else
|
||||||
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
|
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
|
||||||
@@ -109,11 +116,15 @@ function drv_rele_close {
|
|||||||
$GPIO -g write $idx $RELE_GPIO_CLOSE
|
$GPIO -g write $idx $RELE_GPIO_CLOSE
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc" == "drvnotfound" ]; then
|
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"
|
message_write "warning" "Driver not found: $idx"
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
|
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
|
||||||
$fnc "$idx" >> "$LOG_OUTPUT_DRV_FILE" 2>&1
|
$fnc "$idx" >> "$LOG_OUTPUT_DRV_FILE" 2>&1
|
||||||
|
if [ $? -eq 1 ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,11 +142,15 @@ function drv_rele_open {
|
|||||||
$GPIO -g write $idx $RELE_GPIO_OPEN
|
$GPIO -g write $idx $RELE_GPIO_OPEN
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc" == "drvnotfound" ]; then
|
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"
|
message_write "warning" "Driver not found: $idx"
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
|
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
|
||||||
$fnc "$idx" >> "$LOG_OUTPUT_DRV_FILE" 2>&1
|
$fnc "$idx" >> "$LOG_OUTPUT_DRV_FILE" 2>&1
|
||||||
|
if [ $? -eq 1 ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +172,7 @@ function drv_supply_bistable_init {
|
|||||||
$GPIO -g mode $idx1 out
|
$GPIO -g mode $idx1 out
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc1" == "drvnotfound" ]; then
|
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"
|
message_write "warning" "Driver not found: $idx1"
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
@@ -171,7 +186,7 @@ function drv_supply_bistable_init {
|
|||||||
$GPIO -g mode $idx2 out
|
$GPIO -g mode $idx2 out
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc2" == "drvnotfound" ]; then
|
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"
|
message_write "warning" "Driver not found: $idx2"
|
||||||
else
|
else
|
||||||
echo "$(date) $fnc2 arg:$idx2" >> "$LOG_OUTPUT_DRV_FILE"
|
echo "$(date) $fnc2 arg:$idx2" >> "$LOG_OUTPUT_DRV_FILE"
|
||||||
@@ -197,7 +212,7 @@ function drv_supply_positive {
|
|||||||
$GPIO -g write $idx1 $SUPPLY_GPIO_POS
|
$GPIO -g write $idx1 $SUPPLY_GPIO_POS
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc1" == "drvnotfound" ]; then
|
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"
|
message_write "warning" "Driver not found: $idx1"
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
@@ -210,7 +225,7 @@ function drv_supply_positive {
|
|||||||
$GPIO -g write $idx2 $SUPPLY_GPIO_POS
|
$GPIO -g write $idx2 $SUPPLY_GPIO_POS
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc2" == "drvnotfound" ]; then
|
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"
|
message_write "warning" "Driver not found: $idx2"
|
||||||
else
|
else
|
||||||
echo "$(date) $fnc2 arg:$idx2" >> "$LOG_OUTPUT_DRV_FILE"
|
echo "$(date) $fnc2 arg:$idx2" >> "$LOG_OUTPUT_DRV_FILE"
|
||||||
@@ -236,7 +251,7 @@ function drv_supply_negative {
|
|||||||
$GPIO -g write $idx1 $SUPPLY_GPIO_NEG
|
$GPIO -g write $idx1 $SUPPLY_GPIO_NEG
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc1" == "drvnotfound" ]; then
|
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"
|
message_write "warning" "Driver not found: $idx1"
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
@@ -249,7 +264,7 @@ function drv_supply_negative {
|
|||||||
$GPIO -g write $idx2 $SUPPLY_GPIO_NEG
|
$GPIO -g write $idx2 $SUPPLY_GPIO_NEG
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc2" == "drvnotfound" ]; then
|
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"
|
message_write "warning" "Driver not found: $idx2"
|
||||||
else
|
else
|
||||||
echo "$(date) $fnc2 arg:$idx2" >> "$LOG_OUTPUT_DRV_FILE"
|
echo "$(date) $fnc2 arg:$idx2" >> "$LOG_OUTPUT_DRV_FILE"
|
||||||
@@ -273,7 +288,7 @@ function drv_rain_sensor_init {
|
|||||||
$GPIO -g mode $idx in
|
$GPIO -g mode $idx in
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc" == "drvnotfound" ]; then
|
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"
|
message_write "warning" "Driver not found: $idx"
|
||||||
else
|
else
|
||||||
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
|
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
|
||||||
@@ -294,10 +309,37 @@ function drv_rain_sensor_get {
|
|||||||
|
|
||||||
# Nessun driver definito, esegue la lettura del sensore tramite gpio del raspberry
|
# Nessun driver definito, esegue la lettura del sensore tramite gpio del raspberry
|
||||||
if [ -z "$fnc" ]; then
|
if [ -z "$fnc" ]; then
|
||||||
val=`$GPIO -g read $idx`
|
vret=`$GPIO -g read $idx`
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc" == "drvnotfound" ]; then
|
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"
|
||||||
|
vret=`$fnc "$idx"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$vret"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Legge lo stato le condizioni meteo dal servizio online
|
||||||
|
#
|
||||||
|
# $1 identificativo gpio sensore pioggia
|
||||||
|
#
|
||||||
|
function drv_rain_online_get {
|
||||||
|
local idx="$1"
|
||||||
|
local fnc=`get_driver_callback "rain_online_get" "$idx"`
|
||||||
|
local vret=""
|
||||||
|
|
||||||
|
# Nessun driver definito, esegue la lettura del sensore tramite gpio del raspberry
|
||||||
|
if [ -z "$fnc" ]; then
|
||||||
|
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 "drv" "error" "Driver not found: $idx"
|
||||||
message_write "warning" "Driver not found: $idx"
|
message_write "warning" "Driver not found: $idx"
|
||||||
else
|
else
|
||||||
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
|
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
|
||||||
|
|||||||
@@ -5,19 +5,6 @@
|
|||||||
|
|
||||||
function trigger_event {
|
function trigger_event {
|
||||||
|
|
||||||
# check_rain_online_after
|
|
||||||
# check_rain_online_before
|
|
||||||
# check_rain_online_change
|
|
||||||
# check_rain_sensor_after
|
|
||||||
# check_rain_sensor_before
|
|
||||||
# check_rain_sensor_change
|
|
||||||
# ev_close_after
|
|
||||||
# ev_close_before
|
|
||||||
# ev_open_after
|
|
||||||
# ev_open_before
|
|
||||||
# init_after
|
|
||||||
# init_before
|
|
||||||
|
|
||||||
local EVENT="$1"
|
local EVENT="$1"
|
||||||
local CAUSE="$2"
|
local CAUSE="$2"
|
||||||
local current_event_dir="$EVENT_DIR/$EVENT"
|
local current_event_dir="$EVENT_DIR/$EVENT"
|
||||||
@@ -30,12 +17,32 @@ function trigger_event {
|
|||||||
case "$EVENT" in
|
case "$EVENT" in
|
||||||
"ev_open_before" | "ev_open_after")
|
"ev_open_before" | "ev_open_after")
|
||||||
ALIAS="$2"
|
ALIAS="$2"
|
||||||
|
CURRENT_EVENT_ALIAS="$ALIAS"
|
||||||
FORCE="$3"
|
FORCE="$3"
|
||||||
$f "$EVENT" "$ALIAS" "$FORCE" `date +%s` &> /dev/null
|
$f "$EVENT" "$ALIAS" "$FORCE" `date +%s` &> /dev/null
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
"ev_open_in_before")
|
||||||
|
ALIAS="$2"
|
||||||
|
CURRENT_EVENT_ALIAS="$ALIAS"
|
||||||
|
FORCE="$3"
|
||||||
|
local MINUTE_START="$4"
|
||||||
|
local MINUTE_STOP="$5"
|
||||||
|
$f "$EVENT" "$ALIAS" "$FORCE" "$MINUTE_START" "$MINUTE_STOP" `date +%s` &> /dev/null
|
||||||
|
;;
|
||||||
|
|
||||||
|
"ev_open_in_after")
|
||||||
|
ALIAS="$2"
|
||||||
|
CURRENT_EVENT_ALIAS="$ALIAS"
|
||||||
|
FORCE="$3"
|
||||||
|
local CRON_START="$4"
|
||||||
|
local CRON_STOP="$5"
|
||||||
|
$f "$EVENT" "$ALIAS" "$FORCE" "$CRON_START" "$CRON_STOP" `date +%s` &> /dev/null
|
||||||
|
;;
|
||||||
|
|
||||||
"ev_close_before" | "ev_close_after")
|
"ev_close_before" | "ev_close_after")
|
||||||
ALIAS="$2"
|
ALIAS="$2"
|
||||||
|
CURRENT_EVENT_ALIAS="$ALIAS"
|
||||||
$f "$EVENT" "$ALIAS" `date +%s` &> /dev/null
|
$f "$EVENT" "$ALIAS" `date +%s` &> /dev/null
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -45,11 +52,40 @@ function trigger_event {
|
|||||||
$f "$EVENT" "$STATE" `date +%s` &> /dev/null
|
$f "$EVENT" "$STATE" `date +%s` &> /dev/null
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"check_rain_online_before" | "check_rain_online_after" | "check_rain_online_change")
|
"check_rain_online_before")
|
||||||
STATE="$2"
|
STATE="$2"
|
||||||
$f "$EVENT" "$STATE" `date +%s` &> /dev/null
|
$f "$EVENT" "$STATE" `date +%s` &> /dev/null
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
"check_rain_online_after" | "check_rain_online_change")
|
||||||
|
STATE="$2"
|
||||||
|
WEATHER="$3"
|
||||||
|
$f "$EVENT" "$STATE" "$WEATHER" `date +%s` &> /dev/null
|
||||||
|
;;
|
||||||
|
|
||||||
|
|
||||||
|
"init_before" | "init_after")
|
||||||
|
STATE="$2"
|
||||||
|
$f "$EVENT" `date +%s` &> /dev/null
|
||||||
|
;;
|
||||||
|
|
||||||
|
"cron_add_before" | "cron_add_after")
|
||||||
|
local CRON_TYPE="$2"
|
||||||
|
local CRON_ARG="$3"
|
||||||
|
local CRON_ELEMENT="$4"
|
||||||
|
$f "$EVENT" "$CRON_TYPE" "$CRON_ARG" "$CRON_ELEMENT" `date +%s` &> /dev/null
|
||||||
|
;;
|
||||||
|
|
||||||
|
"cron_del_before" | "cron_del_after")
|
||||||
|
local CRON_TYPE="$2"
|
||||||
|
local CRON_ARG="$3"
|
||||||
|
$f "$EVENT" "$CRON_TYPE" "$CRON_ARG" `date +%s` &> /dev/null
|
||||||
|
;;
|
||||||
|
|
||||||
|
"exec_poweroff_before" | "exec_poweroff_after" | "exec_reboot_before" | "exec_reboot_after" )
|
||||||
|
$f "$EVENT" `date +%s` &> /dev/null
|
||||||
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
$f "$EVENT" "$CAUSE" `date +%s` &> /dev/null
|
$f "$EVENT" "$CAUSE" `date +%s` &> /dev/null
|
||||||
;;
|
;;
|
||||||
@@ -57,7 +93,13 @@ function trigger_event {
|
|||||||
|
|
||||||
local ec=$?
|
local ec=$?
|
||||||
#echo "$EVENT ec=$ec" >> /tmp/piGarden.testevent
|
#echo "$EVENT ec=$ec" >> /tmp/piGarden.testevent
|
||||||
|
|
||||||
|
#CURRENT_EVENT="$EVENT"
|
||||||
|
#mqtt_status &
|
||||||
|
|
||||||
if [ $ec -ne 0 ]; then
|
if [ $ec -ne 0 ]; then
|
||||||
|
CURRENT_EVENT="$EVENT"
|
||||||
|
mqtt_status &
|
||||||
log_write "Stop events chain for exit code $ec in $current_event_dir/$f"
|
log_write "Stop events chain for exit code $ec in $current_event_dir/$f"
|
||||||
return $ec
|
return $ec
|
||||||
fi
|
fi
|
||||||
@@ -66,6 +108,9 @@ function trigger_event {
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
CURRENT_EVENT="$EVENT"
|
||||||
|
mqtt_status &
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,47 +1,48 @@
|
|||||||
#
|
#
|
||||||
# Controlla se se piove tramite http://api.wunderground.com/
|
# Esegue controllo meteo tramite servizio online configurato in WEATHER_SERVICE
|
||||||
#
|
#
|
||||||
function check_rain_online {
|
function check_rain_online {
|
||||||
|
|
||||||
trigger_event "check_rain_online_before" ""
|
if [ "$WEATHER_SERVICE" == "none" ]; then
|
||||||
|
log_write "rain" "warning" "check_rain_online - online service is disabled"
|
||||||
# http://www.wunderground.com/weather/api/d/docs?d=resources/phrase-glossary&MR=1
|
return
|
||||||
$CURL http://api.wunderground.com/api/$WUNDERGROUND_KEY/conditions/q/$WUNDERGROUND_LOCATION.json > $TMP_PATH/check_rain_online.json
|
|
||||||
local weather=`cat $TMP_PATH/check_rain_online.json | $JQ -M ".current_observation.weather"`
|
|
||||||
local current_observation=`cat $TMP_PATH/check_rain_online.json | $JQ -M ".current_observation"`
|
|
||||||
local local_epoch=`cat $TMP_PATH/check_rain_online.json | $JQ -M -r ".current_observation.local_epoch"`
|
|
||||||
local current_state_rain_online=""
|
|
||||||
local last_state_rain_online=`cat "$STATUS_DIR/last_state_rain_online" 2> /dev/null`
|
|
||||||
#echo $weather
|
|
||||||
#weather="[Light/Heavy] Drizzle"
|
|
||||||
if [ "$weather" = "null" ]; then
|
|
||||||
log_write "check_rain_online - failed read online data"
|
|
||||||
else
|
|
||||||
log_write "check_rain_online - weather=$weather, local_epoch=$local_epoch"
|
|
||||||
#if [[ "$weather" == *"Clear"* ]]; then
|
|
||||||
#if [[ "$weather" == *"Rain"* ]]; then
|
|
||||||
if [[ "$weather" == *"Rain"* ]] ||
|
|
||||||
[[ "$weather" == *"Snow"* ]] ||
|
|
||||||
[[ "$weather" == *"Hail"* ]] ||
|
|
||||||
[[ "$weather" == *"Ice"* ]] ||
|
|
||||||
[[ "$weather" == *"Thunderstorm"* ]] ||
|
|
||||||
[[ "$weather" == *"Drizzle"* ]];
|
|
||||||
then
|
|
||||||
current_state_rain_online='rain'
|
|
||||||
echo $local_epoch > "$STATUS_DIR/last_rain_online"
|
|
||||||
else
|
|
||||||
current_state_rain_online='norain'
|
|
||||||
fi
|
|
||||||
echo "$current_observation" > "$STATUS_DIR/last_weather_online"
|
|
||||||
if [ "$current_state_rain_online" != "$last_state_rain_online" ]; then
|
|
||||||
echo "$current_state_rain_online" > "$STATUS_DIR/last_state_rain_online"
|
|
||||||
trigger_event "check_rain_online_change" "$current_state_rain_online"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
trigger_event "check_rain_online_after" "$current_state_rain_online"
|
trigger_event "check_rain_online_before" ""
|
||||||
|
|
||||||
|
local local_epoch=`drv_rain_online_get $WEATHER_SERVICE`
|
||||||
|
local current_state_rain_online=""
|
||||||
|
local last_state_rain_online=`cat "$STATUS_DIR/last_state_rain_online" 2> /dev/null`
|
||||||
|
local weather="null"
|
||||||
|
|
||||||
|
if [[ $local_epoch =~ ^-?[0-9]+$ ]]; then
|
||||||
|
if [ $local_epoch -eq 0 ]; then
|
||||||
|
log_write "rain" "error" "check_rain_online - failed read online data"
|
||||||
|
else
|
||||||
|
if [ $local_epoch -gt 0 ]; then
|
||||||
|
current_state_rain_online='rain'
|
||||||
|
echo $local_epoch > "$STATUS_DIR/last_rain_online"
|
||||||
|
else
|
||||||
|
current_state_rain_online='norain'
|
||||||
|
fi
|
||||||
|
weather=$(cat "$STATUS_DIR/last_weather_online" | $JQ -M ".weather")
|
||||||
|
|
||||||
|
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 "rain" "error" "check_rain_online - failed read online data"
|
||||||
|
fi
|
||||||
|
|
||||||
|
trigger_event "check_rain_online_after" "$current_state_rain_online" "$weather"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Controlla se se piove tramite sensore
|
# Controlla se se piove tramite sensore
|
||||||
#
|
#
|
||||||
@@ -56,11 +57,11 @@ function check_rain_sensor {
|
|||||||
current_state_rain_sensor='rain'
|
current_state_rain_sensor='rain'
|
||||||
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"
|
||||||
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
|
#return $local_epoch
|
||||||
else
|
else
|
||||||
current_state_rain_sensor='norain'
|
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
|
fi
|
||||||
if [ "$current_state_rain_sensor" != "$last_state_rain_sensor" ]; then
|
if [ "$current_state_rain_sensor" != "$last_state_rain_sensor" ]; then
|
||||||
echo "$current_state_rain_sensor" > "$STATUS_DIR/last_state_rain_sensor"
|
echo "$current_state_rain_sensor" > "$STATUS_DIR/last_state_rain_sensor"
|
||||||
@@ -68,7 +69,7 @@ function check_rain_sensor {
|
|||||||
fi
|
fi
|
||||||
trigger_event "check_rain_sensor_after" "$current_state_rain_sensor"
|
trigger_event "check_rain_sensor_after" "$current_state_rain_sensor"
|
||||||
else
|
else
|
||||||
log_write "Rain sensor not present"
|
log_write "rain" "warning" "Rain sensor not present"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -112,7 +113,7 @@ function close_all_for_rain {
|
|||||||
#echo "$al = $state"
|
#echo "$al = $state"
|
||||||
if [ "$state" = "1" ] && [ "$evnorain" != "1" ]; then
|
if [ "$state" = "1" ] && [ "$evnorain" != "1" ]; then
|
||||||
ev_close $al
|
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
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function stop_socket_server {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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 $(list_descendants `cat "$TCPSERVER_PID_FILE"`) 2> /dev/null
|
||||||
kill -9 `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]')
|
user=$(echo "$user" | $TR -d '[\r\n]')
|
||||||
password=$(echo "$password" | $TR -d '[\r\n]')
|
password=$(echo "$password" | $TR -d '[\r\n]')
|
||||||
if [ "$user" != "$TCPSERVER_USER" ] || [ "$password" != "$TCPSERVER_PWD" ]; then
|
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"
|
json_error 0 "Bad socket server credentials"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@@ -61,9 +61,9 @@ function socket_server_command {
|
|||||||
arg7=$(echo "$line " | $CUT -d ' ' -f7)
|
arg7=$(echo "$line " | $CUT -d ' ' -f7)
|
||||||
arg8=$(echo "$line " | $CUT -d ' ' -f8)
|
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
|
#reset_messages &> /dev/null
|
||||||
|
|
||||||
case "$arg1" in
|
case "$arg1" in
|
||||||
status)
|
status)
|
||||||
@@ -102,6 +102,12 @@ function socket_server_command {
|
|||||||
json_status
|
json_status
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
cron_enable_all_open_close)
|
||||||
|
cron_enable_all_open_close &> /dev/null
|
||||||
|
message_write "success" "All solenoid enabled"
|
||||||
|
json_status
|
||||||
|
;;
|
||||||
|
|
||||||
set_general_cron)
|
set_general_cron)
|
||||||
local vret=""
|
local vret=""
|
||||||
for i in $arg2 $arg3 $arg4 $arg5 $arg6 $arg7
|
for i in $arg2 $arg3 $arg4 $arg5 $arg6 $arg7
|
||||||
@@ -121,7 +127,7 @@ function socket_server_command {
|
|||||||
|
|
||||||
if [[ ! -z $vret ]]; then
|
if [[ ! -z $vret ]]; then
|
||||||
json_error 0 "Cron set failed"
|
json_error 0 "Cron set failed"
|
||||||
log_write "Cron set failed: $vret"
|
log_write "socket_server" "error" "Cron set failed: $vret"
|
||||||
else
|
else
|
||||||
message_write "success" "Cron set successfull"
|
message_write "success" "Cron set successfull"
|
||||||
json_status
|
json_status
|
||||||
@@ -136,7 +142,7 @@ function socket_server_command {
|
|||||||
|
|
||||||
if [[ ! -z $vret ]]; then
|
if [[ ! -z $vret ]]; then
|
||||||
json_error 0 "Cron set failed"
|
json_error 0 "Cron set failed"
|
||||||
log_write "Cron del failed: $vret"
|
log_write "socket_server" "error" "Cron del failed: $vret"
|
||||||
else
|
else
|
||||||
message_write "success" "Cron set successfull"
|
message_write "success" "Cron set successfull"
|
||||||
json_status
|
json_status
|
||||||
@@ -151,7 +157,7 @@ function socket_server_command {
|
|||||||
|
|
||||||
if [[ ! -z $vret ]]; then
|
if [[ ! -z $vret ]]; then
|
||||||
json_error 0 "Cron del failed"
|
json_error 0 "Cron del failed"
|
||||||
log_write "Cron del failed: $vret"
|
log_write "socket_server" "error" "Cron del failed: $vret"
|
||||||
else
|
else
|
||||||
message_write "success" "Scheduled start successfully deleted"
|
message_write "success" "Scheduled start successfully deleted"
|
||||||
json_status "get_cron_open_in:$arg2"
|
json_status "get_cron_open_in:$arg2"
|
||||||
@@ -167,7 +173,7 @@ function socket_server_command {
|
|||||||
|
|
||||||
if [[ ! -z $vret ]]; then
|
if [[ ! -z $vret ]]; then
|
||||||
json_error 0 "Cron set failed"
|
json_error 0 "Cron set failed"
|
||||||
log_write "Cron set failed: $vret"
|
log_write "socket_server" "error" "Cron set failed: $vret"
|
||||||
else
|
else
|
||||||
message_write "success" "Cron set successfull"
|
message_write "success" "Cron set successfull"
|
||||||
json_status
|
json_status
|
||||||
@@ -182,7 +188,7 @@ function socket_server_command {
|
|||||||
|
|
||||||
if [[ ! -z $vret ]]; then
|
if [[ ! -z $vret ]]; then
|
||||||
json_error 0 "Cron set failed"
|
json_error 0 "Cron set failed"
|
||||||
log_write "Cron set failed: $vret"
|
log_write "socket_server" "error" "Cron set failed: $vret"
|
||||||
else
|
else
|
||||||
message_write "success" "Cron set successfull"
|
message_write "success" "Cron set successfull"
|
||||||
json_status
|
json_status
|
||||||
@@ -197,7 +203,7 @@ function socket_server_command {
|
|||||||
|
|
||||||
if [[ ! -z $vret ]]; then
|
if [[ ! -z $vret ]]; then
|
||||||
json_error 0 "Cron set failed"
|
json_error 0 "Cron set failed"
|
||||||
log_write "Cron set failed: $vret"
|
log_write "socket_server" "error" "Cron set failed: $vret"
|
||||||
else
|
else
|
||||||
message_write "success" "Cron set successfull"
|
message_write "success" "Cron set successfull"
|
||||||
json_status
|
json_status
|
||||||
@@ -205,6 +211,21 @@ function socket_server_command {
|
|||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
cmd_pigardensched)
|
||||||
|
local vret=""
|
||||||
|
|
||||||
|
vret=`cmd_pigardensched $arg2 $arg3 $arg4 $arg5 $arg6`
|
||||||
|
|
||||||
|
if [[ ! -z $vret ]]; then
|
||||||
|
json_error 0 "piGardenSched command failed"
|
||||||
|
log_write "socket_server" "error" "piGardenSched command failed: $vret"
|
||||||
|
else
|
||||||
|
message_write "success" "Schedule set successfull"
|
||||||
|
json_status
|
||||||
|
fi
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
reboot)
|
reboot)
|
||||||
message_write "warning" "System reboot is started"
|
message_write "warning" "System reboot is started"
|
||||||
json_status
|
json_status
|
||||||
@@ -225,7 +246,7 @@ function socket_server_command {
|
|||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
reset_messages &> /dev/null
|
#reset_messages &> /dev/null
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
377
piGarden.sh
377
piGarden.sh
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
function initialize {
|
function initialize {
|
||||||
|
|
||||||
log_write "Run initialize"
|
log_write "general" "info" "Run initialize"
|
||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
@@ -26,10 +26,6 @@ function initialize {
|
|||||||
# 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
|
||||||
drv_supply_bistable_init "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2"
|
drv_supply_bistable_init "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2"
|
||||||
#$GPIO -g write $SUPPLY_GPIO_1 0
|
|
||||||
#$GPIO -g write $SUPPLY_GPIO_2 0
|
|
||||||
#$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
|
||||||
@@ -40,8 +36,6 @@ function initialize {
|
|||||||
do
|
do
|
||||||
g=EV"$i"_GPIO
|
g=EV"$i"_GPIO
|
||||||
drv_rele_init "${!g}"
|
drv_rele_init "${!g}"
|
||||||
#$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
|
||||||
|
|
||||||
@@ -56,21 +50,20 @@ function initialize {
|
|||||||
# Inizializza il sensore di rilevamento pioggia
|
# Inizializza il sensore di rilevamento pioggia
|
||||||
if [ -n "$RAIN_GPIO" ]; then
|
if [ -n "$RAIN_GPIO" ]; then
|
||||||
drv_rain_sensor_init "$RAIN_GPIO"
|
drv_rain_sensor_init "$RAIN_GPIO"
|
||||||
#$GPIO -g mode $RAIN_GPIO in
|
log_write "rain" "info" "Rain sensor initialized"
|
||||||
log_write "Rain sensor initialized"
|
|
||||||
else
|
else
|
||||||
log_write "Rain sensor not present"
|
log_write "rain" "info" "Rain sensor not present"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
trigger_event "init_after" ""
|
trigger_event "init_after" ""
|
||||||
log_write "End initialize"
|
log_write "general" "info" "End initialize"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Elimina i file contenente i messaggi da inserire nel json status
|
# Elimina i file contenente i messaggi da inserire nel json status
|
||||||
#
|
#
|
||||||
function reset_messages {
|
function reset_messages_old {
|
||||||
rm -f "$LAST_INFO_FILE.$!"
|
rm -f "$LAST_INFO_FILE.$!"
|
||||||
rm -f "$LAST_WARNING_FILE.$!"
|
rm -f "$LAST_WARNING_FILE.$!"
|
||||||
rm -f "$LAST_SUCCESS_FILE.$!"
|
rm -f "$LAST_SUCCESS_FILE.$!"
|
||||||
@@ -90,6 +83,10 @@ function ev_open {
|
|||||||
local EVNUM=$?
|
local EVNUM=$?
|
||||||
local g=`ev_number2gpio $EVNUM`
|
local g=`ev_number2gpio $EVNUM`
|
||||||
local EVNORAIN=`ev_number2norain $EVNUM`
|
local EVNORAIN=`ev_number2norain $EVNUM`
|
||||||
|
local EV_IS_REMOTE_VAR=EV"$EVNUM"_REMOTE
|
||||||
|
local EV_IS_REMOTE=${!EV_IS_REMOTE_VAR}
|
||||||
|
local EV_IS_MONOSTABLE_VAR=EV"$EVNUM"_MONOSTABLE
|
||||||
|
local EV_IS_MONOSTABLE=${!EV_IS_MONOSTABLE_VAR}
|
||||||
|
|
||||||
if [ ! "$2" = "force" ] && [ "$EVNORAIN" != "1" ]; then
|
if [ ! "$2" = "force" ] && [ "$EVNORAIN" != "1" ]; then
|
||||||
if [[ "$NOT_IRRIGATE_IF_RAIN_ONLINE" -gt 0 && -f $STATUS_DIR/last_rain_online ]]; then
|
if [[ "$NOT_IRRIGATE_IF_RAIN_ONLINE" -gt 0 && -f $STATUS_DIR/last_rain_online ]]; then
|
||||||
@@ -98,8 +95,10 @@ function ev_open {
|
|||||||
local dif=0
|
local dif=0
|
||||||
let "dif = now - last_rain"
|
let "dif = now - last_rain"
|
||||||
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_ONLINE ]; then
|
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_ONLINE ]; then
|
||||||
log_write "Solenoid '$1' not open for rain (online check)"
|
|
||||||
message_write "warning" "Solenoid not open for rain"
|
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
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -111,8 +110,10 @@ function ev_open {
|
|||||||
local dif=0
|
local dif=0
|
||||||
let "dif = now - last_rain"
|
let "dif = now - last_rain"
|
||||||
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_SENSOR ]; then
|
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_SENSOR ]; then
|
||||||
log_write "Solenoid '$1' not open for rain (sensor check)"
|
|
||||||
message_write "warning" "Solenoid not open for rain"
|
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
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -125,34 +126,36 @@ function ev_open {
|
|||||||
|
|
||||||
trigger_event "ev_open_before" "$1" "$2"
|
trigger_event "ev_open_before" "$1" "$2"
|
||||||
if [ $? -ne 0 ]; then
|
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"
|
message_write 'warning' "Solenoid not open due to external event"
|
||||||
|
mqtt_status
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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" ] || [ "$EV_IS_REMOTE" == "1" ] || [ "$EV_IS_MONOSTABLE" == "1" ]; then
|
||||||
#$GPIO -g write $g $RELE_GPIO_CLOSE
|
|
||||||
drv_rele_close "$g"
|
drv_rele_close "$g"
|
||||||
|
if [ $? -eq 1 ]; then
|
||||||
|
unlock
|
||||||
|
return
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
supply_positive
|
supply_positive
|
||||||
#$GPIO -g write $g $RELE_GPIO_CLOSE
|
|
||||||
drv_rele_close "$g"
|
drv_rele_close "$g"
|
||||||
sleep 1
|
sleep 1
|
||||||
#$GPIO -g write $g $RELE_GPIO_OPEN
|
|
||||||
drv_rele_open "$g"
|
drv_rele_open "$g"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ev_set_state $EVNUM $state
|
ev_set_state $EVNUM $state
|
||||||
|
|
||||||
|
log_write "irrigate" "info" "Solenoid '$1' open"
|
||||||
|
message_write "success" "Solenoid open"
|
||||||
|
|
||||||
trigger_event "ev_open_after" "$1" "$2"
|
trigger_event "ev_open_after" "$1" "$2"
|
||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
log_write "Solenoid '$1' open"
|
|
||||||
message_write "success" "Solenoid open"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -173,23 +176,30 @@ function ev_open_in {
|
|||||||
if ! [[ $minute_start =~ $re ]] ; then
|
if ! [[ $minute_start =~ $re ]] ; then
|
||||||
echo -e "Time start of irrigation is wrong or not specified"
|
echo -e "Time start of irrigation is wrong or not specified"
|
||||||
message_write "warning" "Time start of irrigation is wrong or not specified"
|
message_write "warning" "Time start of irrigation is wrong or not specified"
|
||||||
|
mqtt_status
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if ! [[ $minute_stop =~ $re ]] ; then
|
if ! [[ $minute_stop =~ $re ]] ; then
|
||||||
echo -e "Time stop of irrigation is wrong or not specified"
|
echo -e "Time stop of irrigation is wrong or not specified"
|
||||||
message_write "warning" "Time stop of irrigation is wrong or not specified"
|
message_write "warning" "Time stop of irrigation is wrong or not specified"
|
||||||
|
mqtt_status
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [ $minute_stop -lt "1" ] ; then
|
if [ $minute_stop -lt "1" ] ; then
|
||||||
echo -e "Time stop of irrigation is wrong"
|
echo -e "Time stop of irrigation is wrong"
|
||||||
message_write "warning" "Time stop of irrigation is wrong"
|
message_write "warning" "Time stop of irrigation is wrong"
|
||||||
|
mqtt_status
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [ "empty$alias" == "empty" ]; then
|
if [ "empty$alias" == "empty" ]; then
|
||||||
echo -e "Alias solenoid not specified"
|
echo -e "Alias solenoid not specified"
|
||||||
message_write "warning" "Alias solenoid not specified"
|
message_write "warning" "Alias solenoid not specified"
|
||||||
|
mqtt_status
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
trigger_event "ev_open_in_before" "$3" "$4" "$1" "$2"
|
||||||
|
|
||||||
gpio_alias2number $alias > /dev/null 2>&1
|
gpio_alias2number $alias > /dev/null 2>&1
|
||||||
|
|
||||||
minute_start=$(($minute_start + 1))
|
minute_start=$(($minute_start + 1))
|
||||||
@@ -201,6 +211,7 @@ function ev_open_in {
|
|||||||
|
|
||||||
if [ "$minute_start" -eq "1" ]; then
|
if [ "$minute_start" -eq "1" ]; then
|
||||||
ev_open $alias $force
|
ev_open $alias $force
|
||||||
|
cron_start="- - - - -"
|
||||||
else
|
else
|
||||||
cron_add open_in $cron_start "$alias" "$force"
|
cron_add open_in $cron_start "$alias" "$force"
|
||||||
fi
|
fi
|
||||||
@@ -210,8 +221,7 @@ function ev_open_in {
|
|||||||
|
|
||||||
message_write "success" "Scheduled start successfully performed"
|
message_write "success" "Scheduled start successfully performed"
|
||||||
|
|
||||||
#echo $cron_start
|
trigger_event "ev_open_in_after" "$3" "$4" "$cron_start" "$cron_stop"
|
||||||
#echo $cron_stop
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,33 +236,36 @@ function ev_close {
|
|||||||
ev_alias2number $1
|
ev_alias2number $1
|
||||||
EVNUM=$?
|
EVNUM=$?
|
||||||
g=`ev_number2gpio $EVNUM`
|
g=`ev_number2gpio $EVNUM`
|
||||||
|
local EV_IS_REMOTE_VAR=EV"$EVNUM"_REMOTE
|
||||||
|
local EV_IS_REMOTE=${!EV_IS_REMOTE_VAR}
|
||||||
|
|
||||||
trigger_event "ev_close_before" "$1"
|
trigger_event "ev_close_before" "$1"
|
||||||
|
|
||||||
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" ] || [ "$EV_IS_REMOTE" == "1" ]; then
|
||||||
#$GPIO -g write $g $RELE_GPIO_OPEN
|
|
||||||
drv_rele_open "$g"
|
drv_rele_open "$g"
|
||||||
|
if [ $? -eq 1 ]; then
|
||||||
|
unlock
|
||||||
|
return
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
supply_negative
|
supply_negative
|
||||||
#$GPIO -g write $g $RELE_GPIO_CLOSE
|
|
||||||
drv_rele_close "$g"
|
drv_rele_close "$g"
|
||||||
sleep 1
|
sleep 1
|
||||||
#$GPIO -g write $g $RELE_GPIO_OPEN
|
|
||||||
drv_rele_open "$g"
|
drv_rele_open "$g"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ev_set_state $EVNUM 0
|
ev_set_state $EVNUM 0
|
||||||
|
|
||||||
|
log_write "irrigate" "info" "Solenoid '$1' close"
|
||||||
|
message_write "success" "Solenoid close"
|
||||||
|
|
||||||
trigger_event "ev_close_after" "$1"
|
trigger_event "ev_close_after" "$1"
|
||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
log_write "Solenoid '$1' close"
|
|
||||||
message_write "success" "Solenoid close"
|
|
||||||
|
|
||||||
cron_del open_in_stop $1 > /dev/null 2>&1
|
cron_del open_in_stop $1 > /dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,8 +274,6 @@ function ev_close {
|
|||||||
#
|
#
|
||||||
function supply_positive {
|
function supply_positive {
|
||||||
drv_supply_positive "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2"
|
drv_supply_positive "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2"
|
||||||
#$GPIO -g write $SUPPLY_GPIO_1 $SUPPLY_GPIO_POS
|
|
||||||
#$GPIO -g write $SUPPLY_GPIO_2 $SUPPLY_GPIO_POS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -270,13 +281,13 @@ function supply_positive {
|
|||||||
#
|
#
|
||||||
function supply_negative {
|
function supply_negative {
|
||||||
drv_supply_negative "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2"
|
drv_supply_negative "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2"
|
||||||
#$GPIO -g write $SUPPLY_GPIO_1 $SUPPLY_GPIO_NEG
|
|
||||||
#$GPIO -g write $SUPPLY_GPIO_2 $SUPPLY_GPIO_NEG
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Scrive un messaggio nel file di log
|
# Scrive un messaggio nel file di log
|
||||||
# $1 log da scrivere
|
# $1 type
|
||||||
|
# $2 level
|
||||||
|
# $3 log da scrivere
|
||||||
#
|
#
|
||||||
function log_write {
|
function log_write {
|
||||||
if [ -e "$LOG_FILE" ]; then
|
if [ -e "$LOG_FILE" ]; then
|
||||||
@@ -287,7 +298,33 @@ function log_write {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "`date`\t\t$1" >> $LOG_FILE
|
if [ -e "$LOG_OUTPUT_DRV_FILE" ]; then
|
||||||
|
local actualsize=$($WC -c <"$LOG_OUTPUT_DRV_FILE")
|
||||||
|
if [ $actualsize -ge $LOG_FILE_MAX_SIZE ]; then
|
||||||
|
$GZIP $LOG_OUTPUT_DRV_FILE
|
||||||
|
$MV $LOG_OUTPUT_DRV_FILE.gz $LOG_OUTPUT_DRV_FILE.`date +%Y%m%d%H%M`.gz
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -296,6 +333,20 @@ function log_write {
|
|||||||
# $2 messaggio
|
# $2 messaggio
|
||||||
#
|
#
|
||||||
function message_write {
|
function message_write {
|
||||||
|
local file_message=""
|
||||||
|
if [ "$1" = 'info' ]; then
|
||||||
|
MESSAGE_INFO="$2"
|
||||||
|
elif [ "$1" = "warning" ]; then
|
||||||
|
MESSAGE_WARNING="$2"
|
||||||
|
elif [ "$1" = "success" ]; then
|
||||||
|
MESSAGE_SUCCESS="$2"
|
||||||
|
else
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function message_write_old {
|
||||||
local file_message=""
|
local file_message=""
|
||||||
if [ "$1" = 'info' ]; then
|
if [ "$1" = 'info' ]; then
|
||||||
file_message="$LAST_INFO_FILE.$!"
|
file_message="$LAST_INFO_FILE.$!"
|
||||||
@@ -342,8 +393,9 @@ function gpio_alias2number {
|
|||||||
fi
|
fi
|
||||||
done
|
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"
|
message_write "warning" "Solenoid alias not found"
|
||||||
|
mqtt_status
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,8 +413,9 @@ function ev_alias2number {
|
|||||||
fi
|
fi
|
||||||
done
|
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"
|
message_write "warning" "Solenoid alias not found"
|
||||||
|
mqtt_status
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,7 +500,7 @@ function close_all {
|
|||||||
#echo "$al = $state"
|
#echo "$al = $state"
|
||||||
if [[ "$state" -gt "0" || "$1" = "force" ]]; then
|
if [[ "$state" -gt "0" || "$1" = "force" ]]; then
|
||||||
ev_close $al
|
ev_close $al
|
||||||
log_write "close_all - Close solenoid '$al' for rain"
|
log_write "irrigate" "info" "close_all - Close solenoid '$al' for rain"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -470,8 +523,9 @@ function list_alias {
|
|||||||
#
|
#
|
||||||
# Stampa un json contanente lo status della centralina
|
# Stampa un json contanente lo status della centralina
|
||||||
# $1 .. $6 parametri opzionali
|
# $1 .. $6 parametri opzionali
|
||||||
# - get_cron: aggiunge i dati relativi ai crontab delle scehdulazioni di apertura/chisura delle elettrovalvole
|
# - get_cron: aggiunge i dati relativi ai crontab delle scehdulazioni di apertura/chisura
|
||||||
# - get_cron_open_in: aggiunge i dati relativi ai crontab degli avvii ritardati eseguiti con il comando open_in
|
# - get_cron_open_in: aggiunge i dati relativi ai crontab degli avvii ritardati eseguiti con il comando open_in
|
||||||
|
# - get_schedule: aggiunge i dati relativi alle schedulazioni di piGardenSched
|
||||||
#
|
#
|
||||||
function json_status {
|
function json_status {
|
||||||
local json=""
|
local json=""
|
||||||
@@ -485,6 +539,13 @@ function json_status {
|
|||||||
local last_success=""
|
local last_success=""
|
||||||
local with_get_cron="0"
|
local with_get_cron="0"
|
||||||
local with_get_cron_open_in="0"
|
local with_get_cron_open_in="0"
|
||||||
|
local with_get_schedule="0"
|
||||||
|
local current_pid=$!
|
||||||
|
local json_event="\"event\": {\"event\": \"$CURRENT_EVENT\", \"alias\": \"$CURRENT_EVENT_ALIAS\"}"
|
||||||
|
|
||||||
|
if [ "$PARENT_PID" -gt "0" ]; then
|
||||||
|
current_pid=$PARENT_PID
|
||||||
|
fi
|
||||||
|
|
||||||
local vret=""
|
local vret=""
|
||||||
for i in $1 $2 $3 $4 $5 $6
|
for i in $1 $2 $3 $4 $5 $6
|
||||||
@@ -497,9 +558,12 @@ function json_status {
|
|||||||
with_get_cron_open_in="1"
|
with_get_cron_open_in="1"
|
||||||
elif [[ "$i" == get_cron_open_in:* ]]; then
|
elif [[ "$i" == get_cron_open_in:* ]]; then
|
||||||
with_get_cron_open_in="${i#get_cron_open_in:}"
|
with_get_cron_open_in="${i#get_cron_open_in:}"
|
||||||
|
elif [ $i = "get_schedule" ] && [[ $PIGARDENSCHED == "1" ]]; then
|
||||||
|
with_get_schedule="1"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
local json_ev=""
|
||||||
for i in $(seq $EV_TOTAL)
|
for i in $(seq $EV_TOTAL)
|
||||||
do
|
do
|
||||||
local a=EV"$i"_ALIAS
|
local a=EV"$i"_ALIAS
|
||||||
@@ -509,9 +573,14 @@ function json_status {
|
|||||||
if [ -n "$json" ]; then
|
if [ -n "$json" ]; then
|
||||||
json="$json,"
|
json="$json,"
|
||||||
fi
|
fi
|
||||||
json="$json\"$i\":{\"name\":\"$av\",\"state\":$sv}"
|
json="$json\"$av\":{\"name\":\"$av\",\"state\":$sv}"
|
||||||
|
|
||||||
|
if [ -n "$json_ev" ]; then
|
||||||
|
json_ev="$json_ev,"
|
||||||
|
fi
|
||||||
|
json_ev="$json_ev\"$a\":{\"alias\":\"$av\"}"
|
||||||
done
|
done
|
||||||
json="\"zones\":{$json}"
|
json="\"zones\":{$json},\"ev\":{$json_ev}"
|
||||||
|
|
||||||
local last_rain_sensor=`cat "$STATUS_DIR/last_rain_sensor" 2> /dev/null`
|
local last_rain_sensor=`cat "$STATUS_DIR/last_rain_sensor" 2> /dev/null`
|
||||||
local last_rain_online=`cat "$STATUS_DIR/last_rain_online" 2> /dev/null`
|
local last_rain_online=`cat "$STATUS_DIR/last_rain_online" 2> /dev/null`
|
||||||
@@ -520,15 +589,10 @@ function json_status {
|
|||||||
if [[ ! -z "$last_weather_online" ]]; then
|
if [[ ! -z "$last_weather_online" ]]; then
|
||||||
json_last_weather_online=$last_weather_online
|
json_last_weather_online=$last_weather_online
|
||||||
fi
|
fi
|
||||||
if [ -f "$LAST_INFO_FILE.$!" ]; then
|
|
||||||
last_info=`cat "$LAST_INFO_FILE.$!"`
|
last_info="$MESSAGE_INFO"
|
||||||
fi
|
last_warning="$MESSAGE_WARNING"
|
||||||
if [ -f "$LAST_WARNING_FILE.$!" ]; then
|
last_success="$MESSAGE_SUCCESS"
|
||||||
last_warning=`cat "$LAST_WARNING_FILE.$!"`
|
|
||||||
fi
|
|
||||||
if [ -f "$LAST_SUCCESS_FILE.$!" ]; then
|
|
||||||
last_success=`cat "$LAST_SUCCESS_FILE.$!"`
|
|
||||||
fi
|
|
||||||
local json_last_weather_online="\"last_weather_online\":$json_last_weather_online"
|
local json_last_weather_online="\"last_weather_online\":$json_last_weather_online"
|
||||||
local json_last_rain_sensor="\"last_rain_sensor\":\"$last_rain_sensor\""
|
local json_last_rain_sensor="\"last_rain_sensor\":\"$last_rain_sensor\""
|
||||||
local json_last_rain_online="\"last_rain_online\":\"$last_rain_online\""
|
local json_last_rain_online="\"last_rain_online\":\"$last_rain_online\""
|
||||||
@@ -569,6 +633,24 @@ function json_status {
|
|||||||
fi
|
fi
|
||||||
local json_cron="\"cron\":{$json_get_cron}"
|
local json_cron="\"cron\":{$json_get_cron}"
|
||||||
|
|
||||||
|
local json_get_schedule=""
|
||||||
|
local json_schedule=""
|
||||||
|
if [ $with_get_schedule != "0" ]; then
|
||||||
|
json_get_schedule=""
|
||||||
|
for scheduled in `$PIGARDENSCHED_PATH sched`
|
||||||
|
do
|
||||||
|
local ev=$(echo $scheduled|$CUT -f1 -d";")
|
||||||
|
local evcomplete="$ev"_ALIAS
|
||||||
|
local al=${!evcomplete}
|
||||||
|
local json_get_schedule="\"$ev\": {\"alias\": \"$al\", \"entry\": \"$scheduled\"}, $json_get_schedule"
|
||||||
|
done
|
||||||
|
if [[ ! -z $json_get_schedule ]]; then
|
||||||
|
json_get_schedule="${json_get_schedule::-2}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local json_schedule=", \"schedule\":{$json_get_schedule}"
|
||||||
|
fi
|
||||||
|
|
||||||
local json_get_cron_open_in=""
|
local json_get_cron_open_in=""
|
||||||
if [ $with_get_cron_open_in != "0" ]; then
|
if [ $with_get_cron_open_in != "0" ]; then
|
||||||
local values_open_in=""
|
local values_open_in=""
|
||||||
@@ -601,8 +683,9 @@ function json_status {
|
|||||||
json_get_cron_open_in="\"open_in\": {$values_open_in},\"open_in_stop\": {$values_open_in_stop}"
|
json_get_cron_open_in="\"open_in\": {$values_open_in},\"open_in_stop\": {$values_open_in_stop}"
|
||||||
fi
|
fi
|
||||||
local json_cron_open_in="\"cron_open_in\":{$json_get_cron_open_in}"
|
local json_cron_open_in="\"cron_open_in\":{$json_get_cron_open_in}"
|
||||||
|
local json_timestamp="\"timestamp\": $(date +%s)"
|
||||||
|
|
||||||
json="{$json_version,$json,$json_last_weather_online,$json_error,$json_last_info,$json_last_warning,$json_last_success,$json_last_rain_online,$json_last_rain_sensor,$json_cron,$json_cron_open_in}"
|
json="{$json_version,$json_timestamp,$json_event,$json,$json_last_weather_online,$json_error,$json_last_info,$json_last_warning,$json_last_success,$json_last_rain_online,$json_last_rain_sensor,$json_cron,$json_cron_open_in $json_schedule}"
|
||||||
|
|
||||||
echo "$json"
|
echo "$json"
|
||||||
|
|
||||||
@@ -610,6 +693,26 @@ function json_status {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Invia al broker mqtt il json contentente lo stato del sistema
|
||||||
|
#
|
||||||
|
# $1 parent pid (opzionale)
|
||||||
|
#
|
||||||
|
function mqtt_status {
|
||||||
|
|
||||||
|
if [ ! $MQTT_ENABLE -eq 1 ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -z "$1" ]; then
|
||||||
|
PARENT_PID=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local js=$(json_status)
|
||||||
|
$MOSQUITTO_PUB -h $MQTT_HOST -p $MQTT_PORT -u $MQTT_USER -P $MQTT_PWD -i $MQTT_CLIENT_ID -r -t "$MQTT_TOPIC" -m "$js"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Mostra il i parametri dello script
|
# Mostra il i parametri dello script
|
||||||
#
|
#
|
||||||
@@ -624,7 +727,8 @@ function show_usage {
|
|||||||
echo -e "\t$NAME_SCRIPT list_alias view list of aliases solenoid"
|
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 alias show status solenoid"
|
||||||
echo -e "\t$NAME_SCRIPT ev_status_all show status solenoids"
|
echo -e "\t$NAME_SCRIPT ev_status_all show status solenoids"
|
||||||
echo -e "\t$NAME_SCRIPT json_status [get_cron|get_cron_open_in] show status in json format"
|
echo -e "\t$NAME_SCRIPT json_status [get_cron|get_cron_open_in|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 "\t$NAME_SCRIPT check_rain_online check rain from http://api.wunderground.com/"
|
||||||
echo -e "\t$NAME_SCRIPT check_rain_sensor check rain from hardware sensor"
|
echo -e "\t$NAME_SCRIPT check_rain_sensor check rain from hardware sensor"
|
||||||
echo -e "\t$NAME_SCRIPT close_all_for_rain close all solenoid if it's raining"
|
echo -e "\t$NAME_SCRIPT close_all_for_rain close all solenoid if it's raining"
|
||||||
@@ -655,6 +759,8 @@ function show_usage {
|
|||||||
echo -e "\t$NAME_SCRIPT del_cron_close alias remove all crontab for close a solenoid"
|
echo -e "\t$NAME_SCRIPT del_cron_close alias remove all crontab for close a solenoid"
|
||||||
echo -e "\t$NAME_SCRIPT get_cron_close alias get all crontab for close a solenoid"
|
echo -e "\t$NAME_SCRIPT get_cron_close alias get all crontab for close a solenoid"
|
||||||
echo -e "\n"
|
echo -e "\n"
|
||||||
|
echo -e "\t$NAME_SCRIPT cmd_pigardensched [prm1 [prm2 [prm3]...]] performs a pigardensched command"
|
||||||
|
echo -e "\n"
|
||||||
echo -e "\t$NAME_SCRIPT debug1 [parameter]|[parameter]|..] Run debug code 1"
|
echo -e "\t$NAME_SCRIPT debug1 [parameter]|[parameter]|..] Run debug code 1"
|
||||||
echo -e "\t$NAME_SCRIPT debug2 [parameter]|[parameter]|..] Run debug code 2"
|
echo -e "\t$NAME_SCRIPT debug2 [parameter]|[parameter]|..] Run debug code 2"
|
||||||
}
|
}
|
||||||
@@ -693,12 +799,12 @@ function lock {
|
|||||||
local foo=bar
|
local foo=bar
|
||||||
else
|
else
|
||||||
if [ "$current_time" -gt "$max_time" ]; then
|
if [ "$current_time" -gt "$max_time" ]; then
|
||||||
log_write "Maximum locked time reached"
|
log_write "general" "error" "Maximum locked time reached"
|
||||||
sleep $max_time
|
sleep $max_time
|
||||||
unlock
|
unlock
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
log_write "Sleep 1 second for locked state"
|
log_write "general" "info" "Sleep 1 second for locked state"
|
||||||
sleep 1
|
sleep 1
|
||||||
lock $current_time
|
lock $current_time
|
||||||
return
|
return
|
||||||
@@ -747,7 +853,7 @@ function send_identifier {
|
|||||||
fi
|
fi
|
||||||
echo "$ID" > "$FILE_ID"
|
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
|
$CURL https://www.lejubila.net/statistic/collect_usage/piGarden/$ID/$VERSION/$SUB_VERSION/$RELEASE_VERSION > /dev/null 2>&1
|
||||||
|
|
||||||
@@ -757,19 +863,135 @@ function send_identifier {
|
|||||||
# Spenge il sistema
|
# Spenge il sistema
|
||||||
#
|
#
|
||||||
function exec_poweroff {
|
function exec_poweroff {
|
||||||
|
trigger_event "exec_poweroff_before"
|
||||||
local PATH_SCRIPT=`$READLINK -f "$DIR_SCRIPT/scripts/poweroff.sh"`
|
local PATH_SCRIPT=`$READLINK -f "$DIR_SCRIPT/scripts/poweroff.sh"`
|
||||||
echo "$PATH_SCRIPT" > tmp/prova.txt
|
|
||||||
sleep 15
|
sleep 15
|
||||||
. $PATH_SCRIPT
|
. $PATH_SCRIPT
|
||||||
|
trigger_event "exec_poweroff_after"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Spenge il sistema
|
# Spenge il sistema
|
||||||
#
|
#
|
||||||
function exec_reboot {
|
function exec_reboot {
|
||||||
|
trigger_event "exec_reboot_before"
|
||||||
local PATH_SCRIPT=`$READLINK -f "$DIR_SCRIPT/scripts/reboot.sh"`
|
local PATH_SCRIPT=`$READLINK -f "$DIR_SCRIPT/scripts/reboot.sh"`
|
||||||
sleep 15
|
sleep 15
|
||||||
. $PATH_SCRIPT
|
. $PATH_SCRIPT
|
||||||
|
trigger_event "exec_reboot_after"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Esegue un comando con piGardenSched
|
||||||
|
#
|
||||||
|
# $1 parametro 1
|
||||||
|
# $2 parametro 2
|
||||||
|
# $3 parametro 3
|
||||||
|
# $4 parametro 4
|
||||||
|
# $5 parametro 5
|
||||||
|
|
||||||
|
function cmd_pigardensched {
|
||||||
|
local foo="bar"
|
||||||
|
|
||||||
|
if [ $PIGARDENSCHED == 0 ]; then
|
||||||
|
echo "piGardenSched not configured in piGarden" >&2
|
||||||
|
log_write "piGardenSched" "error" "piGardenSched not configured in piGarden"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
$PIGARDENSCHED_PATH $1 $2 $3 $4 $5
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "piGardenSched command failed"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Converte da gradi a direzione
|
||||||
|
#
|
||||||
|
# $1 gradi
|
||||||
|
#
|
||||||
|
function deg2dir {
|
||||||
|
local deg=$(echo $1 | $SED 's/\..*$//')
|
||||||
|
local dir=""
|
||||||
|
|
||||||
|
if [ "$deg" == "null" ]; then
|
||||||
|
echo ""
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# N 348.75 - 11.25
|
||||||
|
if [ $deg -le 11 ]; then
|
||||||
|
dir="North"
|
||||||
|
|
||||||
|
# NNE 11.25 - 33.75
|
||||||
|
elif [ $deg -le 33 ]; then
|
||||||
|
dir="NNE"
|
||||||
|
|
||||||
|
# NE 33.75 - 56.25
|
||||||
|
elif [ $deg -le 56 ]; then
|
||||||
|
dir="NE"
|
||||||
|
|
||||||
|
# ENE 56.25 - 78.75
|
||||||
|
elif [ $deg -le 78 ]; then
|
||||||
|
dir="ENE"
|
||||||
|
|
||||||
|
# E 78.75 - 101.25
|
||||||
|
elif [ $deg -le 101 ]; then
|
||||||
|
dir="East"
|
||||||
|
|
||||||
|
# ESE 101.25 - 123.75
|
||||||
|
elif [ $deg -le 123 ]; then
|
||||||
|
dir="ESE"
|
||||||
|
|
||||||
|
# SE 123.75 - 146.25
|
||||||
|
elif [ $deg -le 146 ]; then
|
||||||
|
dir="SE"
|
||||||
|
|
||||||
|
# SSE 146.25 - 168.75
|
||||||
|
elif [ $deg -le 168 ]; then
|
||||||
|
dir="SSE"
|
||||||
|
|
||||||
|
# S 168.75 - 191.25
|
||||||
|
elif [ $deg -le 191 ]; then
|
||||||
|
dir="South"
|
||||||
|
|
||||||
|
# SSW 191.25 - 213.75
|
||||||
|
elif [ $deg -le 213 ]; then
|
||||||
|
dir="SSW"
|
||||||
|
|
||||||
|
# SW 213.75 - 236.25
|
||||||
|
elif [ $deg -le 236 ]; then
|
||||||
|
dir="SW"
|
||||||
|
|
||||||
|
# WSW 236.25 - 258.75
|
||||||
|
elif [ $deg -le 258 ]; then
|
||||||
|
dir="WSW"
|
||||||
|
|
||||||
|
# W 258.75 - 281.25
|
||||||
|
elif [ $deg -le 281 ]; then
|
||||||
|
dir="West"
|
||||||
|
|
||||||
|
# WNW 281.25 - 303.75
|
||||||
|
elif [ $deg -le 303 ]; then
|
||||||
|
dir="WNW"
|
||||||
|
|
||||||
|
# NW 303.75 - 326.25
|
||||||
|
elif [ $deg -le 326 ]; then
|
||||||
|
dir="NW"
|
||||||
|
|
||||||
|
# NNW 326.25 - 348.75
|
||||||
|
elif [ $deg -le 348 ]; then
|
||||||
|
dir="NNW"
|
||||||
|
|
||||||
|
# N 348.75 - 11.25
|
||||||
|
else
|
||||||
|
dir="North"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $dir
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function debug1 {
|
function debug1 {
|
||||||
@@ -781,7 +1003,7 @@ function debug2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VERSION=0
|
VERSION=0
|
||||||
SUB_VERSION=5
|
SUB_VERSION=6
|
||||||
RELEASE_VERSION=1
|
RELEASE_VERSION=1
|
||||||
|
|
||||||
DIR_SCRIPT=`dirname $0`
|
DIR_SCRIPT=`dirname $0`
|
||||||
@@ -810,18 +1032,33 @@ fi
|
|||||||
. "$DIR_SCRIPT/include/rain.include.sh"
|
. "$DIR_SCRIPT/include/rain.include.sh"
|
||||||
. "$DIR_SCRIPT/include/events.include.sh"
|
. "$DIR_SCRIPT/include/events.include.sh"
|
||||||
|
|
||||||
LAST_INFO_FILE="$STATUS_DIR/last_info"
|
MESSAGE_INFO=""
|
||||||
LAST_WARNING_FILE="$STATUS_DIR/last_warning"
|
MESSAGE_WARNING=""
|
||||||
LAST_SUCCESS_FILE="$STATUS_DIR/last_success"
|
MESSAGE_SUCCESS=""
|
||||||
|
|
||||||
|
CURRENT_EVENT=""
|
||||||
|
CURRENT_EVENT_ALIAS=""
|
||||||
|
|
||||||
|
PARENT_PID=0
|
||||||
|
|
||||||
if [ -z $LOG_OUTPUT_DRV_FILE ]; then
|
if [ -z $LOG_OUTPUT_DRV_FILE ]; then
|
||||||
$LOG_OUTPUT_DRV_FILE="/dev/null"
|
LOG_OUTPUT_DRV_FILE="/dev/null"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$EVENT_DIR" ]; then
|
if [ -z "$EVENT_DIR" ]; then
|
||||||
EVENT_DIR="$DIR_SCRIPT/events"
|
EVENT_DIR="$DIR_SCRIPT/events"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z $WEATHER_SERVICE ]; then
|
||||||
|
WEATHER_SERVICE="drv:wunderground"
|
||||||
|
elif [ "$WEATHER_SERVICE" != "none" ]; then
|
||||||
|
WEATHER_SERVICE="drv:$WEATHER_SERVICE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
PIGARDENSCHED="0"
|
||||||
|
if [[ -x "$PIGARDENSCHED_PATH" ]]; then
|
||||||
|
PIGARDENSCHED="1"
|
||||||
|
fi
|
||||||
|
|
||||||
# Elimina il file di lock se più vecchio di 11 secondi
|
# Elimina il file di lock se più vecchio di 11 secondi
|
||||||
if [ -f "$LOCK_FILE" ]; then
|
if [ -f "$LOCK_FILE" ]; then
|
||||||
@@ -836,6 +1073,8 @@ fi
|
|||||||
send_identifier &
|
send_identifier &
|
||||||
setup_drv
|
setup_drv
|
||||||
|
|
||||||
|
#echo "EV_MONOSTABLE=$EV_MONOSTABLE"
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
init)
|
init)
|
||||||
initialize
|
initialize
|
||||||
@@ -876,6 +1115,10 @@ case "$1" in
|
|||||||
json_status $2 $3 $4 $5 $6
|
json_status $2 $3 $4 $5 $6
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
mqtt_status)
|
||||||
|
mqtt_status $2
|
||||||
|
;;
|
||||||
|
|
||||||
check_rain_online)
|
check_rain_online)
|
||||||
check_rain_online
|
check_rain_online
|
||||||
;;
|
;;
|
||||||
@@ -907,7 +1150,7 @@ case "$1" in
|
|||||||
nohup $0 start_socket_server_daemon > /dev/null 2>&1 &
|
nohup $0 start_socket_server_daemon > /dev/null 2>&1 &
|
||||||
|
|
||||||
echo "Daemon is started widh pid $!"
|
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)
|
start_socket_server_daemon)
|
||||||
@@ -990,6 +1233,10 @@ case "$1" in
|
|||||||
get_cron_close $2
|
get_cron_close $2
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
cmd_pigardensched)
|
||||||
|
cmd_pigardensched $2 $3 $4 $5
|
||||||
|
;;
|
||||||
|
|
||||||
reboot)
|
reboot)
|
||||||
exec_reboot
|
exec_reboot
|
||||||
;;
|
;;
|
||||||
@@ -1017,4 +1264,4 @@ esac
|
|||||||
rm "$TMP_CRON_FILE" 2> /dev/null
|
rm "$TMP_CRON_FILE" 2> /dev/null
|
||||||
rm "$TMP_CRON_FILE-2" 2> /dev/null
|
rm "$TMP_CRON_FILE-2" 2> /dev/null
|
||||||
|
|
||||||
reset_messages &> /dev/null
|
#reset_messages &> /dev/null
|
||||||
|
|||||||
Reference in New Issue
Block a user