paho.mqtt.embedded-c icon indicating copy to clipboard operation
paho.mqtt.embedded-c copied to clipboard

Missing MQTTSerialize_pubrec() API?

Open jedidiahuang opened this issue 6 years ago • 1 comments

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

jedidiahuang avatar Apr 09 '18 07:04 jedidiahuang

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);

icraggs avatar Apr 13 '18 10:04 icraggs