diff options
| author | microbuilder <contact@microbuilder.eu> | 2018-01-15 16:40:17 +0100 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2018-01-18 11:32:47 -0800 |
| commit | fda065ea89c383cbf16df3b8101d897d485ba6b2 (patch) | |
| tree | ac8e307b2225a058c3f3aa4dcb66b4d629c848c7 | |
| parent | e2ebcbe514739fbbe2bc4fcbf25ab35960e97a75 (diff) | |
Minor scan example cleanup
| -rw-r--r-- | ports/nrf/boards/feather52/examples/ble_scan.py | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/ports/nrf/boards/feather52/examples/ble_scan.py b/ports/nrf/boards/feather52/examples/ble_scan.py index aaa59673b..9cacbe6f4 100644 --- a/ports/nrf/boards/feather52/examples/ble_scan.py +++ b/ports/nrf/boards/feather52/examples/ble_scan.py @@ -1,23 +1,26 @@ from ubluepy import Scanner, constants -def bytes_to_str(bytes): - string = "" - for b in bytes: - string += chr(b) - return string - -def list_scan_results(scan_entries): +def display_scan_results(scan_entries): for e in scan_entries: - print("ADDR: ", e.addr()) - print("TYPE: ", e.addr_type()) - print("RSSI: ", e.rssi()) + print("ADDR: ", e.addr()) + print("TYPE: ", e.addr_type()) + print("RSSI: ", e.rssi()) + + # Parse the contents of the advertising packet scan = e.getScanData() if scan: for s in scan: - #if s[0] == constants.ad_types.AD_TYPE_COMPLETE_LOCAL_NAME: - print('\t{}: {}'.format(s[1], s[2])) + # Convert byte array to hex format string + hex = ' '.join('0x%02X' % b for b in s[2]) + # Display enum value and hex string together + print('\t{}: {}'.format(s[1], hex)) + + # Line break between record sets print("") +# Scan 1s for advertising devices in range s = Scanner() -scan_res = s.scan(2000) -list_scan_results(scan_res) +scan_res = s.scan(1000) + +# Display the scan results +display_scan_results(scan_res) |
