34 lines
1 KiB
Python
34 lines
1 KiB
Python
import time
|
|
|
|
import adafruit_ble
|
|
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
|
|
from adafruit_ble_ibbq import IBBQService
|
|
|
|
# PyLint can't find BLERadio for some reason so special case it here.
|
|
ble = adafruit_ble.BLERadio() # pylint: disable=no-member
|
|
|
|
ibbq_connection = None
|
|
|
|
while True:
|
|
print("Scanning...")
|
|
for adv in ble.start_scan(ProvideServicesAdvertisement, timeout=5):
|
|
if IBBQService in adv.services:
|
|
print("found an IBBq advertisement")
|
|
ibbq_connection = ble.connect(adv)
|
|
print("Connected")
|
|
break
|
|
|
|
# Stop scanning whether or not we are connected.
|
|
ble.stop_scan()
|
|
|
|
if ibbq_connection and ibbq_connection.connected:
|
|
ibbq_service = ibbq_connection[IBBQService]
|
|
ibbq_service.init()
|
|
while ibbq_connection.connected:
|
|
print(
|
|
"Temperatures:",
|
|
ibbq_service.temperatures,
|
|
"; Battery:",
|
|
ibbq_service.battery_level,
|
|
)
|
|
time.sleep(2)
|