Skip to content

Slow to publish message #44

Closed
Closed
@law-ko

Description

@law-ko

Describe the bug
We have realized the time to get the message published to AWS IoT takes around 2 seconds. Any method to reduce this time?

System information
Running on ESP32

Screenshots or console output

I (59746) fleet_prov_by_claim_demo: Sending publish request to coreMQTT-Agent with message "{"state":{"reported":{"accessories":{"outlet":0}},"desired":null}}" on topic "$aws/things/XXX/shadow/name/XXX/update" with ID 11.
I (59776) aws_demo: Waiting for publish 11 to complete.
I (60476) coreMQTT: Publishing message to $aws/things/XXX/update.
I (61696) coreMQTT: Ack packet deserialized with result: MQTTSuccess.
I (61696) coreMQTT: State record updated. New state=MQTTPublishDone.

From sending publish request (59746) to MQTTPublishDone (61696): 1950

The code to publish to AWS IoT

ESP_LOGI( TAG,
                  "Sending publish request to coreMQTT-Agent with message \"%s\" on topic \"%s\" with ID %ld.",
                  pcPayload,
                  pcTopicName,
                  ulPublishMessageId );

        /* To ensure ulNotification doesn't accidentally hold the expected value
         * as it is to be checked against the value sent from the callback.. */
        ulNotifiedValue = ~ulPublishMessageId;

        xCommandAcknowledged = pdFALSE;

        xCommandAdded = MQTTAgent_Publish( &xGlobalMqttAgentContext,
                                           &xPublishInfo,
                                           &xCommandParams );

        if( xCommandAdded == MQTTSuccess )
        {
            /* For QoS 1 and 2, wait for the publish acknowledgment.  For QoS0,
             * wait for the publish to be sent. */
            ESP_LOGI( TAG,
                      "Waiting for publish %ld to complete.",
                      ulPublishMessageId );

            xCommandAcknowledged = prvWaitForNotification( &ulNotifiedValue );
        }
        else
        {
            ESP_LOGE( TAG,
                      "Failed to enqueue publish command. Error code=%s",
                      MQTT_Status_strerror( xCommandAdded ) );
        }

        /* Check all ways the status was passed back just for demonstration
         * purposes. */
        if( ( xCommandAcknowledged != pdTRUE ) ||
            ( xCommandContext.xReturnStatus != MQTTSuccess ) ||
            ( ulNotifiedValue != ulPublishMessageId ) )
        {
            ESP_LOGW( TAG,
                      "Error or timed out waiting for ack for publish message %ld. Re-attempting publish.",
                      ulPublishMessageId );
        }
        else
        {
            ESP_LOGI( TAG,
                      "Publish %ld succeeded.",
                      ulPublishMessageId );
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions