-
Notifications
You must be signed in to change notification settings - Fork 3
/
clinet_setup.py
50 lines (37 loc) · 1.17 KB
/
clinet_setup.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
import bluetooth
import subprocess
# FOR SCANNING
# 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))
import sys
addr = "DC:A6:32:B8:AC:C9"
print(sys.argv)
if len(sys.argv) < 2:
print("No device specified. Searching all nearby bluetooth devices for "
"the SampleServer service...")
else:
addr = sys.argv[1]
print("Searching for SampleServer on {}...".format(addr))
# search for the SampleServer service
uuid = "94f39d29-7d6d-437d-973b-fba39e49d4e0"
service_matches = bluetooth.find_service(uuid=uuid, address=addr)
if len(service_matches) == 0:
print("Couldn't find the SampleServer service.")
sys.exit(0)
first_match = service_matches[0]
port = first_match["port"]
name = first_match["name"]
host = first_match["host"]
print("Connecting to \"{}\" on {}".format(name, host))
# Create the client socket
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((host, port))
print("Connected. Type something...")
while True:
data = input()
if not data:
break
sock.send(data)
sock.close()