Scan everything
Ensure your device works with this simple test. When working, will print out advertising data of nearby BLE devices.
examples/ble_simpletest.py
1# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""
5This example scans for any BLE advertisements and prints one advertisement and one scan response
6from every device found.
7"""
8
9from adafruit_ble import BLERadio
10
11ble = BLERadio()
12print("scanning")
13found = set()
14scan_responses = set()
15for advertisement in ble.start_scan():
16 addr = advertisement.address
17 if advertisement.scan_response and addr not in scan_responses:
18 scan_responses.add(addr)
19 elif not advertisement.scan_response and addr not in found:
20 found.add(addr)
21 else:
22 continue
23 print(addr, advertisement)
24 print("\t" + repr(advertisement))
25 print()
26
27print("scan done")
Detailed scan
Ensure your device works with this simple test.
examples/ble_detailed_scan.py
1# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4# This example scans for any BLE advertisements and prints one advertisement and one scan response
5# from every device found. This scan is more detailed than the simple test because it includes
6# specialty advertising types.
7
8from adafruit_ble import BLERadio
9from adafruit_ble.advertising import Advertisement
10from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
11
12ble = BLERadio()
13print("scanning")
14found = set()
15scan_responses = set()
16# By providing Advertisement as well we include everything, not just specific advertisements.
17for advertisement in ble.start_scan(ProvideServicesAdvertisement, Advertisement):
18 addr = advertisement.address
19 if advertisement.scan_response and addr not in scan_responses:
20 scan_responses.add(addr)
21 elif not advertisement.scan_response and addr not in found:
22 found.add(addr)
23 else:
24 continue
25 print(addr, advertisement)
26 print("\t" + repr(advertisement))
27 print()
28
29print("scan done")