#!/bin/bash linea=$1 tempo=$2 pompasi=1 pompa=10 data=$(date) log=$(mktemp) if [ __${tempo}__ == ____ ] ; then echo "non e' stato indicato il tempo, si va in automatico" | tee ${log} tempo=30s fi echo "data : ${data}" |tee -a ${log} echo "linea: ${linea}" |tee -a ${log} echo "pompa: ${pompa}" |tee -a ${log} echo "tempo: ${tempo}" |tee -a ${log} echo "" # verifica la presenza del file "irrigatore" if [ -f ~/script/irrigatore ]; then echo "File 'irrigatore' presente" | tee ${log} echo "Apro valvola ${linea} per ${tempo}" | tee ${log} raspi-gpio set ${linea} dl mosquitto_pub -h nuc -p 1883 -u swarn -P "Abcd.1234" -t "Status" -m "{\"irrigatore\":${linea},\"status\":$(pinctrl lev ${linea})}" if [ ${pompasi} == 1 ]; then echo "Accendo pompa ${pompa}" | tee ${log} raspi-gpio set ${pompa} dl mosquitto_pub -h nuc -p 1883 -u swarn -P "Abcd.1234" -t "Status" -m "{\"pompa\":${pompa},\"status\":$(pinctrl lev ${pompa})}" fi mosquitto_pub -h nuc -p 1883 -u swarn -P "Abcd.1234" -t "Status" -m "{\"tempo\":${pompa},\"status\":${tempo})}" sleep ${tempo} if [ ${pompasi} == 1 ]; then echo "Spengo pompa ${pompa}" | tee ${log} raspi-gpio set ${pompa} dh mosquitto_pub -h nuc -p 1883 -u swarn -P "Abcd.1234" -t "Status" -m "{\"pompa\":${pompa},\"status\":$(pinctrl lev ${pompa})}" fi echo "Chiudo valvola ${linea}" | tee ${log} raspi-gpio set ${linea} dh mosquitto_pub -h nuc -p 1883 -u swarn -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