From 1a837cbe411b4522582d323454a03ef02e9dd292 Mon Sep 17 00:00:00 2001 From: Edvin Date: Wed, 9 Apr 2025 15:40:25 +0200 Subject: Functional two-way communication --- control.py | 4 +++- main.py | 11 ++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/control.py b/control.py index 8fa33cd..f86d3bf 100644 --- a/control.py +++ b/control.py @@ -26,7 +26,7 @@ print("Connected to %s." % pi) input = "0" -while input != "a": +while input != "q": input = get_input() print("Sending: %s" % input) @@ -38,6 +38,8 @@ while input != "a": sock.send("33") elif input == "k": sock.send("22") + elif input == "q": + sock.send("1000") else: sock.send("0") diff --git a/main.py b/main.py index 3f07b8a..b22dc6c 100644 --- a/main.py +++ b/main.py @@ -32,18 +32,15 @@ recv_sock, client_info = server_sock.accept() print("Connected to %s." % client_info[0]) -send_sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM) -send_sock.connect((client_info[0], 2)) +read = "0" -print("Created sending socket to %s" % client_info[0]) - -while read != "a": +while read != "1000": read = recv_sock.recv(1024) read = read.decode("utf-8").strip('\n') print("Received: %s" % read) - send_sock.send("Acknowledge: " + read) - print("Sent acknowledge") + print(f"Sending: 'Acknowledge: {read}'") + client_sock.send(f"Acknowledge: {read}\n".encode()) # Remember NEW LINE for ÖS to be able to read lines. if read == "0": # Do nothing GPIO.output(P1, False) -- cgit v1.2.3