My devices don't receive C2D messages anymore from IoT Hub

Andrea Previtali 106 Reputation points
2023-11-09T14:26:41.5133333+00:00

Hello everyone,

I've been going crazy for a few days with my IoT Hub and I can't figure out why.

On my devices, I have connected about 60-70 of them, the C2D messaging system doesn't work anymore.

My "system" is very simple, it is based on an embedded Linux distribution and I have a script written in C that is invoked every 10'' to send a teletrics message to IoT Hub, so far so good, everything works correctly and never had any problems.

I use mosquitto and MQTT protocol.

Every x seconds, depending on the device, a Subscribe request is also made via another script written in C.

The connection is successfully made to IoT Hub, but the device no downloads the message, it is as if it did not receive it.

My scripts, both the one for sending telemetry and the one for receiving messages are based on the C codes downloaded from here:

https://learn.microsoft.com/it-it/azure/iot-hub/iot-hub-mqtt-support

My devices authenticate with X.509 certificates and everything has always worked properly, I have been using this system for almost a year.

In the past few days I started having problems on sending messages from cloud to device: from Azure interface the message shows correctly sent and queued, but to the device it is as if it never arrives.

I thought that for some reason the post script might conflict with the subscribe script but I noticed that the problem persists even when running only the subscribe script.

To rule out the possibility that the problem could be associated with the platform, I also used the C program in the Linux Ubuntu environment. The problem persists.

Has something changed in Azure IoT Hub that I missed?

Has anyone experienced similar problems?

I am very concerned because I need to restore this "communication" as soon as possible but I don't know how to do it.

Thanks to everybody.

Andrea Previtali

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,175 questions
{count} votes

Accepted answer
  1. LeelaRajeshSayana-MSFT 14,831 Reputation points Microsoft Employee
    2023-11-28T23:34:10.7033333+00:00

    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.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Andrea Previtali 106 Reputation points
    2023-11-28T14:15:13.1066667+00:00

    Hello everyone,

    I have a little bit of news that may be of interest to everybody and maybe it will bring me closer to understanding what happened.

    I didn't lose heart and doing some testing with other scripts to query my IoT Hub I found this ploy.

    My old code involved these two instructions:

    #define DEVICEMESSAGE "devices/" DEVICEID "/messages/#"
    

    As I told you it was no longer working, today I gave it a try by modifying my code as follows:

    #define DEVICEMESSAGE "devices/" DEVICEID "/messages/devicebound/#"
    

    The program written this way worked.

    I went back to the old version and that works too.

    I assure you that I did not change a single line of code, simply after this change and after going back, the system started working again.

    Do you guys have any idea what could have happened?

    1 person found this answer helpful.
    0 comments No comments

  2. Sander van de Velde | MVP 32,006 Reputation points MVP
    2023-11-09T17:48:28.9533333+00:00

    Hello @Andrea Previtali ,

    welcome to this moderated Azure community forum.

    I expect you are not reusing device registrations, please double check.

    There has been one mayor change regarding the IoT Hub.

    Microsoft is migrating to the new Digicert TLS certificate. This is announced a few years ago an postponed several times to give users more time to migrate.

    Are your device capable to working with this Digicert certificate?

    If this is ok, I recommend submitting a support ticket so the Azure helpdesk can check your backend.


    This answer is written by myself, not by some AI. If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.