-
Notifications
You must be signed in to change notification settings - Fork 3
/
BluetoothController.py
69 lines (47 loc) · 1.48 KB
/
BluetoothController.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sys
import subprocess
from flask import Flask, request
from flask_cors import CORS
import bluetooth
import socket
#import clinet_setup
#from clinet_setup import sock
app = Flask(__name__)
CORS(app)
# 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))
addr = "DC:A6:32:B8:AC:C9"
print("HERE")
print(sys.argv)
# 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...")
print("HELLO ITS HERE")
@app.route('/send-signal', methods=['POST'])
def sendSignal():
param = request.json["param"]
print(param)
sock.send(param)
return param
if __name__ == '__main__':
app.run(host=' 172.20.10.6')
# 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))