-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluetooth_client.py
50 lines (44 loc) · 1.32 KB
/
bluetooth_client.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
""""
Execute on the local windows client machine which is your PC
"""
import bluetooth
import argparse
import json
def write_file(car_telemetry: str, telemetry_file_name: str):
with open(telemetry_file_name, "w") as file_handle:
file_handle.write(json.dumps(car_telemetry))
def main():
host = args.host
port = args.port
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((host, port))
while True:
text = input("Enter f=forward b=back r=right l=left s=stop q=quit : ")
if text == "q":
break
sock.send(text)
car_telemetry = sock.recv(1024).decode()
print(f"writing telemetry received from car: {car_telemetry}\n")
write_file(car_telemetry, args.telemetry_file)
sock.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--host",
type=str,
required=False,
help="bluetooth address",
default="E4:5F:01:78:14:3C",
)
parser.add_argument(
"--port", type=int, required=False, help="bluetooth address", default=1
)
parser.add_argument(
"--telemetry-file",
type=str,
required=False,
help="filename to write to disk",
default="car-telemetry.json",
)
args = parser.parse_args()
main()