Advertisement
Guest User

Untitled

a guest
May 13th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #!/usr/bin/python
  2. import RPi.GPIO as GPIO
  3. import mysql.connector
  4. import time
  5. from RPLCD import CharLCD
  6. GPIO.setmode(GPIO.BOARD)
  7.  
  8. #BD
  9. conn = mysql.connector.connect(host="127.0.0.1",user="brewing",password="", database="brewing")
  10. cursor = conn.cursor()
  11.  
  12. #LCD init
  13. lcd = CharLCD(pin_rs=15, pin_rw=18, pin_e=16,
  14. pins_data=[21, 22, 23, 24],
  15. numbering_mode=GPIO.BOARD,
  16. cols=16, rows=2, dotsize=8,
  17. charmap='A02', auto_linebreaks=True)
  18.  
  19. #Relay init closed HIGH
  20. pinList = [36, 37]
  21. for i in pinList:
  22. GPIO.setup(i, GPIO.OUT)
  23. GPIO.output(i, GPIO.HIGH)
  24.  
  25. SleepTimeL = 5
  26. epoch_time = int(time.time())
  27.  
  28. #Refresh LCD + log database
  29. def refresh():
  30. lcd.clear()
  31. lcd.write_string('Cur: ' + str(current_temp) + ' Goal: ' + str(goal) + '\r\n' + status)
  32. cursor.execute("""INSERT INTO logs (log_id, value,
  33. timestamp, goal) VALUES(%s, %s, %s, %s)""",
  34. ("NULL", current_temp, epoch_time, goal))
  35. conn.commit()
  36. return
  37.  
  38. def readconfig():
  39. cursor.execute("""SELECT value FROM conf WHERE id = 1""")
  40. row = cursor.fetchone()
  41. goal = int(row[0])
  42. return
  43.  
  44. # main loop
  45. while True:
  46. try:
  47. #todo get temp
  48. current_temp = int(60)
  49. readconfig()
  50. time.sleep(SleepTimeL)
  51. if current_temp < goal:
  52. GPIO.output(36, GPIO.LOW)
  53. status = "Heating"
  54. refresh();
  55. elif current_temp > goal:
  56. GPIO.output(36, GPIO.HIGH)
  57. GPIO.output(37, GPIO.LOW)
  58. status = "Cooling"
  59. refresh()
  60. elif current_temp == goal:
  61. GPIO.output(36, GPIO.HIGH)
  62. GPIO.output(37, GPIO.HIGH)
  63. status = "Stopped"
  64. refresh()
  65. except KeyboardInterrupt:
  66. print " Quit"
  67. GPIO.cleanup()
  68. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement