Advertisement
Guest User

python2

a guest
Jan 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. import serial
  2. import datetime
  3. from time import sleep
  4. import atexit
  5. import os
  6. import time
  7. from time import ctime
  8. import datetime
  9. from bokeh.plotting import figure, output_file, show
  10.  
  11. output_file("/var/www/html/index.html")
  12. p = figure()
  13. arduino_serial = serial.Serial(port='/dev/ttyACM1', baudrate=115200, parity='N', stopbits=1, timeout=1)
  14. data = []
  15. timea=[]
  16. humi = []
  17. temp = []
  18. location = 0
  19. def getdata():
  20. with open("log.txt","a") as file :
  21. arduino_serial.flushInput()
  22. arduino_serial.flushOutput()
  23. linet = arduino_serial.readline().decode('UTF-8')
  24. tmp = linet.strip('\n').split(' ')
  25. tmp = [datetime.datetime.now().minute,eval(tmp[0]),eval(tmp[1])]
  26. data.append(tmp)
  27.  
  28. timea.append(datetime.datetime.now().minute)
  29. humi.append(tmp[1])
  30. temp.append(tmp[2])
  31. print(humi[0:len(humi)])
  32. #temp.append(eval(tmp[1]))
  33. #print("[ "+ctime()+" ] "+line)
  34. file.write("[ "+ctime()+" ] "+linet)
  35. # send = input("SEND TO ARDUINO: ")
  36. # arduino_serial.write(send.encode())
  37. print()
  38. p.line(timea[0:len(timea)],humi[0:len(humi)],line_width=2)
  39. p.rect(x=timea[0:len(timea)], y=humi[0:len(humi)], width=0.4, height=h, color="#CAB2D6")
  40.  
  41.  
  42. show(p)
  43.  
  44. def _main_():
  45. print("Wait for Arduino...")
  46. time.sleep(1)
  47. file = open("log.txt","a")
  48.  
  49. # if arduino_serial.is_open:
  50. line = arduino_serial.readline()
  51. print(line)
  52.  
  53. inp = str(input("INPUT HERE: "))
  54. while (1):
  55. arduino_serial.write(inp.encode())
  56. time.sleep(2)
  57. getdata()
  58. # print("[ "+ctime()+" ] "+"exit !!\n")
  59. file.write("[ "+ctime()+" ] ")
  60.  
  61. time.sleep(60);
  62.  
  63. # exit()
  64.  
  65. _main_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement