summaryrefslogtreecommitdiffstatshomepage
path: root/examples/bluetooth/ble_temperature_central.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/bluetooth/ble_temperature_central.py')
-rw-r--r--examples/bluetooth/ble_temperature_central.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/examples/bluetooth/ble_temperature_central.py b/examples/bluetooth/ble_temperature_central.py
index 8b679b9b80..19dc93409e 100644
--- a/examples/bluetooth/ble_temperature_central.py
+++ b/examples/bluetooth/ble_temperature_central.py
@@ -80,6 +80,8 @@ class BLETemperatureCentral:
# Connected device.
self._conn_handle = None
+ self._start_handle = None
+ self._end_handle = None
self._value_handle = None
def _irq(self, event, data):
@@ -124,18 +126,31 @@ class BLETemperatureCentral:
# Connected device returned a service.
conn_handle, start_handle, end_handle, uuid = data
if conn_handle == self._conn_handle and uuid == _ENV_SENSE_UUID:
+ self._start_handle, self._end_handle = start_handle, end_handle
+
+ elif event == _IRQ_GATTC_SERVICES_DONE:
+ # Service query complete.
+ if self._start_handle and self._end_handle:
self._ble.gattc_discover_characteristics(
- self._conn_handle, start_handle, end_handle
+ self._conn_handle, self._start_handle, self._end_handle
)
+ else:
+ print("Failed to find environmental sensing service.")
elif event == _IRQ_GATTC_CHARACTERISTIC_RESULT:
# Connected device returned a characteristic.
conn_handle, def_handle, value_handle, properties, uuid = data
if conn_handle == self._conn_handle and uuid == _TEMP_UUID:
self._value_handle = value_handle
+
+ elif event == _IRQ_GATTC_CHARACTERISTICS_DONE:
+ # Characteristic query complete.
+ if self._value_handle:
# We've finished connecting and discovering device, fire the connect callback.
if self._conn_callback:
self._conn_callback()
+ else:
+ print("Failed to find temperature characteristic.")
elif event == _IRQ_GATTC_READ_RESULT:
# A read completed successfully.