-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
28 lines (21 loc) · 753 Bytes
/
Copy pathserver.py
File metadata and controls
28 lines (21 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# echo-server.py
import socket
import serial
HOST = "127.0.0.1" # Standard loopback interface address (localhost)
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
serial = serial.Serial('/dev/ttyACM1', baudrate=115200, timeout=0.01)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
while True:
connection, addr = s.accept()
with connection:
print(f"Connected by {addr}")
while True:
data = connection.recv(1024)
serial.write(data)
print(data)
if not data:
break
data = serial.read_until()
connection.sendall(data)