mqtt收到平臺下發消息,QOS等級為1 沒給發PUBACK報文 導致平臺一直下發消息
`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;
}`
我已經改了 就是MQTT發布消息等級不是有0和1和2麼 1的話需要回複PUBACK報文但是MQTT例程裡面的沒有回複,導致平臺以為沒收到 一直再下發,我自己增加回複了
@qq3147106 真棒!