Advertisement
Guest User

Untitled

a guest
May 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. def background_thread(args):
  2. db = MySQLdb.connect(host=myhost,user=myuser,passwd=mypasswd,db=mydb)
  3. cursor = db.cursor()
  4. count = 0
  5. dataList = []
  6. serialTemp = ""
  7. length = 0
  8. lengthTemp = 0
  9. sV = ""
  10. tV = ""
  11. srlV = ""
  12. while True:
  13. if args:
  14. A = dict(args).get('A')
  15. sV = dict(args).get('s_value')
  16. tV = dict(args).get('t_value')
  17. srlV = dict(args).get('value')
  18. btnV = dict(args).get('btn_value')
  19. else:
  20. A = 1
  21. srlV = 'null'
  22. btnV = ""
  23. #print A
  24. socketio.sleep(1)
  25. count += 1
  26. n = "test"#rSer.readline()
  27. if "Present" in n:
  28. length = int(re.search(r'\d+', n.split(": ",1)[1]).group())
  29.  
  30. if srlV != serialTemp or length != lengthTemp:
  31. serialTemp = srlV
  32. lengthTemp = length
  33. dataDict = {
  34. "time": count,
  35. "speed": sV,
  36. "throttle": tV,
  37. "dist": length}
  38. #ser.write(serialTemp)
  39. if btnV == "start":
  40. dataList.append(dataDict)
  41. print dataDict
  42. if btnV == "stop" and len(dataList)>0:
  43. btnV = "null"
  44. output = str(dataList).replace("[","")
  45. output = output.replace("]","")
  46. cursor.execute("INSERT INTO movement (data) VALUES (%s)",[output])
  47. db.commit()
  48. del dataList[:]
  49. socketio.emit('my_response',
  50. {'data': float(A), 'count': count},
  51. namespace='/test')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement