eclipse-paho / paho.mqtt.embedded-c

Paho MQTT C client library for embedded systems. Paho is an Eclipse IoT project (https://iot.eclipse.org/)
https://eclipse.org/paho
Other
1.37k stars 757 forks source link

A problem with MQTTConnectWithResults and readPacket #192

Open IvanRaykov opened 5 years ago

IvanRaykov commented 5 years ago

Hello, I am finding error in MQTT protocol connection to MQTT broker.

In the file MQTTClient.c function readPacket (row 112), when connection is triggered and the header byte is read, the return from the function is compared to 1. As far as I managed to track the problem, the header byte returns 4, with the local mosquitto server and a cloud based one. If I make it to compare to 4, the result is fine. It seems that it is expecting packet with more information, but the ACK packet that is received on connect request is empty! If I replace the comparison to 4, it passes the check, otherwise MQTTConnect returns -1 and ongoing communication is blocked due to client.isconnected not set to 1. I am not sure if this is correct solution or the servers answer is not correct.

P.S. If client.isconnected is set manually than communication is possible. With Wireshark, the Connect is acknowledged, the connect is acknowledged!

Please help with this issue! Thank you in advance!