Bladeren bron

nuove versioni dello script di irrigazione

mauro 2 dagen geleden
bovenliggende
commit
ac20639e4e
7 gewijzigde bestanden met toevoegingen van 196 en 4 verwijderingen
  1. 18 0
      all.sh
  2. 0 0
      irrigatore
  3. 158 0
      po.sh
  4. 0 0
      pozzo
  5. 6 4
      pozzo.sh
  6. 7 0
      programma.txt
  7. 7 0
      test.txt

+ 18 - 0
all.sh

@@ -0,0 +1,18 @@
+#!/bin/bash
+cd /home/mauro/script
+
+bash /home/mauro/script/linea.sh 4 20m
+sleep 10
+bash /home/mauro/script/linea.sh 5 20m
+sleep 10
+bash /home/mauro/script/pozzo.sh 9 15m
+sleep 10
+bash /home/mauro/script/linea.sh 6 10m
+sleep 10
+bash /home/mauro/script/linea.sh 7 10m
+sleep 10
+bash /home/mauro/script/linea.sh 8 10m
+sleep 10
+bash /home/mauro/script/pozzo.sh 9 15m
+sleep 10
+

+ 0 - 0
irrigatore


+ 158 - 0
po.sh

@@ -0,0 +1,158 @@
+#!/bin/bash
+
+nomefileprogramma=$1
+
+#pompacirsterna, si riferisce alla sola pompa nella cisterna
+pompacisternasi=1
+pompacisterna=10
+
+#pompapozzo si riferisce alla pompa del pozzo
+pompapozzosi=1
+pompapozzo=11
+
+#valvolaingresso,  che consente il caricamento della cisterna dalla linea 
+# pubblica o dal pozzo se quest'ultimo viene avviato
+valvolaingresso=9
+
+etichettapozzo="~/script/pozzo"
+etichettairrigatore="~/script/irrigatore"
+
+data=$(date)
+
+log=$(mktemp)
+
+###########################
+status() {
+  echo "status porte" | tee -a  ${log}
+  raspi-gpio get 4,5,6,7,8,9,10,11 | tee -a  ${log}
+}
+###########################
+apri() {
+  alinea=$1
+  echo "Apro pin ${alinea}"  | tee -a  ${log}
+  raspi-gpio get ${alinea}
+  raspi-gpio set ${alinea} dl 
+  raspi-gpio get ${alinea}
+  mosquitto_pub -h nuc1 -p 1883 -u sword  -P "Abcd.1234" -t "Status" -m "{\"linea\":${alinea},\"status\":$(pinctrl lev ${alinea})}"
+}
+###########################
+chiudi() {
+  clinea=$1 
+  echo "Chiudo pin ${clinea}" | tee -a  ${log}
+  raspi-gpio get ${clinea}
+  raspi-gpio set ${clinea} dh
+  raspi-gpio get ${clinea}
+  mosquitto_pub -h nuc1 -p 1883 -u sword  -P "Abcd.1234" -t "Status" -m "{\"linea\":${clinea},\"status\":$(pinctrl lev ${clinea})}"
+}
+##########################
+esecuzione() {
+  o=$1
+  linea=$2
+  tempo=$3
+
+  if [ __${tempo}__ == ____ ] ; then
+    echo "non e' stato indicato il tempo, si va in automatico" | tee -a  ${log}
+    tempo=30s
+  fi
+
+echo "#############################"
+echo "data : ${data}"  |tee -a ${log}
+echo "rich : ${o}"     |tee -a ${log}
+echo "linea: ${linea}" |tee -a ${log}
+echo "tempo: ${tempo}" |tee -a ${log}
+echo "" |tee -a ${log}
+
+if [ __${o}__ == __i__ ]; then
+  echo "Richiesta attivazione irrigatore"
+
+  # verifica la presenza del file "${etichettairrigatore}" 
+  if [ -f ${etichettairrigatore}  ]; then 
+    echo "File 'irrigatore' presente" | tee -a  ${log}
+    echo "Apro linea ${linea} per ${tempo}"  | tee -a  ${log}
+    apri ${linea}
+
+    if [ ${pompacisternasi} == 1 ]; then
+      echo "Accendo pompa ${pompacisterna}" | tee -a  ${log}
+      apri ${pompacisterna}
+    fi
+
+    mosquitto_pub -h nuc1 -p 1883 -u sword  -P "Abcd.1234" -t "Status" -m "{\"tempo\":${pompa},\"status\":${tempo})}"
+    sleep ${tempo}
+
+    if [ ${pompacisternasi} == 1 ]; then
+      echo "Spengo pompa ${pompacisterna}" | tee -a  ${log}
+      chiudi ${pompacisterna}
+    fi
+
+    echo "Chiudo linea ${linea}" | tee -a  ${log}
+    chiudi ${linea}
+  else
+    echo -e "Accensione linea ${linea} per ${tempo}\nDisattivata: manca file '${etichettairrigatore}'." | tee -a ${log}
+  fi
+fi
+
+if [ __${o}__ == __p__ ]; then
+  echo "Richiesta attivazione pozzo"
+
+  if [ -f ${etichettapozzo} ]; then
+    echo "File '${etichettapozzo}' presente" |tee -a ${log}
+
+    echo "Apro valvola ${valvolaingresso}"  |tee -a  ${log}
+    apri ${valvolaingresso}
+
+    if [ ${pompapozzosi} == 1 ]; then
+      echo "Accendo pompa ${pompapozzo}" |tee -a  ${log}
+      apri ${pompapozzo}
+    fi
+
+    mosquitto_pub -h nuc1 -p 1883 -u sword  -P "Abcd.1234" -t "Status" -m "{\"tempo\":${pompa},\"status\":${tempo})}"
+    sleep ${tempo}
+
+    if [ ${pompapozzosi} == 1 ]; then
+      echo "Spengo pompa ${pompapozzo}" |tee -a  ${log}
+      chiudi ${pompapozzo}
+    fi
+
+    echo "Chiudo valvola ${linea}" |tee -a  ${log}
+    chiudi ${valvolaingresso}
+
+  else
+    echo -e "Accensione pompa pozzo ${pompapozzo} per ${tempo}\nDisattivata: manca file '${etichettapozzo}'." |tee -a ${log}
+  fi
+fi
+
+#dl lo attiva
+#dh lo disattiva
+#op abilita la linea
+}
+
+############################################
+
+if [ __${nomefileprogramma}__ == ____ ]; then
+  nomefileprogramma="programma.txt"
+  echo "nome file non indicato, inserito default ${nomefileprogramma}" | tee -a ${log}
+fi 
+
+echo "Lettura file ${nomefileprogramma}" | tee -a ${log}
+
+if [ ! -f ${nomefileprogramma} ]; then
+  echo "il file con la programmazione '${nomefileprogramma}' non esiste" | tee -a ${log}
+  exit 99
+fi
+
+status
+
+while read -u 10 -r o l t; do
+  echo $o $l $t 
+  esecuzione $o $l $t  
+  sleep 5
+done 10<${nomefileprogramma}
+
+status
+
+cat ${log} | mail -s "${data}: linea ${linea} per ${tempo}" root
+rm ${log}
+
+###########################
+
+

+ 0 - 0
pozzo


+ 6 - 4
pozzo.sh

@@ -12,10 +12,11 @@ lineadefault=9
 
 # poppa abilitata
 pompasi=1
+
 # pompa del pozzo
 pompa=11
 
-tempodefault=30m
+tempodefault=15m
 
 log=$(mktemp)
 
@@ -35,8 +36,9 @@ echo "pompa: ${pompa}" |tee -a ${log}
 echo "tempo: ${tempo}" |tee -a ${log}
 echo ""
 
-# verifica la presenza del file "pompa" |tee -a ${log}
-if [ -f  ~/script/pompa ]; then 
+# verifica la presenza del file "pozzo" |tee -a ${log}
+
+if [ -f  ~/script/pozzo ]; then 
   echo "File 'pompa' presente" |tee -a ${log}
   echo "Apro valvola ${linea}"  |tee -a ${log}
   raspi-gpio set ${linea} dl 
@@ -63,7 +65,7 @@ if [ -f  ~/script/pompa ]; then
   mosquitto_pub -h nuc1 -p 1883 -u sword  -P "Abcd.1234" -t "Status" -m "{\"valvola\":${linea},\"status\":$(pinctrl lev ${linea})}"
 
 else
-  echo -e "Accensione linea ${linea} per ${tempo}\nDisattivata: manca file 'irrigatore' in home" |tee -a ${log}
+  echo -e "Accensione linea ${linea} per ${tempo}\nDisattivata: manca file 'pozzo' in home" |tee -a ${log}
 fi
 
 cat ${log} | mail -s "${data}: linea ${linea} per ${tempo}" root

+ 7 - 0
programma.txt

@@ -0,0 +1,7 @@
+i 4 20m
+i 5 20m
+p 9 15m
+i 6 10m
+i 7 10m
+i 8 10m
+p 9 15m

+ 7 - 0
test.txt

@@ -0,0 +1,7 @@
+i 4 5s
+i 5 5s
+p 9 5s
+i 6 5s
+i 7 5s
+i 8 5s
+p 9 5s