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 @   飞说晓事  阅读(312)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示