Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- import serial
- import RPi.GPIO as GPIO
- import cayenne.client
- import time
- import datetime
- LEDontime = 22
- LEDofftime = 6
- GPIO.setmode(GPIO.BCM)
- GPIO.setwarnings(False)
- pins = [26, 19, 13, 06]
- GPIO.setup(pins, GPIO.OUT)
- pHDown = 26
- pHUp = 19
- TEC = 13
- LED = 06
- GPIO.output(pins, GPIO.LOW)
- time.sleep(0.5)
- GPIO.output(pins, GPIO.HIGH)
- time.sleep(0.5)
- GPIO.output(pins, GPIO.LOW)
- time.sleep(0.5)
- GPIO.output(pins, GPIO.HIGH)
- time.sleep(0.5)
- pHCounter = 0
- print "clearing up relays"
- ser=serial.Serial("/dev/ttyUSB0",9600) #change USB as found from ls /dev/tty/USB*
- ser.baudrate=9600
- MQTT_USERNAME = "61334000-fc63-11e7-848a-61efd1c01e7d"
- MQTT_PASSWORD = "ca292be60d160c1e96bf6074bdf77710949036a6"
- MQTT_CLIENT_ID = "33b92b50-125a-11e8-b42d-698bd45831f1"
- client = cayenne.client.CayenneMQTTClient()
- client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
- #GET SENSOR VALUES
- value = ser.readline()
- time.sleep(5)
- print value
- pH = float(value[1:4])
- strpH = value[1:4]
- humidity = float(value[5:10])
- strhumidity = value[5:10]
- temp = float(value[11:16])
- strtemp = value[11:16]
- wtemp = float(value[17:])
- strwtemp = value[17:]
- realTime = datetime.datetime.now().strftime("%H:%M")
- window = Tk()
- window.title("Greenhouse Based Hydroponics - Sensor Data")
- window.geometry('900x400')
- ########
- timelbl = Label(window, text=realTime, font=("Arial Bold", 30))
- timelbl.grid(column=1, row=0)
- def clock():
- global pHCounter
- newCounter = pHCounter + 1
- pHCounter = newCounter
- hourTime = datetime.datetime.now().strftime("%H")
- if (int(hourTime) >= LEDontime):
- print "Grow lights are now off"
- GPIO.output(LED, GPIO.LOW)
- if (int(hourTime) >= LEDofftime) and (int(hourTime) < LEDontime):
- print "Grow lights are now ON"
- GPIO.output(LED, GPIO.LOW)
- client.loop()
- value=ser.readline()
- pH = float(value[1:5])
- humidity = float(value[6:11])
- temp = float(value[12:17])
- wtemp = float(value[18:])
- #print(value)
- #print(value[1:5])
- #print(value[5:10])
- #print(value[10:15])
- #-------- allow 15 ph tests before adjusting ph
- if pHCounter >= 15:
- if pH < 5:
- print "ph is below 5"
- print pH
- GPIO.output(pHUp, GPIO.LOW)
- GPIO.output(pHDown, GPIO.HIGH)
- if pH > 6 and pH < 7:
- print pH
- print "ph is safe range"
- GPIO.output(pHUp, GPIO.HIGH)
- GPIO.output(pHDown, GPIO.HIGH)
- if pH > 7:
- print "abovep h"
- GPIO.output(pHUp, GPIO.HIGH)
- GPIO.output(pHDown, GPIO.LOW)
- client.celsiusWrite(1, temp)
- client.luxWrite(2, humidity)
- client.luxWrite(3, pH)
- print ("pH Tests done: " + str(newCounter))
- client.celsiusWrite(4, wtemp)
- ################################
- value = ser.readline()
- strpH = value[1:4]
- print strpH
- pHlbl.configure(text=strpH)
- strtemp = value[12:17]
- print strtemp
- templbl.configure(text=strtemp)
- strhumidity = value[6:11]
- print strhumidity
- humlbl.configure(text=strhumidity)
- strwtemp = value[18:]
- print strwtemp
- wtemplbl.configure(text=strwtemp)
- time = time = datetime.datetime.now().strftime("Time: %H:%M:%S")
- timelbl.config(text=time)
- window.after(7000, clock)
- ###############
- pHlbl = Label(window, text=strpH, font=("Arial Bold", 30))
- pHlbl.grid(column=0, row=2)
- ideallbl = Label(window, text="Ideal pH range is 6.0 - 7.0", font=("Arial Bold", 10))
- ideallbl.grid(column=0, row=3)
- def pHclick():
- value = ser.readline()
- strpH = value[1:4]
- print strpH
- pHlbl.configure(text=strpH)
- pHbtn = Button(window, text=" Update pH ", command= pHclick ,bg="powder blue", fg="black", font=("Arial Bold", 12))
- pHbtn.grid(column=1, row=2)
- ###############
- templbl = Label(window, text=strtemp, font=("Arial Bold", 30))
- templbl.grid(column=0, row=4)
- def tempclick():
- value = ser.readline()
- strtemp = value[12:17]
- print strtemp
- templbl.configure(text=strtemp)
- tempbtn = Button(window, text=" Update room temp ", command = tempclick,bg="burlywood1", fg="black", font=("Arial Bold", 12))
- tempbtn.grid(column=1, row=4)
- ###############
- humlbl = Label(window, text=strhumidity, font=("Arial Bold", 30))
- humlbl.grid(column=0, row=6)
- def humclick():
- value = ser.readline()
- strhumidity = value[6:11]
- print strhumidity
- humlbl.configure(text=strhumidity)
- print "humidity update"
- humbtn = Button(window, text="Update relative humidity reading ", command= humclick,bg="light salmon", fg="black", font=("Arial Bold", 12))
- humbtn.grid(column=1, row=6)
- ###############
- wtemplbl = Label(window, text=strwtemp, font=("Arial Bold", 30))
- wtemplbl.grid(column=0, row=8)
- def wtempclick():
- value=ser.readline()
- strwtemp = value[18:]
- print strwtemp
- wtemplbl.configure(text=strwtemp)
- wtempbtn = Button(window, text=" Update nutrient solution temp ", command = wtempclick,bg="steelblue1", fg="black", font=("Arial Bold", 12))
- wtempbtn.grid(column=1, row=8)
- ###################
- '''
- bufferlbl = Label(window, text="pH Buffer status : ", font=("Arial Bold", 30))
- bufferlbl.grid(column=0, row=10)
- bufferTxt = "Buffer status standby"
- def bufferclick():
- if pH < 6:
- bufferTxt = "Up buffer is ON"
- print "ph less than 6"
- if pH > 7:
- bufferTxt = "Down buffer is ON"
- print "ph greater than 7"
- if (pH>6) and (pH<7):
- bufferTxt = "Buffers are OFF"
- print "ph ideal range"
- statuslbl.configure(text=bufferTxt)
- statuslbl = Button(window, text = bufferTxt, font=("Arial Bold", 15),bg="palevioletred2", command=bufferclick)
- statuslbl.grid(column=1, row=10)'''
- #########################
- plantlbl = Label(window, text="Plant grown : ", font=("Arial Bold", 30))
- plantlbl.grid(column=0, row=12)
- plant2lbl = Label(window, text=" Lettuce ", font=("Arial bold", 20),bg="darkolivegreen2",fg="black")
- plant2lbl.grid(column=1, row=12)
- ###################################### NAMES
- name = Button(window, text=" SMART GREENHOUSE HYDROPONICS", bg="darkolivegreen3", fg="black", font=("Arial Bold", 12))
- name.grid(column=2, row=2)
- name = Button(window, text=" WITH IOT INTEGRATION ", bg="darkolivegreen3", fg="black", font=("Arial Bold", 12))
- name.grid(column=2, row=3)
- plantlbl = Label(window, text="Researchers: ", font=("Arial Bold", 15))
- plantlbl.grid(column=2, row=4)
- name = Label(window, text="Reuben Anthony Renes", font=("Arial Bold", 15))
- name.grid(column=2, row=6)
- name2lbl = Label(window, text="Christian Rey Ylaya", font=("Arial Bold", 15))
- name2lbl.grid(column=2, row=8)
- name3lbl = Label(window, text="Nikki Jimenez", font=("Arial Bold", 15))
- name3lbl.grid(column=2, row=10)
- clock()
- window.mainloop()
- ################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement