karpy47/PhpMqttClient

MQTT_QOS2 gets blocked at sendPublish function

Closed this issue · 2 comments

https://github.com/karpy47/php-mqtt-client/blob/b5a932a54a51a37249ae9055a8d1beff4aa2d4a1/MQTTClient.php#L395

On line 395 there's a check for the MQTT_QOS. The check is true, if it's not MQTT_QOS0 or MQTT_QOS1 (if($qos!=self::MQTT_QOS0 && $qos!=self::MQTT_QOS1) return false;) this holds true for MQTT_QOS2.

I didn't create a pull request, as I currently don't have a broker to test MQTT_QOS2 against, but i noticed that on line 418, there's a check for MQTT_QOS2 so IMO, line 395 is wrong.
https://github.com/karpy47/php-mqtt-client/blob/b5a932a54a51a37249ae9055a8d1beff4aa2d4a1/MQTTClient.php#L418

One possible fix for Line 395 would be something like:
if (!in_array($qos, array(self::MQTT_QOS0, self::MQTT_QOS1, self::MQTT_QOS2))) return false;

As I remember the code supports QoS level 2, but I did not test it and thus added a check to only allow level 0 and 1. Please feel free to change as you proposed and try it out. Report back if it works and we'll update the code.

QoS level 2 is now allowed, but still not tested so experimental support only.