An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
Hi @Stargazer
What you're seeing matches how IoT Hub's registry connectionState is designed. It isn't intended to provide real-time device presence.
The device connectionState property is eventually consistent and may be delayed. In fact, Microsoft recommends using it only for development/debugging and specifically advises against querying connectionState at runtime to determine whether a device is currently online.
That also explains why your diagnostic logs can show deviceConnect earlier while Azure IoT Explorer and:
RegistryManager.CreateQuery(...)
still show the previous state. Those are different mechanisms, and the registry view isn't updated synchronously with the connection event.
For production per-device monitoring, Microsoft currently recommends Azure Event Grid and subscribing to:
Microsoft.Devices.DeviceConnected
Microsoft.Devices.DeviceDisconnected
Event Grid provides lower-latency per-device connection monitoring than registry polling.
However, Event Grid still has an important limitation: It doesn't provide instantaneous presence. IoT Hub evaluates connection-state changes on approximately 60-second intervals, so events can be delayed by up to about a minute, and very short connect/disconnect transitions can be missed.
Since you're using MQTT, also make sure the device performs the appropriate SUBSCRIBE or PUBLISH operation after connecting; Microsoft documents this as part of connection-state event reporting.
If you need stronger near-real-time knowledge of whether a device is actually alive, for example, tighter than Event Grid's connection-state semantics, the recommended pattern is an application-level heartbeat. Have the device periodically publish a heartbeat/telemetry message and maintain a lastSeen timestamp in your application. I suggest a custom heartbeat when Event Grid's limitations aren't suitable.
So don't try to reduce the 6–12 minute registry delay. Instead, change the monitoring source:
Registry connectionState → debugging/status reference
Event Grid → normal production connect/disconnect monitoring
Heartbeat/last-seen → stricter application-level presence requirements
References:
Monitor device connection status
Monitor and troubleshoot IoT Hub device connectivity
Help make this community better for everyone: If this answer helped or resolved your issue, please accept it or upvote it. If not, share more details in a comment so we can continue the discussion and find the right solution. Thank you.