alexCajas / EmbeddedMqttBroker

This is a Mqtt broker for embedded devices, developed in C++, FreeRTOS to use advanced multitasking capabilities, and arduino core. Tested in an Esp32 and esp8266.
https://github.com/alexCajas/EmbeddedMqttBroker
MIT License
71 stars 14 forks source link

MQTT broker received message with error while third-party mqtt client sended message with QoS 1 and QoS 2 #5

Closed wwwolfsasa closed 1 year ago

wwwolfsasa commented 1 year ago

Hi,

I built an esp32 mqtt broker with version 1.0.3. It works very well, but when I use a third-party mqtt client to send messages with QoS 1 and 2, the broker transforms the received messages into error messages. For example:

Third-party mqtt client --> [send topic]: test [send message]: "12345" Broker received and third-party mqtt client subscribed --> [subscribed topic]: test [subscribed message]: "345"

The broker always loses the first two characters. This is the issue that I have found.

Thank you.

alexCajas commented 1 year ago

Hi!, @wwwolfsasa, thanks four you comment, you right, there are two bytes that are always missing when you publish topics with qos > 0, the problem is in these lines https://github.com/alexCajas/EmbeddedMqttBroker/blob/d1b10c1893aeb5ba2ed46a5d501f7b7234fec2c7/src/MqttMessages/PublishMqttMessage.cpp#L7-L16 In Line 16 you can see how the packet to send to the receiver is built with the type and flags (including qos level) of the topic that your are publising with qos-1, then, when your client receives a topic with qos > 1, interprets these two missing bytes like message id. I will fix that early.

alexCajas commented 1 year ago

Please try it again, with this branch https://github.com/alexCajas/EmbeddedMqttBroker/tree/5-mqtt-broker-received-message-with-error-while-third-party-mqtt-client-sended-message-with-qos-1-and-qos-2 and let me now if the issue is fixed, thanks!

wwwolfsasa commented 1 year ago

HI,

Unfortunately, qos1、2 still doesn't working.

thank you.

SteeveGL commented 1 year ago

Please try it again, with this branch https://github.com/alexCajas/EmbeddedMqttBroker/tree/5-mqtt-broker-received-message-with-error-while-third-party-mqtt-client-sended-message-with-qos-1-and-qos-2 and let me now if the issue is fixed, thanks!

@alexCajas I got the same issue since Paho's android library set qos to 1 by default. The change you propose works for me.

Thanks!

alexCajas commented 1 year ago

@wwwolfsasa, can you give me more information? for example the software that are you using like clients, I'm little lost, I can't reproduce the issue now....