-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbtclient.py
More file actions
71 lines (51 loc) · 1.26 KB
/
Copy pathbtclient.py
File metadata and controls
71 lines (51 loc) · 1.26 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
# bt client
#
#from bluetooth import *
import socket
import signal
import sys
from time import sleep
from datetime import datetime
#BTAddr = '40:1C:83:C9:9F:81' # pc
#BTAddr = 'DC:A6:32:8D:3F:87' # devhost
BTAddr = 'B8:27:EB:C5:C7:EE' # devhost
#BTsocket = BluetoothSocket (RFCOMM)
#BTsocket.connect ((BTAddr), 1)
#socket s;
# graceful exit on CNTRL-C
def signal_handler(sig, frame):
# close port and exit
print("\nCaught signal, exiting ....")
s.close() # not shutdown as this is a broadcast stream
sys.exit(0)
# SIGINT
signal.signal(signal.SIGINT, signal_handler)
for i in range(3):
snow = datetime.now()
#print("now =", snow)
try:
s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
s.connect((BTAddr,5))
req = "profiles"
encReq = req.encode()
#s.send(b'profiles')
s.send(bytearray(encReq))
profiles = s.recv(1024)
#print (profiles)
print (profiles.decode())
except:
print ("Connection failed")
s.close()
tnow = datetime.now()
print("now =", tnow, tnow - snow)
sleep(3)
s.close
s.close()
'''
while (True):
data = conn.recv(1024)
if not data: # socket was closed
break
print(data)
'''