Hi @Andrea Previtali I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Based on your findings, I would assume that the device must have connected to the IoT Hub using the CleanSession
flag set to 1. You could see from the Receiving cloud-to-device messages documentation that if the device uses the CleanSession flag set to 1, it doesn't receive any messages from IoT Hub until it subscribes to the device endpoint devices/{device-id}/messages/devicebound/#
This is a possible explanation for the behavior you are encountering. I have found a following reference from the Azure IoT SDK C sample where the flag is set to 1. I am not sure if this is being referenced by your code base. I would try setting it to 0 and see if you continue to receive updates even when a new session is established.
Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer .
Issue:
Devices stopped receiving C2D messages when using MQTT through Azure C SDK.
Solution:
Subscribing to the topic /messages/devicebound/#
from the below line of code helped resume the C2D messages.
#define DEVICEMESSAGE "devices/" DEVICEID "/messages/devicebound/#"
If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.
I hope this helps!
If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.