# How to detect MQTT disconnections when using Shadow API

**URL:** <https://forums.freertos.org/t/how-to-detect-mqtt-disconnections-when-using-shadow-api/8898>\
**Category:** AWS\
**Created:** [February 19, 2019, 6:03am UTC](https://forums.freertos.org/t/how-to-detect-mqtt-disconnections-when-using-shadow-api/8898 "2019-02-19T06:03:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 19, 2019, 6:03am UTC](https://forums.freertos.org/t/how-to-detect-mqtt-disconnections-when-using-shadow-api/8898/1 "2019-02-19T06:03:57Z")

</div>

**[egoltzman](https://forums.aws.amazon.com/profile.jspa?userID=460203)** wrote on February 19, 2019:

My device code is based on the Shadow Demo, that is, it is using Shadow API.  
I need to identify connection lost and then to react on it.  
I see in aws\_api.c prvShadowMQTTCallback that if the MQTT event is eMQTTAgentDisconnect then the code resets the subscriptions to update\get\delete and return with no additional actions.  
My questions here are:

1. How can I know that there was a disconnection?
2. Is there any mechanism that I can use to automatically try to resubscribe?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [February 20, 2019, 10:50pm UTC](https://forums.freertos.org/t/how-to-detect-mqtt-disconnections-when-using-shadow-api/8898/2 "2019-02-20T22:50:10Z")

</div>

**[Gaurav-Aggarwal-AWS](https://forums.aws.amazon.com/profile.jspa?userID=447386)** wrote on February 20, 2019:

Please see the response here: [https://github.com/aws/amazon-freertos/issues/326#issuecomment-465749771](https://github.com/aws/amazon-freertos/issues/326#issuecomment-465749771)

Please let us know if you have any feedback about the new library. We are very interested in your feedback.

Thanks.
