summaryrefslogtreecommitdiffstatshomepage
path: root/examples/bluetooth/ble_temperature_central.py
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2020-05-11 21:46:56 +1000
committerDamien George <damien.p.george@gmail.com>2020-06-05 14:07:52 +1000
commit6a3c89d584db4f14c7e2432b7c5ad87951e6c2d5 (patch)
tree866cf6ef026c65d3fae6f4bc54a2dd707892399c /examples/bluetooth/ble_temperature_central.py
parente6881f08292d03f089185718c131f543d095089b (diff)
downloadmicropython-6a3c89d584db4f14c7e2432b7c5ad87951e6c2d5.tar.gz
micropython-6a3c89d584db4f14c7e2432b7c5ad87951e6c2d5.zip
extmod/modbluetooth: Add discover complete events for svc/char/desc.
Without this it's difficult to implement a state machine correctly if the desired services are not found.
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.