Mark2020H

Code that for some reason causes Arduino to crash

Mar 31st, 2021 (edited)
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. #!/usr/bin/env python3.6
  2. # Trying this serial  wont work  and causes  arduino to  lock #
  3. # Bryan  Cairns   Void Realms Face  Book #
  4.  
  5. #MD Harrington
  6.  
  7. import mariadb
  8. import serial
  9. import syslog
  10. import time
  11. import threading
  12.  
  13.  
  14.  
  15. port='/dev/ttyACM0'
  16. baudrate=57600
  17. ser = serial.Serial(port,baudrate,timeout=5)
  18. global conn
  19.  
  20. def activatePort():
  21.     m_text="Hello world"
  22.     m_arr=m_text.encode('ansii')
  23.     ser.write(m_arr)
  24.     sleep(20)
  25.     ser.close()
  26.     print("Finished")
  27.    
  28.    
  29.  
  30.  
  31.  
  32. def doSql(ID):
  33.         # Connect to MariaDB Platform
  34.     try:
  35.         conn = mariadb.connect(
  36.             user="xxxx",
  37.             password="xxxxx",
  38.             host="192.168.0.80",
  39.             port=3306,
  40.             database="Instructions"
  41.  
  42.         )
  43.         cursor = conn.cursor()
  44.         statement = "SELECT ID, Username , Message FROM Instructions.Messages WHERE ID=%s"
  45.         data = (ID,)
  46.         print(f"Messages For ID = {ID} ")
  47.         cursor.execute(statement, data)
  48.         row = cursor.fetchone()
  49.         while row:
  50.             name = row[1]
  51.             print (name)
  52.             msg= row[2]
  53.             print (msg)
  54.            
  55.             row = cursor.fetchone()
  56.         conn.close()
  57.        
  58.    
  59.     except mariadb.Error as e:
  60.         print(f"Error retrieving entry from database: {e}")
  61.  
  62.  
  63.  
  64. ID ="MDWONE"
  65.  
  66. # tried  with threading as welland without
  67.  
  68. x =threading.Thread(target=activatePort)
  69. x.start()
  70.  
  71. y= threading.Thread(target=doSql,args=(ID,))
  72. y.start()
  73.  
  74. ser.close()  
  75. exit(1)
  76.  
Add Comment
Please, Sign In to add comment