run.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. linea=$1
  3. tempo=$2
  4. linea_cisterna=10
  5. linea_pozzo=11
  6. data=$(date)
  7. log=$(mktemp)
  8. if [ __${tempo}__ == ____ ] ; then
  9. echo "non e' stato indicato il tempo, si va in automatico" | tee ${log}
  10. tempo=30s
  11. fi
  12. irrigatore=0
  13. cisterna=0
  14. pozzo=0
  15. if [ -f ~/script/irrigatore ]; then irrigatore=1; fi
  16. if [ -f ~/script/cisterna ]; then cisterna=1; fi
  17. if [ -f ~/script/pozzo ]; then pozzo=1; fi
  18. echo "stato irrigatore: ${irrigatore}"
  19. echo "stato cisterna : ${cisterna}"
  20. echo "stato pozzo : ${pozzo}"
  21. echo "data : ${data}" |tee -a ${log}
  22. echo "linea : ${linea}" |tee -a ${log}
  23. echo ""
  24. echo "linea_cisterna: ${linea_cisterna}" |tee -a ${log}
  25. echo "linea_pozzo : ${linea_pozzo}" | tee -a ${log}
  26. echo ""
  27. echo "tempo : ${tempo}" |tee -a ${log}
  28. echo ""
  29. # verifica la presenza del file "irrigatore"
  30. if [ ${irrigatore} == 1 ]; then
  31. echo "File 'irrigatore' presente" | tee ${log}
  32. echo "Apro valvola ${linea} per ${tempo}" | tee ${log}
  33. raspi-gpio set ${linea} dl
  34. mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"irrigatore\":${linea},\"status\":$(pinctrl lev ${linea})}"
  35. if [ ${cisterna} == 1 ]; then
  36. echo "Accendo cisterna ${linea_cisterna}" | tee ${log}
  37. raspi-gpio set ${linea_cisterna} dl
  38. mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"cisterna\":${linea_cisterna},\"status\":$(pinctrl lev ${linea_cisterna})}"
  39. fi
  40. if [ ${pozzo} == 1 ]; then
  41. echo "Accendo pozzo ${linea_pozzo}" | tee ${log}
  42. raspi-gpio set ${linea_pozzo} dl
  43. mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"pozzo\":${linea_pozzo},\"status\":$(pinctrl lev ${linea_pozzo})}"
  44. fi
  45. mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"tempo\":${pompa},\"status\":${tempo})}"
  46. sleep ${tempo}
  47. if [ ${pozzo} == 1 ]; then
  48. echo "Spengo pozzo ${linea_pozzo}" | tee ${log}
  49. raspi-gpio set ${linea_pozzo} dh
  50. mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"pozzo\":${linea_pozzo},\"status\":$(pinctrl lev ${linea_pozzo})}"
  51. if [ ${cisterna} == 1 ]; then
  52. echo "Spengo cisterna ${linea_cisterna}" | tee ${log}
  53. raspi-gpio set ${linea_cisterna} dh
  54. mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"cisterna\":${linea_cisterna},\"status\":$(pinctrl lev ${linea_cisterna})}"
  55. fi
  56. echo "Chiudo linea ${linea}" | tee ${log}
  57. raspi-gpio set ${linea} dh
  58. mosquitto_pub -h nuc1 -p 1883 -u sword -P "Abcd.1234" -t "Status" -m "{\"irrigatore\":${linea},\"status\":$(pinctrl lev ${linea})}"
  59. else
  60. echo -e "Accensione linea ${linea} per ${tempo}\nDisattivata: manca file 'irrigatore' in home" | tee ${log}
  61. fi
  62. cat ${log} | mail -s "${data}: linea ${linea} per ${tempo}" root
  63. rm ${log}
  64. #dl lo attiva
  65. #dh lo disattiva
  66. #op abilita la linea