aws-iot-device-sdk-embedded-C icon indicating copy to clipboard operation
aws-iot-device-sdk-embedded-C copied to clipboard

MQTT_Publish() return MQTTSuccess,but the message is not being published to broker successfuly

Open zhengasif opened this issue 1 year ago • 6 comments

hi teams
I'm using the latest version of embedded sdk in my arm-linux device. I found an error that MQTT_Publish() return MQTTSuccess,but in fact there are no messages in broker ,and after 5 seconds it returns MQTTKeepAliveTimeout because of the bad network condition.I set QOS0 for my msgs. why it is like that in poor network condition? my code is like below: mqttStatus = MQTT_Publish( &AwsMqttContext,&outgoingPublishPackets[publishIndex].pubInfo,outgoingPublishPackets[publishIndex ].packetId); if(mqttStatus!=MQTTSuccess ) { printf("Failed to send PUBLISH packet to broker with error = %s.",MQTT_Status_strerror(mqttStatus)); returnStatus = EXIT_FAILURE; cleanupOutgoingPublish( publishIndex ); } else { printf( "PUBLISH sent for topic %.*s to broker with packet ID %u.\n\n",strlen(pub_topic),pub_topic,outgoingPublishPackets[ publishIndex ].packetId); } The log file is in the attachment. sendnook

zhengasif avatar Jan 08 '24 13:01 zhengasif

已收到,我会尽快回复!

zhuang-hy avatar Jan 08 '24 13:01 zhuang-hy

Can you check what does your transport send/writev function return? If it returns success, MQTT has no way to determine that the data was not actually sent. In that case the MQTT keep alive should detect broken connection, which it seems to do. If the transport send does not return success, then it may be a bug in the library to return success.

aggarg avatar Jan 09 '24 13:01 aggarg

hi
I check the return of send function, it return scuccess but no msg in my broker. For this case, how can I do to make my code more robust, set qos1 or add some other code to check the return msg?

sendmsg001 sendmsg002 sendmsg003

zhengasif avatar Jan 15 '24 07:01 zhengasif

Hey @zhengasif sorry that you've been seeing this issue. I was wondering if you've verified that you're able to connect to the broker with the credentials that you're using on your device?

If you have verified this could you then try hosting, and then connecting to, a local MQTT broker? This way you can inspect the packets that are coming into and out of the broker using Wireshark or a similar utility. This would help us figure out what the root cause of your problem is

Skptak avatar Jan 24 '24 00:01 Skptak

已收到,我会尽快回复!

zhuang-hy avatar Jan 24 '24 00:01 zhuang-hy

set qos1 or add some other code to check the return msg?

That should help to catch broken connection.

aggarg avatar Jan 24 '24 11:01 aggarg