Skip to content

Commit 4f05c2f

Browse files
microbuildersommersoft
microbuilder
authored andcommitted
Minor scan example cleanup
1 parent adf192d commit 4f05c2f

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
from ubluepy import Scanner, constants
22

3-
def bytes_to_str(bytes):
4-
string = ""
5-
for b in bytes:
6-
string += chr(b)
7-
return string
8-
9-
def list_scan_results(scan_entries):
3+
def display_scan_results(scan_entries):
104
for e in scan_entries:
11-
print("ADDR: ", e.addr())
12-
print("TYPE: ", e.addr_type())
13-
print("RSSI: ", e.rssi())
5+
print("ADDR: ", e.addr())
6+
print("TYPE: ", e.addr_type())
7+
print("RSSI: ", e.rssi())
8+
9+
# Parse the contents of the advertising packet
1410
scan = e.getScanData()
1511
if scan:
1612
for s in scan:
17-
#if s[0] == constants.ad_types.AD_TYPE_COMPLETE_LOCAL_NAME:
18-
print('\t{}: {}'.format(s[1], s[2]))
13+
# Convert byte array to hex format string
14+
hex = ' '.join('0x%02X' % b for b in s[2])
15+
# Display enum value and hex string together
16+
print('\t{}: {}'.format(s[1], hex))
17+
18+
# Line break between record sets
1919
print("")
2020

21+
# Scan 1s for advertising devices in range
2122
s = Scanner()
22-
scan_res = s.scan(2000)
23-
list_scan_results(scan_res)
23+
scan_res = s.scan(1000)
24+
25+
# Display the scan results
26+
display_scan_results(scan_res)

0 commit comments

Comments
 (0)