espMqttClient
espMqttClient copied to clipboard
Too strict for mqtt v3.1?
https://github.com/bertmelis/espMqttClient/blob/885e631f1669aaaeb88098811aace215a43d01b8/src/Packets/Parser.cpp#L97
This code really handles mqtt msg as v3.1.1. But maybe too strict for v3.1 as in v3.1 the fixed bits are different?
eg. https://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html#suback vs http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718068
Open for discussion...
I never even read the 3.1 specification. Do you still use this version?
one broker I work with has it, so all other libraries never complaint and I never saw any errors in the other libraries But when working with your lib, the client disconnected because of this reason. It was no problem in the Async-mqtt-client
This library complains because it is a 3.1.1 library. And when the header flags are not what they suppose to be, it's a protocol error and the connection must be closed.
What should be done to accommodate your issue is to implement v3.1 of the spec and not to lower the bar for 3.1.1.
I have yet to adapt the library to enable multiple protocol versions. But I had mqtt5 in mind instead of 3.1.
maybe like this?
switch (p->_packet.fixedHeader.packetType & 0xF0) {
case PacketType.CONNACK:
case PacketType.PUBACK:
case PacketType.PUBREC:
case PacketType.PUBREL:
case PacketType.PUBCOMP:
case PacketType.UNSUBACK:
p->_parse = _remainingLengthFixed;
break;
case PacketType.SUBACK:
p->_parse = _remainingLengthVariable;
p->_bytePos = 0;
break;
case PacketType.PINGRESP:
p->_parse = _remainingLengthNone;
break;
default:
emc_log_w("Invalid packet header: 0x%02x", p->_packet.fixedHeader.packetType);
return ParserResult::protocolError;
}
I'm not inclined to do that. This library send a CONNECT packet with the MQTT 3.1.1 protocol level. If your broker doesn't support that, it should disconnect. I'm not convinced this library is at fault.
For now, the only way I want to solve this issue is to create a whole separate set of packet/parser/logic flow specifically for MQTT 3.1.
But I didn't design the library to handle multiple version of the protocol so I have yet to come up with a solution for this. The most straightforward way is to duplicate all of the code and make minor adjustments like your proposal. In a second iteration we can deduplicate as much as possible.
I might find some spare time during the Christmas holidays to create something...
Ok, no rush, enjoy your holidays!
Until, in an undefined future, I will create a whole new version, you can use branch https://github.com/bertmelis/espMqttClient/tree/MQTT_3.1.