Advertisement
Guest User

hydroponics relays only

a guest
Feb 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import serial
  3. import RPi.GPIO as GPIO
  4. import cayenne.client
  5. import time
  6. import datetime
  7. from Tkinter import *
  8. root = Tk()
  9. LEDontime = 22
  10. LEDofftime = 6
  11. pHCounter = 14
  12. GPIO.setmode(GPIO.BCM)
  13. GPIO.setwarnings(False)
  14. pins = [26, 19, 13, 06]
  15. GPIO.setup(pins, GPIO.OUT)
  16. pHDown = 26
  17. pHUp = 19
  18. TEC = 13
  19. LED = 06
  20. GPIO.output(pins, GPIO.LOW)
  21. time.sleep(0.5)
  22. GPIO.output(pins, GPIO.HIGH)
  23. time.sleep(0.5)
  24. GPIO.output(pins, GPIO.LOW)
  25. time.sleep(0.5)
  26. GPIO.output(pins, GPIO.HIGH)
  27. time.sleep(0.5)
  28.  
  29.  
  30. print "cleaning up relays"
  31.  
  32.  
  33. ser=serial.Serial("/dev/ttyUSB0",9600) #change USB as found from ls /dev/tty/USB*
  34. ser.baudrate=9600
  35. # Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
  36. MQTT_USERNAME = "61334000-fc63-11e7-848a-61efd1c01e7d"
  37. MQTT_PASSWORD = "ca292be60d160c1e96bf6074bdf77710949036a6"
  38. MQTT_CLIENT_ID = "33b92b50-125a-11e8-b42d-698bd45831f1"
  39.  
  40.  
  41. client = cayenne.client.CayenneMQTTClient()
  42.  
  43. client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
  44.  
  45. i=0
  46. timestamp = 0
  47. value=ser.readline()
  48. time.sleep(5)
  49. while True:
  50.  
  51. hourTime = datetime.datetime.now().strftime("%H")
  52. minTime = datetime.datetime.now().strftime("%M")
  53. print hourTime
  54. if int(hourTime) >= 22:
  55. GPIO.output(LED, GPIO.LOW)
  56. print "shit"
  57. client.loop()
  58. value=ser.readline()
  59.  
  60.  
  61. #pH = float(value[1:5])
  62. pH = 8
  63. humidity = float(value[6:11])
  64. temp = float(value[12:17])
  65. wtemp = float(value[18:])
  66. #print(value)
  67. #print(value[1:5])
  68. #print(value[5:10])
  69. #print(value[10:15])
  70.  
  71.  
  72. #-------- allow 15 ph tests before adjusting ph
  73. if pHCounter >= 15:
  74. ph = 8
  75. if pH < 5:
  76. print pH
  77. GPIO.output(pHUp, GPIO.LOW)
  78. GPIO.output(pHDown, GPIO.HIGH)
  79. if pH > 6 and pH < 7:
  80. print pH
  81. GPIO.output(pHUp, GPIO.HIGH)
  82. GPIO.output(pHDown, GPIO.HIGH)
  83.  
  84. if pH > 7:
  85. print pH
  86. GPIO.output(pHUp, GPIO.HIGH)
  87. GPIO.output(pHDown, GPIO.LOW)
  88.  
  89.  
  90.  
  91.  
  92.  
  93. if (time.time() > timestamp + 10):
  94. client.celsiusWrite(1, temp)
  95. client.luxWrite(2, humidity)
  96. client.luxWrite(3, pH)
  97. pHCounter += 1
  98. print ("pH Tests done: " + str(pHCounter))
  99. client.celsiusWrite(4, wtemp)
  100. timestamp = time.time()
  101. i = i+1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement