← Back to ratslair.com
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--control.py15
-rw-r--r--main.py13
2 files changed, 23 insertions, 5 deletions
diff --git a/control.py b/control.py
index aa86c1b..8fa33cd 100644
--- a/control.py
+++ b/control.py
@@ -29,6 +29,7 @@ input = "0"
while input != "a":
input = get_input()
+ print("Sending: %s" % input)
if input == "i":
sock.send("11")
elif input == "j":
@@ -39,8 +40,20 @@ while input != "a":
sock.send("22")
else:
sock.send("0")
- print(input)
+
+ read = sock.recv(1024)
+ read = read.decode("utf-8").strip('\n')
+ print("Received: '%s'" % read )
time.sleep(0.1)
+print("Sending: %s" % input)
+sock.send(input)
+
+read = sock.recv(1024)
+read = read.decode("utf-8").strip('\n')
+print("Received: '%s'" % read )
+
+print("Shutting down...")
+
sock.close()
diff --git a/main.py b/main.py
index 0e7e008..3f07b8a 100644
--- a/main.py
+++ b/main.py
@@ -28,16 +28,21 @@ port = server_sock.getsockname()[1]
print("Waiting for connection on RFCOMM channel %d..." % port)
-client_sock, client_info = server_sock.accept()
+recv_sock, client_info = server_sock.accept()
print("Connected to %s." % client_info[0])
-while client_sock:
- read = client_sock.recv(1024)
+send_sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
+send_sock.connect((client_info[0], 2))
+
+print("Created sending socket to %s" % client_info[0])
+
+while read != "a":
+ read = recv_sock.recv(1024)
read = read.decode("utf-8").strip('\n')
print("Received: %s" % read)
- sock.send("Acknowledge: " + read)
+ send_sock.send("Acknowledge: " + read)
print("Sent acknowledge")
if read == "0": # Do nothing