Getting Connection Status Azure IoTHub client

David 6 Reputation points
2022-10-13T00:37:19.413+00:00

I am using the Azure C sdk and struggling to implement a solution that checks the connection status during the sending of messages. My application that connects to the iothub is not designed to be persistent, so I need to know if I lose connection while sending data so I can try again later. Any information would be great on how to either get the acknowledgement statement that the IoTHub received my information, or a way to check connection status during the DoWork loop.

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,136 questions
Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
208 questions
{count} vote

1 answer

Sort by: Most helpful
  1. QuantumCache 20,031 Reputation points
    2022-10-13T04:46:43.253+00:00

    Hello @David , Could you please add more info on your C lang Code snippet or any Github link where we can have a look at the public facing code snippet?
    Please add any tutorial or the document reference which you have followed for getting started on this scenario.

    Community SME's on this topic or our team will review your scenario and circle back at the possible earliest time.

    Reference:
    First, create a message:

    249951-image.png

    249942-image.png

    249933-image.png

    static void SendConfirmationCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback)  
    {  
        EVENT_INSTANCE* eventInstance = (EVENT_INSTANCE*)userContextCallback;  
        (void)printf("Confirmation[%d] received for message tracking id = %zu with result = %s\r\n", callbackCounter, eventInstance->messageTrackingId, MU_ENUM_TO_STRING(IOTHUB_CLIENT_CONFIRMATION_RESULT, result));  
        /* Some device specific action code goes here... */  
        callbackCounter++;  
        IoTHubMessage_Destroy(eventInstance->messageHandle);  
    }  
    

    Note the call to the IoTHubMessage_Destroy function when you're done with the message. This function frees the resources allocated when you created the message.