Hello,
I'm using SDK for Thread and Zigbee v4.1 and I developed a network using mqtt-sn library.
Since the developed application requires data publishing at a high rate, I noticed a possible bug in the mqttsn_packet_sender.c file.
Function mqttsn_packet_sender_publish() increases automatically the message ID by means of function next_packet_id_get(): everything works fine until the message ID reaches a value equal to MQTTSN_MAX_PACKET_ID, set by default to 65535. In this case function next_packet_id_get() returns an ID equal to 1 but does not update the message ID contained in the client structure. In this way the message saved in packet queue will have an ID different from the one of the sent packet.
When the PUBACK of that message is received, function mqttsn_packet_fifo_elem_find() will not be able to find the message in the packet queue, since the message ID remained stuck at MQTTSN_MAX_PACKET_ID, thus returning error NRF_ERROR_INTERNAL ("PUBACK packet ID has unexpected value").
I think the possible solution may be the following:
uint32_t mqttsn_packet_sender_publish(mqttsn_client_t * p_client,
mqttsn_topic_t * p_topic,
const uint8_t * payload,
uint16_t payload_len)
{
...
p_client->message_id = next_packet_id_get(p_client);
uint16_t datalen = MQTTSNSerialize_publish(p_data,
packet_len,
dup,
qos,
retained,
p_client->message_id,
topic,
(uint8_t *)payload,
payload_len);
....
}
This is probably needed in all other functions that call next_packet_id_get() in file mqttsn_packet_sender.c.
Please let me know if this is right or if I just missed something.
Thanks!