summaryrefslogtreecommitdiff
path: root/ports/nrf/boards/feather_nrf52832/examples/ble_scan.py
diff options
context:
space:
mode:
Diffstat (limited to 'ports/nrf/boards/feather_nrf52832/examples/ble_scan.py')
-rw-r--r--ports/nrf/boards/feather_nrf52832/examples/ble_scan.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/ports/nrf/boards/feather_nrf52832/examples/ble_scan.py b/ports/nrf/boards/feather_nrf52832/examples/ble_scan.py
new file mode 100644
index 000000000..9cacbe6f4
--- /dev/null
+++ b/ports/nrf/boards/feather_nrf52832/examples/ble_scan.py
@@ -0,0 +1,26 @@
+from ubluepy import Scanner, constants
+
+def display_scan_results(scan_entries):
+ for e in scan_entries:
+ 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:
+ # 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(1000)
+
+# Display the scan results
+display_scan_results(scan_res)