Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymysql
- import serial
- import time
- s = None
- db = pymysql.connect(host='140.118.70.162', user='kevin',
- password='HGPK82LO27HXXGr9', db='trash_data', charset='utf8')
- cursor = db.cursor()
- # Prepare SQL query to INSERT a record into the database.
- sql = "INSERT INTO trash_data(chip_id, trash_amount, trash_gas) VALUES (%s, %s, %s)"
- def setup():
- global s
- s = serial.Serial("/dev/ttyS0", 57600) #set the baud rate to 57600 bps for communicating with MCU
- def loop():
- cursor.execute(sql, (1, 23, 99))
- db.commit()
- s.write("done") #send the acknowledge to MCU
- time.sleep(10)
- if __name__ == '__main__':
- setup()
- while True:
- loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement