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
9from adafruit_ble import BLERadio
10
11from adafruit_ble_adafruit.adafruit_service import AdafruitServerAdvertisement
12from adafruit_ble_adafruit.temperature_service import TemperatureService
13
14temp_svc = TemperatureService()
15temp_svc.measurement_period = 100
16temp_last_update = 0
17
18ble = BLERadio()
19
20# Unknown USB PID, since we don't know what board we're on
21adv = AdafruitServerAdvertisement()
22adv.pid = 0x0000
23
24while True:
25 # Advertise when not connected.
26 print(adv)
27 print(bytes(adv))
28 ble.start_advertising(adv)
29 while not ble.connected:
30 pass
31 ble.stop_advertising()
32
33 while ble.connected:
34 now_msecs = time.monotonic_ns() // 1000000
35
36 if now_msecs - temp_last_update >= temp_svc.measurement_period:
37 temp_svc.temperature = microcontroller.cpu.temperature
38
39 temp_last_update = now_msecs