[Technical Question] Is there a way to generate connection status events as the state changes?
See original GitHub issueI have a situation in which a set of actions must be run as soon as the state of the iot hub device connection changes and right now I don’t see a clean way to achieve this. I know I can poll the state of the connection using the connected
property but what I’m really after is a way to turn this into an event based approach.
By looking at https://github.com/Azure/azure-iot-sdk-python/blob/master/azure-iot-device/azure/iot/device/iothub/aio/async_clients.py#L73-L74 I can see a way to hack my way around this limitation (by chaining handlers) but that would involve dealing with an object’s privates and because of this I don’t see it as a proper long term solution.
In the old SDK I was using IoTHubClient.set_connection_status_callback
for this. Is there another way that I’m not seeing right now?
AB#7366705
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
@zoopp Just an update on this. This work item has been been scheduled on our backlog and looks to be done sometime this fall
@zoopp This feature has now been added. There now exists a
.on_connection_state_change
handler that can be set on the client, which will be invoked every time the connection state changes. We recommend checking the connection state (the.connected
attribute) in your handler definition as connection states can potentially change during the execution of the handlerThis will be included as part of the next package release.