summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormicrobuilder <contact@microbuilder.eu>2018-01-15 16:04:30 +0100
committerScott Shawcroft <scott@tannewt.org>2018-01-18 11:32:47 -0800
commite2ebcbe514739fbbe2bc4fcbf25ab35960e97a75 (patch)
tree49243c33d943191c141777b4690cb890691e097e
parent1276c120974b67b1bc09c7a160201e230c6b844b (diff)
Simple BLE scanner example
-rw-r--r--ports/nrf/boards/feather52/examples/ble_scan.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/ports/nrf/boards/feather52/examples/ble_scan.py b/ports/nrf/boards/feather52/examples/ble_scan.py
new file mode 100644
index 000000000..aaa59673b
--- /dev/null
+++ b/ports/nrf/boards/feather52/examples/ble_scan.py
@@ -0,0 +1,23 @@
+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):
+ for e in scan_entries:
+ print("ADDR: ", e.addr())
+ print("TYPE: ", e.addr_type())
+ print("RSSI: ", e.rssi())
+ 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]))
+ print("")
+
+s = Scanner()
+scan_res = s.scan(2000)
+list_scan_results(scan_res)