Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3.6
- # Trying this serial wont work and causes arduino to lock #
- # Bryan Cairns Void Realms Face Book #
- #MD Harrington
- import mariadb
- import serial
- import syslog
- import time
- import threading
- port='/dev/ttyACM0'
- baudrate=57600
- ser = serial.Serial(port,baudrate,timeout=5)
- global conn
- def activatePort():
- m_text="Hello world"
- m_arr=m_text.encode('ansii')
- ser.write(m_arr)
- sleep(20)
- ser.close()
- print("Finished")
- def doSql(ID):
- # Connect to MariaDB Platform
- try:
- conn = mariadb.connect(
- user="xxxx",
- password="xxxxx",
- host="192.168.0.80",
- port=3306,
- database="Instructions"
- )
- cursor = conn.cursor()
- statement = "SELECT ID, Username , Message FROM Instructions.Messages WHERE ID=%s"
- data = (ID,)
- print(f"Messages For ID = {ID} ")
- cursor.execute(statement, data)
- row = cursor.fetchone()
- while row:
- name = row[1]
- print (name)
- msg= row[2]
- print (msg)
- row = cursor.fetchone()
- conn.close()
- except mariadb.Error as e:
- print(f"Error retrieving entry from database: {e}")
- ID ="MDWONE"
- # tried with threading as welland without
- x =threading.Thread(target=activatePort)
- x.start()
- y= threading.Thread(target=doSql,args=(ID,))
- y.start()
- ser.close()
- exit(1)
Add Comment
Please, Sign In to add comment