Advertisement
Guest User

Untitled

a guest
Mar 27th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1.  
  2. import RPi.GPIO as GPIO
  3. import sys
  4. import Adafruit_DHT
  5. import time
  6. import pyodbc
  7. from mysql.connector import connect
  8.  
  9. DEMO = 1
  10.  
  11. GPIO.setmode(GPIO.BCM)
  12. pinList = [26, 13]
  13. manualPinList = [5, 6]
  14.  
  15. # loop through pins and set mode and state to 'off'
  16.  
  17. for i in pinList:
  18. GPIO.setup(i, GPIO.OUT)
  19. GPIO.output(i, GPIO.LOW)
  20.  
  21.  
  22. for j in manualPinList:
  23. GPIO.setup(j, GPIO.OUT)
  24. GPIO.output(j, GPIO.HIGH)
  25.  
  26. SERVER_CONNECTOR = ['']
  27.  
  28. def Connect_MYSQL():
  29.  
  30. SERVER = 'digitechautomation.cywrzfld2wji.us-west-2.rds.amazonaws.com' #'r2ocontainers.cywrzfld2wji.us-west-2.rds.amazonaws.com'
  31. PORT = 3306 #1433
  32. DATABASE_NAME = 'CraigslistPosterTest' #'SmartPanel'
  33. LOGIN = 'admin' #'r2oadmin'
  34. PASSWORD = 'digitech123' #'pop90909'
  35.  
  36. conn = connect(user=LOGIN, password=PASSWORD, database=DATABASE_NAME, port=PORT, host=SERVER)
  37.  
  38. return conn
  39.  
  40.  
  41. def Read_from_db_table(conn):
  42. cursor = conn.cursor(buffered=True)
  43. cursor.execute("SELECT b.mode, a.humidity, b.humidity_threshold, b.fan1, b.fan2, a.timestamp FROM CraigslistPosterTest.sp_demo_graph a INNER JOIN CraigslistPosterTest.sp_demo b ON a.sp_demo_id = b.demo WHERE demo = {0} ORDER BY a.timestamp DESC LIMIT 1".format(DEMO))
  44. rows = cursor.fetchall()
  45. return rows[0]
  46.  
  47. def main():
  48. while True:
  49. conn = Connect_MYSQL()
  50. mode, humidity, humidity_threshold, fan1, fan2, timestamp = Read_from_db_table(conn)
  51. print('**************')
  52. print('demo: %s' % (DEMO))
  53. print('mode: %s' % (mode))
  54. print('humidity: %s' % (humidity))
  55. print('humidity threshold: %s' % (humidity_threshold))
  56. print('fan 1: %s' % (fan1))
  57. print('fan 2: %s' % (fan2))
  58. print('timestamp: %s' % (timestamp))
  59. print('**************')
  60.  
  61. if mode == 'logic':
  62. if humidity > humidity_threshold:
  63. print "humidity > threshold - turn both fans on"
  64. GPIO.output(26, True)
  65. GPIO.output(13, True)
  66. else:
  67. print "humidity < threshold - turn both fans off"
  68. GPIO.output(26, False)
  69. GPIO.output(13, False)
  70. elif mode == 'manual':
  71. if fan1 == '1':
  72. print "manual - fan 1 on"
  73. GPIO.output(26, True)
  74. else:
  75. print "manual - fan 1 off"
  76. GPIO.output(26, False)
  77.  
  78. if fan2 == '1':
  79. print "manual - fan 2 on"
  80. GPIO.output(13, True)
  81. else:
  82. print "manual - fan 2 off"
  83. GPIO.output(13, False)
  84. time.sleep(1)
  85.  
  86. if __name__ == '__main__':
  87. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement