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
被浏覽
1.6k
1 個回答
isme
isme 認證專家 2023-12-21
冰鎮大西瓜

不懂什麼意思哦

撰寫答案

請登錄後再發布答案,點擊登錄

發布
問題

分享
好友

手機
浏覽

掃碼手機浏覽