Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import RPi.GPIO as GPIO
- import mysql.connector
- import time
- from RPLCD import CharLCD
- GPIO.setmode(GPIO.BOARD)
- #BD
- conn = mysql.connector.connect(host="127.0.0.1",user="brewing",password="", database="brewing")
- cursor = conn.cursor()
- #LCD init
- lcd = CharLCD(pin_rs=15, pin_rw=18, pin_e=16,
- pins_data=[21, 22, 23, 24],
- numbering_mode=GPIO.BOARD,
- cols=16, rows=2, dotsize=8,
- charmap='A02', auto_linebreaks=True)
- #Relay init closed HIGH
- pinList = [36, 37]
- for i in pinList:
- GPIO.setup(i, GPIO.OUT)
- GPIO.output(i, GPIO.HIGH)
- SleepTimeL = 5
- epoch_time = int(time.time())
- #Refresh LCD + log database
- def refresh():
- lcd.clear()
- lcd.write_string('Cur: ' + str(current_temp) + ' Goal: ' + str(goal) + '\r\n' + status)
- cursor.execute("""INSERT INTO logs (log_id, value,
- timestamp, goal) VALUES(%s, %s, %s, %s)""",
- ("NULL", current_temp, epoch_time, goal))
- conn.commit()
- return
- def readconfig():
- cursor.execute("""SELECT value FROM conf WHERE id = 1""")
- row = cursor.fetchone()
- goal = int(row[0])
- return
- # main loop
- while True:
- try:
- #todo get temp
- current_temp = int(60)
- readconfig()
- time.sleep(SleepTimeL)
- if current_temp < goal:
- GPIO.output(36, GPIO.LOW)
- status = "Heating"
- refresh();
- elif current_temp > goal:
- GPIO.output(36, GPIO.HIGH)
- GPIO.output(37, GPIO.LOW)
- status = "Cooling"
- refresh()
- elif current_temp == goal:
- GPIO.output(36, GPIO.HIGH)
- GPIO.output(37, GPIO.HIGH)
- status = "Stopped"
- refresh()
- except KeyboardInterrupt:
- print " Quit"
- GPIO.cleanup()
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement