paho.mqtt.embedded-c
paho.mqtt.embedded-c copied to clipboard
Missing MQTTSerialize_pubrec() API?
Dear Craggs,
I have a issue of QoS 2 when subscribing a topic. When I received PUBLISH packet from Broker, I responded Broker a PUBREC packet. But I did not find MQTTSerialize_pubrec () API, So I called MQTTSerialize_ack() API to reply broker an PUBREC, i.e.: MQTTSerialize_ack(ls_buf, MAX_BUF_LEN, PUBREC, 0, msgid); After receiving PUBREL, I called MQTTSerialize_pubcomp() to complete QoS2 hand-shaking. But it didn't work. After receiving PUBLISH from Broker, I replied PUBREC, but Broker did not receive PUBREC, instead it closed socket after timeout.
Please help and thanks a lot.
Best Regards, Victor
Using MQTTSerialize_ack() is what was intended. This is some example code from MQTTClient/src/MQTTClient.h:
if (msg.qos == QOS1)
len = MQTTSerialize_ack(sendbuf, MAX_MQTT_PACKET_SIZE, PUBACK, 0, msg.id);
else if (msg.qos == QOS2)
len = MQTTSerialize_ack(sendbuf, MAX_MQTT_PACKET_SIZE, PUBREC, 0, msg.id);
if (len <= 0)
rc = FAILURE;
else
rc = sendPacket(len, timer);