Advertisement
coolcat647

Untitled

May 31st, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import pymysql
  2. import serial
  3. import time
  4.  
  5. s = None
  6.  
  7. db = pymysql.connect(host='140.118.70.162', user='kevin',
  8.         password='HGPK82LO27HXXGr9', db='trash_data', charset='utf8')
  9. cursor = db.cursor()
  10.  
  11. # Prepare SQL query to INSERT a record into the database.
  12. sql = "INSERT INTO trash_data(chip_id, trash_amount, trash_gas) VALUES (%s, %s, %s)"
  13.  
  14.  
  15.  
  16. def setup():
  17.     global s
  18.     s = serial.Serial("/dev/ttyS0", 57600)      #set the baud rate to 57600 bps for communicating with MCU
  19.  
  20. def loop():
  21.     cursor.execute(sql, (1, 23, 99))
  22.     db.commit()
  23.     s.write("done")                             #send the acknowledge to MCU
  24.     time.sleep(10)
  25.  
  26. if __name__ == '__main__':
  27.     setup()
  28. while True:
  29.     loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement