Browse Source

modificato go.sh, ora consente di attivare l'avvio della pompa subito dopo l'apertura della linea di irrigazione.
andra' ulteriormente modificato per includere la pompa del pozzo e le varie elettrovalvole previste.
Sicuramente andra' ampliato il valo porta raspberry... (gia' previsto)

mauro 5 months ago
parent
commit
3832d45151
4 changed files with 84 additions and 3 deletions
  1. 14 2
      go.sh
  2. 0 0
      irrigatore
  3. 61 0
      mqtt.cli.py
  4. 9 1
      start.sh

+ 14 - 2
go.sh

@@ -2,6 +2,9 @@
 linea=$1
 tempo=$2
 
+pompasi=0
+pompa=10
+
 log=$(mktemp)
 
 if [ __${tempo}__ == ____ ] ; then
@@ -12,11 +15,19 @@ fi
 # verifica la presenza del file "irrigatore" >> ${log}
 if [ -f  ~/script/irrigatore ]; then 
   echo "File 'irrigatore' presente" >> ${log}
-  echo "Accensione linea ${linea} per ${tempo}"  >> ${log}
+  echo "Apertura valvola ${linea} per ${tempo}"  >> ${log}
   raspi-gpio set ${linea} dl 
+  if [ ${pompasi} == 1 ]; then
+    echo "Accensione pompa ${pompa}" >> ${log}
+    raspi-gpio set ${pompa} dl
+  fi
   sleep ${tempo}
+  if [ ${pompasi} == 1 ]; then
+    echo "Spengo pompa ${pompa}" >> ${log}
+    raspi-gpio set ${pompa} dh
+  fi
+  echo "Chiusura valvola ${linea}" >> ${log}
   raspi-gpio set ${linea} dh
-  echo "Spegnimento linea ${linea}" >> ${log}
 else
   echo "Accensione linea ${linea} per ${tempo}\nDisattivata: manca file 'irrigatore' in home" >> ${log}
 fi
@@ -27,3 +38,4 @@ rm ${log}
 #dl lo attiva
 #dh lo disattiva
 #op abilita la linea
+

+ 0 - 0
irrigatore


+ 61 - 0
mqtt.cli.py

@@ -0,0 +1,61 @@
+#!/usr/bin/env python3
+
+import paho.mqtt.client as mqtt
+import RPi.GPIO as GPIO
+import datetime
+import time
+import json
+
+def on_connect(client, userdata, flags, reason_code, properties):
+  print('connesso',reason_code)
+  client.subscribe('sensor/+',0)
+  client.subscribe('message/+',0)
+  client.subscribe('request/+',0)
+  client.subscribe('Irrigatore/#',0)
+  client.subscribe('Pompa/#',0)
+  #client.subscribe('$SYS/#',0)
+  client.publish('message',"{'message':'avvio'}")
+
+def on_message(client,userdata,msg):
+  ora = datetime.datetime.now().strftime("%H:%M:%S %d-%m-%Y")
+
+  print('tipo dato ricevuto',type(msg.payload.decode()))
+
+  print('msg.topic',msg.topic)
+  print('msg.payload',str(msg.payload))
+
+#  if type(msg.payload) == bytes:
+#    print('msg.payload:',msg.payload.decode())
+
+  data=None
+  ok=False
+  try:
+    data = json.loads(msg.payload)
+    print("{}: {}".format(ora,data))
+    ok=True
+  except json.decoder.JSONDecodeError as jse:
+    print("errore",jse)
+    print('payload',msg.payload)
+
+  if ok:
+    print(data['irrigatore'],data['status'],type(data['irrigatore']))
+    if data['status'] == 1:
+      GPIO.output(data['irrigatore'],GPIO.HIGH)
+    else:
+      GPIO.output(data['irrigatore'],GPIO.LOW)
+
+GPIO.setmode(GPIO.BCM)
+
+GPIO.setwarnings(False)
+for i in range(4,12):
+  print('linea',i)
+  GPIO.setup(i,GPIO.OUT)
+
+client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
+client.on_connect = on_connect
+client.on_message = on_message
+
+client.username_pw_set('swarn','Abcd.1234')
+client.connect('nuc',1883,60)
+client.loop_forever()
+

+ 9 - 1
start.sh

@@ -22,6 +22,14 @@ sleep 3
 raspi-gpio set 8 dh
 
 raspi-gpio set 9 op
-sleep 3 
+sleep 1
 raspi-gpio set 9 dh
 
+raspi-gpio set 10 op
+sleep 1
+raspi-gpio set 10 dh
+
+raspi-gpio set 11 op
+sleep 1
+raspi-gpio set 11 dh
+