MQTT 使用中的问题汇总

  版本:eclipse-paho-mqtt-c-1.3.12 

 

  开发工具:QT

 

 

  问题1、其他都正常,唯独无法收到订阅消息

  原因:

MQTTClient_setCallbacks函数必须在MQTTClient_connect调用


问题2、
MQTTClient_messageArrived回调函数异常,多次收到重复内容。
原因:
MQTTClient_messageArrived回调函数返回了0
函数返回值说明:
1:成功
2:失败,会再次回调
return This function must return 0 or 1 indicating whether or not
 * the message has been safely received by the client application. <br>
 * Returning 1 indicates that the message has been successfully handled.
 * To free the message storage, ::MQTTClient_freeMessage must be called.
 * To free the topic name storage, ::MQTTClient_free must be called.<br>
 * Returning 0 indicates that there was a problem. In this
 * case, the client library will reinvoke MQTTClient_messageArrived() to
 * attempt to deliver the message to the application again.
 * Do not free the message and topic storage when returning 0, otherwise
 * the redelivery will fail.

 


问题3、MQTTClient_publishMessage阻塞
原因:在同一个线程进行消息订阅和消息推送,导致MQTT程序内部造成死循环




 

posted @ 2023-12-29 15:43  飞说晓事  阅读(474)  评论(0)    收藏  举报