Azure IoT C SDK: Message timeout Option on outgoing messages

82 Views Asked by At

We are using the Azure IoT SDK C source code package in our embedded/firmware project. We might have come into a situation where some devices have spotty communication with the cloud and outgoing messages (Device to cloud) are getting stuck and accumulated to the point the device runs out of memory. We do get a connectivity error at some point but in certain scenarios, it might not be fast enough and a lot of outgoing messages could be queued up right before it.

We are connecting to the IotHub through MQTT.

I saw in the code there is a "Message Timeout" client option that can be enabled. However, there is a clear Deprecation notice right above it.

https://github.com/Azure/azure-iot-sdk-c/blob/40a62f61e887026ba04d8c7fe77f967cfd134d48/iothub_client/inc/iothub_client_options.h#L53C17-L53C17

Keeping in mind we are using MQTT, what other option is there to ensure we don't encounter a situation where outgoing messages would pile-up in an outgoing queue without timing out already queued-in messages?

Thank you.

1

There are 1 best solutions below

0
Pavan On

Azure IoT C SDK: Message Timeout Option for Outgoing Messages

To prevent outgoing messages from piling up in the outgoing queue without timing out Here's a general approach you can take:

Send an outgoing message, timestamp it with the current time, and increase the timestamp.

  • Connect MQTT Client to Azure IoT Hub |
  • Use MQTT to communicate with Azure IoT Hub - Azure IoT Hub

code taken from the reference github


void connect_callback(struct mosquitto* mosq, void* obj, int result)
{
    printf("Connect callback returned result: %s\r\n", mosquitto_strerror(result));
    if (result == MOSQ_ERR_CONN_REFUSED)
    {
        printf("Connection refused. Please check DeviceId, IoTHub name or if your SAS Token has expired.\r\n");
    }
}

void disconnect_callback(struct mosquitto* mosq, void* obj, int rc)
{
    printf("Disconnect callback %d : %s\r\n", rc, mosquitto_strerror(rc));
}

void publish_callback(struct mosquitto* mosq, void* userdata, int mid)
{
    printf("Publish OK. Now disconnecting the client.\r\n");

    mosquitto_disconnect(mosq);
}

int mosquitto_error(int rc, const char* message = NULL)
{
    printf("Error: %s\r\n", mosquitto_strerror(rc));

    if (message != NULL)
    {
        printf("%s\r\n", message);
    }

    mosquitto_lib_cleanup();
    return rc;
}






enter image description here