File tree 1 file changed +17
-14
lines changed
ports/nrf/boards/feather52/examples 1 file changed +17
-14
lines changed Original file line number Diff line number Diff line change 1
1
from ubluepy import Scanner , constants
2
2
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 ):
10
4
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
14
10
scan = e .getScanData ()
15
11
if scan :
16
12
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
19
19
print ("" )
20
20
21
+ # Scan 1s for advertising devices in range
21
22
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 )
You can’t perform that action at this time.
0 commit comments