Search code examples
azureazure-iot-hubazure-eventgrid

When are EventGrid IoT Hub DeviceConnected and DeviceDisconnected Events raised


IoT Hub publishes the events "DeviceConnected" and "DeviceDisconnected" via Event Grid according to the documentation.

My question is, which action from an actual IoT Device triggers these events?

For the "DeviceConnected" event:

  • Is it triggered when the OpenAsync Method is called on the Client SDK?
  • Is it triggered implicitly when the SendEvent Method is called?
  • Is this event also available via direct AMQP/MQTT connections?
  • For how long will it stay in this state?

For the "DeviceDisconnected" event:

  • Is the device going to "disconnected" as soon as "Close" on the DeviceClient is called?
  • What if connectivity is not good? Is there a constant ping along with a timeout mechanism which marks a device as offline after it was idle for a given time?

We currently have implemented the heartbeat pattern as described here but we are wondering if there is an easier and eventually more cost-efficient way to achieve the same goal.


Solution

  • I found this passage in the documentation

    The connection state is updated only for devices using MQTT or AMQP. Also, it is based on protocol-level pings (MQTT pings, or AMQP pings), and it can have a maximum delay of only 5 minutes. For these reasons, there can be false positives, such as devices reported as connected but that are disconnected.

    This covers most of my questions.