aws / aws-iot-device-sdk-embedded-C

SDK for connecting to AWS IoT from a device using embedded C.
MIT License
974 stars 622 forks source link

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

Open zhengasif opened 6 months ago

zhengasif commented 6 months ago

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

zhuang-hy commented 6 months ago

已收到,我会尽快回复!

aggarg commented 6 months ago

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.

zhengasif commented 6 months ago

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

Skptak commented 5 months ago

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

zhuang-hy commented 5 months ago

已收到,我会尽快回复!

aggarg commented 5 months ago

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

That should help to catch broken connection.