From 01ab739d055c1f4762de9739bdb3aa05e143f2d0 Mon Sep 17 00:00:00 2001 From: wangfq Date: Fri, 10 Jul 2026 09:20:14 +0800 Subject: [PATCH] =?UTF-8?q?vd960DBN:=20=E4=BF=AE=E5=A4=8D=20mqtt=5Fpublish?= =?UTF-8?q?=20QoS>0=20=E6=97=B6=20packet=5Fid=3D0=20=E5=AF=BC=E8=87=B4=20b?= =?UTF-8?q?roker=20=E6=96=AD=E8=BF=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MQTT 规范要求 QoS≥1 的 PUBLISH 必须带非零 packet_id。 net_srv.c 的 mqtt_publish 硬编码 packet_id=0,broker 检测到协议违规后主动断开连接。 修复:QoS>0 时使用递增的 packet_id。 --- vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/net_srv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/net_srv.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/net_srv.c index c8ac243..e4e3a88 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/net_srv.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/net_srv.c @@ -170,7 +170,9 @@ void mqtt_publish(char *topic, char *message, int req_qos) MQTTString topicString = MQTTString_initializer; int msglen = strlen(message); topicString.cstring = topic; - len = MQTTSerialize_publish(mqttBuf, sizeof(mqttBuf), 0, req_qos, 0, 0, topicString, (unsigned char *)message, msglen); + static uint16_t s_mqtt_pkt_id = 0; + uint16_t pkt_id = (req_qos > 0) ? ++s_mqtt_pkt_id : 0; + len = MQTTSerialize_publish(mqttBuf, sizeof(mqttBuf), 0, req_qos, 0, pkt_id, topicString, (unsigned char *)message, msglen); // Transport_SendPacket(mqttBuf, len); WCHNET_SocketSend(SocketId_TCP, (uint8_t *)mqttBuf, &len); }