Simple test

Ensure your device works with this simple test.

examples/ble_lywsd03mmc_simpletest.py
 1# SPDX-FileCopyrightText: 2021 Dan Halbert, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4
 5import time
 6
 7import adafruit_ble
 8from adafruit_ble.advertising.standard import Advertisement
 9from adafruit_ble_lywsd03mmc import LYWSD03MMCService
10
11# PyLint can't find BLERadio for some reason so special case it here.
12ble = adafruit_ble.BLERadio()  # pylint: disable=no-member
13
14connection = None
15
16while True:
17    print("Scanning...")
18    for adv in ble.start_scan(Advertisement, timeout=5):
19        if adv.complete_name == "LYWSD03MMC":
20            connection = ble.connect(adv)
21            print("Connected")
22            break
23
24    # Stop scanning whether or not we are connected.
25    ble.stop_scan()
26
27    if connection and connection.connected:
28        service = connection[LYWSD03MMCService]
29        while connection.connected:
30
31            print(
32                "Temperature, Humidity",
33                service.temperature_humidity,
34            )
35            time.sleep(5)