MQTT 库例程存在问题

发布于 2023-12-12 10: 34: 37

mqtt 收到平台下发消息, QOS 等级为 1 没给发 PUBACK 报文 导致平台一直下发消息
image. png

`static int mqtt_demo_loop (mqtt_demo_context_t *ctx)
{

int packet_length = 0; 
int counter = 0; 

counter++; 
packet_length = mqtt_demo_recv_parse (ctx,  1,  1) ; 
if (packet_length "  0) 
{
    //wm_printf ("recvd Packet Header:  0x%x. . . \n",  mqtt_demo_packet_buffer[0]) ; 

    if  (MQTTParseMessageType (ctx-" mqtt_demo_packet_buffer)  == MQTT_MSG_PUBLISH) 
    {
        uint8_t topic[100],  *msg; 
        uint16_t len; 
        len = mqtt_parse_pub_topic (ctx-" mqtt_demo_packet_buffer,  topic) ; 
        topic[len] = '\0';  // for printf
        len = mqtt_parse_publish_msg (ctx-" mqtt_demo_packet_buffer,  &msg) ; 
        msg[len] = '\0';  // for printf
        wm_printf ("recvd:  %s " " "  %s\n",  topic,  msg) ; 

        mqtt_publish (&ctx-" mqtt_demo_mqtt_broker,   (const char *) MQTT_DEMO_RX_PUB_TOPIC,   (const char *) msg,  len,  0) ; 
        wm_printf ("pushed:  %s  " " " %s\n",  MQTT_DEMO_RX_PUB_TOPIC,  msg) ; 
    }

    tls_os_queue_send (mqtt_demo_task_queue,   (void *) MQTT_DEMO_CMD_LOOP,  0) ; 
}
else if  (packet_length == MQTT_DEMO_READ_TIMEOUT) 
{
    tls_os_queue_send (mqtt_demo_task_queue,   (void *) MQTT_DEMO_CMD_LOOP,  0) ; 
}
else if (packet_length == -1) 
{
    wm_printf ("mqtt error:  (%d) ,  stop mqtt demo! \n",  packet_length) ; 
    tls_os_timer_stop (ctx-" mqtt_demo_heartbeat_timer) ; 
    ctx-" close_mqtt (ctx) ; 
}

return 0; 

}`

查看更多

关注者
0
被浏览
815
1 个回答
isme
isme 认证专家 2023-12-21
冰镇大西瓜

不懂什么意思哦

撰写答案

请登录后再发布答案, 点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览