Hi Peder Dueled
Sorry for the inconvenience.
Periodic disconnect might happen due to below reasons.
- Keep alive interval- If the device doesn’t send a ping request within the keep-alive interval, the IoT Hub will disconnect it - We should increase the keep alive interval to max 1767 / 1.5 = 1177 second - Reference - https://learn.microsoft.com/en-us/azure/iot/iot-mqtt-connect-to-iot-hub#default-keep-alive-time-out
- Duplicate session is used with same device id - We should use only one device id
- Connect time out - Please increase time out second (like 20 or 30 second)
- Please check Devices are enabled on IOT hub.
- IoT Hub doesn't support QoS 2 messages. If a device application publishes a message with QoS 2, IoT Hub closes the network connection.
Please check Device side logs to find out Device Specific issues
Please check below sample code
Other Scenarios
https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718127
Reference used - https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-troubleshoot-connectivity#mqtt-device-disconnect-behavior-with-azure-iot-sdks
Hope it helps
Thank you.