|
@@ -0,0 +1,83 @@
|
|
|
|
|
+#!/bin/bash
|
|
|
|
|
+linea=$1
|
|
|
|
|
+tempo=$2
|
|
|
|
|
+
|
|
|
|
|
+linea_cisterna=10
|
|
|
|
|
+linea_pozzo=11
|
|
|
|
|
+
|
|
|
|
|
+data=$(date)
|
|
|
|
|
+
|
|
|
|
|
+log=$(mktemp)
|
|
|
|
|
+
|
|
|
|
|
+if [ __${tempo}__ == ____ ] ; then
|
|
|
|
|
+ echo "non e' stato indicato il tempo, si va in automatico" | tee ${log}
|
|
|
|
|
+ tempo=30s
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
|
|
+irrigatore=0
|
|
|
|
|
+cisterna=0
|
|
|
|
|
+pozzo=0
|
|
|
|
|
+
|
|
|
|
|
+if [ -f ~/script/irrigatore ]; then irrigatore=1; fi
|
|
|
|
|
+if [ -f ~/script/cisterna ]; then cisterna=1; fi
|
|
|
|
|
+if [ -f ~/script/pozzo ]; then pozzo=1; fi
|
|
|
|
|
+
|
|
|
|
|
+echo "stato irrigatore: ${irrigatore}"
|
|
|
|
|
+echo "stato cisterna : ${cisterna}"
|
|
|
|
|
+echo "stato pozzo : ${pozzo}"
|
|
|
|
|
+
|
|
|
|
|
+echo "data : ${data}" |tee -a ${log}
|
|
|
|
|
+echo "linea : ${linea}" |tee -a ${log}
|
|
|
|
|
+echo ""
|
|
|
|
|
+echo "linea_cisterna: ${linea_cisterna}" |tee -a ${log}
|
|
|
|
|
+echo "linea_pozzo : ${linea_pozzo}" | tee -a ${log}
|
|
|
|
|
+echo ""
|
|
|
|
|
+echo "tempo : ${tempo}" |tee -a ${log}
|
|
|
|
|
+echo ""
|
|
|
|
|
+
|
|
|
|
|
+# verifica la presenza del file "irrigatore"
|
|
|
|
|
+if [ ${irrigatore} == 1 ]; then
|
|
|
|
|
+ echo "File 'irrigatore' presente" | tee ${log}
|
|
|
|
|
+ echo "Apro valvola ${linea} per ${tempo}" | tee ${log}
|
|
|
|
|
+ raspi-gpio set ${linea} dl
|
|
|
|
|
+ mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"irrigatore\":${linea},\"status\":$(pinctrl lev ${linea})}"
|
|
|
|
|
+
|
|
|
|
|
+ if [ ${cisterna} == 1 ]; then
|
|
|
|
|
+ echo "Accendo cisterna ${linea_cisterna}" | tee ${log}
|
|
|
|
|
+ raspi-gpio set ${linea_cisterna} dl
|
|
|
|
|
+ mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"cisterna\":${linea_cisterna},\"status\":$(pinctrl lev ${linea_cisterna})}"
|
|
|
|
|
+ fi
|
|
|
|
|
+ if [ ${pozzo} == 1 ]; then
|
|
|
|
|
+ echo "Accendo pozzo ${linea_pozzo}" | tee ${log}
|
|
|
|
|
+ raspi-gpio set ${linea_pozzo} dl
|
|
|
|
|
+ mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"pozzo\":${linea_pozzo},\"status\":$(pinctrl lev ${linea_pozzo})}"
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"tempo\":${pompa},\"status\":${tempo})}"
|
|
|
|
|
+ sleep ${tempo}
|
|
|
|
|
+
|
|
|
|
|
+ if [ ${pozzo} == 1 ]; then
|
|
|
|
|
+ echo "Spengo pozzo ${linea_pozzo}" | tee ${log}
|
|
|
|
|
+ raspi-gpio set ${linea_pozzo} dh
|
|
|
|
|
+ mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"pozzo\":${linea_pozzo},\"status\":$(pinctrl lev ${linea_pozzo})}"
|
|
|
|
|
+
|
|
|
|
|
+ if [ ${cisterna} == 1 ]; then
|
|
|
|
|
+ echo "Spengo cisterna ${linea_cisterna}" | tee ${log}
|
|
|
|
|
+ raspi-gpio set ${linea_cisterna} dh
|
|
|
|
|
+ mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"cisterna\":${linea_cisterna},\"status\":$(pinctrl lev ${linea_cisterna})}"
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ echo "Chiudo linea ${linea}" | tee ${log}
|
|
|
|
|
+ raspi-gpio set ${linea} dh
|
|
|
|
|
+ mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"irrigatore\":${linea},\"status\":$(pinctrl lev ${linea})}"
|
|
|
|
|
+else
|
|
|
|
|
+ echo -e "Accensione linea ${linea} per ${tempo}\nDisattivata: manca file 'irrigatore' in home" | tee ${log}
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
|
|
+cat ${log} | mail -s "${data}: linea ${linea} per ${tempo}" root
|
|
|
|
|
+rm ${log}
|
|
|
|
|
+
|
|
|
|
|
+#dl lo attiva
|
|
|
|
|
+#dh lo disattiva
|
|
|
|
|
+#op abilita la linea
|
|
|
|
|
+
|