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
 9
10from adafruit_ble.advertising import Advertisement
11from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
12
13ble = BLERadio()
14print("scanning")
15found = set()
16scan_responses = set()
17# By providing Advertisement as well we include everything, not just specific advertisements.
18for advertisement in ble.start_scan(ProvideServicesAdvertisement, Advertisement):
19    addr = advertisement.address
20    if advertisement.scan_response and addr not in scan_responses:
21        scan_responses.add(addr)
22    elif not advertisement.scan_response and addr not in found:
23        found.add(addr)
24    else:
25        continue
26    print(addr, advertisement)
27    print("\t" + repr(advertisement))
28    print()
29
30print("scan done")