You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
566 B
34 lines
566 B
import serial
|
|
from datetime import datetime
|
|
from time import sleep
|
|
import socketio
|
|
|
|
sio = socketio.Client()
|
|
now = datetime.now()
|
|
|
|
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)
|
|
ser.flush()
|
|
|
|
|
|
@sio.event
|
|
def connect():
|
|
print('connection established')
|
|
|
|
|
|
flag = 0
|
|
while True:
|
|
if flag != 1:
|
|
sio.connect('http://localhost:5000/')
|
|
flag += 1
|
|
if ser.in_waiting > 0:
|
|
data = ser.readline().decode('utf-8').rstrip()
|
|
print(data)
|
|
sio.emit('data', data)
|
|
print(now.strftime("%Y-%m-%d %H:%M"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|