Simple test

Ensure your device works with this simple test.

examples/ble_adafruit_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# Use with Web Bluetooth Dashboard, or with ble_adafruit_simpletest_client.py
 5
 6import time
 7
 8import microcontroller
 9
10from adafruit_ble import BLERadio
11
12from adafruit_ble_adafruit.adafruit_service import AdafruitServerAdvertisement
13from adafruit_ble_adafruit.temperature_service import TemperatureService
14
15temp_svc = TemperatureService()
16temp_svc.measurement_period = 100
17temp_last_update = 0
18
19ble = BLERadio()
20
21# Unknown USB PID, since we don't know what board we're on
22adv = AdafruitServerAdvertisement()
23adv.pid = 0x0000
24
25while True:
26    # Advertise when not connected.
27    print(adv)
28    print(bytes(adv))
29    ble.start_advertising(adv)
30    while not ble.connected:
31        pass
32    ble.stop_advertising()
33
34    while ble.connected:
35        now_msecs = time.monotonic_ns() // 1000000  # pylint: disable=no-member
36
37        if now_msecs - temp_last_update >= temp_svc.measurement_period:
38            temp_svc.temperature = (
39                microcontroller.cpu.temperature  # pylint: disable=no-member
40            )
41
42            temp_last_update = now_msecs