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程序内部造成死循环
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具