vd960DBN: 修复 mqtt_publish QoS>0 时 packet_id=0 导致 broker 断连
MQTT 规范要求 QoS≥1 的 PUBLISH 必须带非零 packet_id。 net_srv.c 的 mqtt_publish 硬编码 packet_id=0,broker 检测到协议违规后主动断开连接。 修复:QoS>0 时使用递增的 packet_id。
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user