coolcat647 May 31st, 2017 61 Never
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='18.104.22.168', 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))
- s.write("done") #send the acknowledge to MCU
- if __name__ == '__main__':
- while True:
RAW Paste Data