-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog_draft_client.py
82 lines (45 loc) · 1.44 KB
/
prog_draft_client.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
70
71
72
73
74
75
76
77
78
79
80
81
82
##Draft code for basic smart badge implementation.
##RasPi local code
##Author: T D G Wilson
##Date: 18/11/2014
HOST = '192.168.20.113'
PORT = 50007
import os, time, subprocess, time, sys, bluetooth, csv, blescan #Will need to import ble library
import bluetooth._bluetooth as bluez
import socket
running = 1
def init():
dev_id = 0
try:
sock = bluez.hci_open_dev(dev_id)
except:
print "error accessing bluetooth device..."
sys.exit(1)
blescan.hci_le_set_scan_parameters(sock)
blescan.hci_enable_le_scan(sock)
return sock
def send_data(unique_nearby_devices, HOST, PORT):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
for line in unique_nearby_devices:
s.sendall(str(line))
data = s.recv(1024)
s.close
def unique(nearby_devices, unique_nearby_devices):
for addr in nearby_devices:
device = []
device.append(addr.split(','))
if device[0][0] not in unique_nearby_devices:
unique_nearby_devices.append(device[0][0])
return unique_nearby_devices
def scan():
unique_nearby_devices = []
nearby_devices = blescan.parse_events(sock, 4)
unique_nearby_devices = unique(nearby_devices, unique_nearby_devices)
#send_data(unique_nearby_devices, HOST, PORT)
for addr in unique_nearby_devices:
print addr
sock = init()
while running:
print "Checking " + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
scan()