opened
mattsches
username_0
Can be mqttv31 or mqttv311. Defaults to mqttv31.

I suppose `Mosquitto-PHP` makes use of the default protocol version and there is no way to set the version in the client code? Unfortunately my broker (Home Assistant built-in broker) requires `mqttv311` :(

Will now try to set up my own custom broker using `Mosquitto` and integrate it into my Home Assistant setup, but it would be nice to be able to set the version in my client script.
Option to set the version of the MQTT protocol
issue
created
mgdm
username_1
I didn't realise that was possible, though I've just had a look into the library code and can see how it's done now:

https://github.com/eclipse/mosquitto/blob/master/lib/mosquitto.h#L947

 I'll give it a go in the next couple of days, I don't have a lot of time right at this moment.
comment
created
mattsches
username_0
Thanks, no hurry! I got it to work by configuring the broker to accept 3.1.
comment
created
mgdm
username_1
Hi, I've had a go at it now, can you give the patch in https://github.com/username_1/Mosquitto-PHP/pull/68 a go and let me know how you get on?
comment
created
mattsches
username_0
Finally found the time to check out your branch and test it against the embedded MQTT broker of Home Assistant.

I can confirm that setting the protocol works, and that it makes a difference on the broker side.

The following does NOT work against the broker:
```php
$c = new \Mosquitto\Client();
$c->setProtocolVersion(\Mosquitto\ProtocolVersion::V31);
...
```
while this works:
```php
$c = new \Mosquitto\Client();
$c->setProtocolVersion(\Mosquitto\ProtocolVersion::V311);
...
```

To sum it up: Your patch works as expected :smile:
comment
closed
mgdm
username_1
issue