diff --git a/bluetooth_visibility.sh b/bluetooth_visibility.sh new file mode 100644 index 0000000..e7402a2 --- /dev/null +++ b/bluetooth_visibility.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +sudo hciconfig hci0 piscan + +# sudo hciconfig -a +# should contain PICSCAN flag \ No newline at end of file diff --git a/client.py b/client.py index f1d8654..89b19a2 100644 --- a/client.py +++ b/client.py @@ -10,7 +10,7 @@ print('This devices bluetooth address is: {}'.format(bt_mac)) def send_payload(address): payload = json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}]) - sock = bluetooth.BluetoothSocket(bluetooth.L2CAP) + sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM) bt_addr = address port = 0x1001 @@ -26,17 +26,18 @@ def send_payload(address): data = sock.recv(1024) print("Data received:", str(data)) + a = input("exit: ") sock.close() -while True: - nearby_devices = bluetooth.discover_devices(lookup_names=True) - print("found %d devices" % len(nearby_devices)) - - for addr, name in nearby_devices: - print(" %s - %s" % (addr, name)) - if addr == settings.PEER_BT_ADDRESS: - print("PEERING PARTNER FOUND") - send_payload(addr) - - time.sleep(settings.BT_SLEEP) \ No newline at end of file +# while True: +# nearby_devices = bluetooth.discover_devices(lookup_names=True) +# print("found %d devices" % len(nearby_devices)) +# +# for addr, name in nearby_devices: +# print(" %s - %s" % (addr, name)) +# if addr == settings.PEER_BT_ADDRESS: +# print("PEERING PARTNER FOUND") +# send_payload(addr) +# +# time.sleep(settings.BT_SLEEP) \ No newline at end of file diff --git a/server.py b/server.py index 80413cb..4b94ba1 100644 --- a/server.py +++ b/server.py @@ -5,23 +5,30 @@ import settings bt_mac = settings.get_own_bt_address() print('This devices bluetooth address is: {}'.format(bt_mac)) -server_sock = bluetooth.BluetoothSocket(bluetooth.L2CAP) +server_sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM) port = 0x1001 server_sock.bind(("", port)) server_sock.listen(1) -client_sock, address = server_sock.accept() -print("Accepted connection from ", address) +client_sock = False -data = client_sock.recv(1024) -print("Data received: ", str(data)) +try: + client_sock, address = server_sock.accept() + print("Accepted connection from ", address) -while data: - client_sock.send('Echo => ' + str(data)) data = client_sock.recv(1024) - print("Data received:", str(data)) + print("Data received: ", str(data)) + + while data: + client_sock.send('Echo => ' + str(data)) + data = client_sock.recv(1024) + print("Data received:", str(data)) +except KeyboardInterrupt: + print("closing") +finally: + if client_sock: + client_sock.close() + server_sock.close() -client_sock.close() -server_sock.close() \ No newline at end of file diff --git a/settings.py b/settings.py index c00b946..c38d476 100644 --- a/settings.py +++ b/settings.py @@ -1,7 +1,9 @@ # this is the address of the hikey -# PEER_BT_ADDRESS = '98:7B:F3:19:FE:57' -PEER_BT_ADDRESS = '7C:E9:D3:DD:66:23' -BT_SLEEP = 2 # seconds +HIKEY_BT_ADDRESS = '98:7B:F3:19:FE:57' +# raspy +RASPY_BT_ADDRESS = 'B8:27:EB:76:09:0B' +PEER_BT_ADDRESS = RASPY_BT_ADDRESS +BT_SLEEP = 0.01 # seconds from subprocess import Popen, PIPE import re @@ -25,3 +27,5 @@ def get_own_bt_address(): return bt_addresses[0] + +