php-mqtt/client

I'm sorry. I don't know what went wrong

wjssk0517 opened this issue · 6 comments

The code looks like this

$server   = '192.168.8.41';
        $port     = 9001;
        $clientId = '75c90d5b-4cac-4d38-88a0-a1b2c3d4';
        try {
            $mqtt = new MqttClient($server, $port, $clientId);
        } catch (ProtocolNotSupportedException $e) {
            dump($e->getMessage());
        }
        //try {
        $connectionSettings = (new ConnectionSettings)
            ->setUsername('htt')
            ->setPassword('password');
        try {
            $mqtt->connect($connectionSettings, true);
        } catch (ConfigurationInvalidException $e) {
            echo 'ConfigurationInvalidException';
            dump($e->getMessage());
        } catch (ConnectingToBrokerFailedException $e) {
            echo 'ConnectingToBrokerFailedException';
            dump($e->getMessage());
        }
        $mqtt->publish('/gateway/2d5181efa65c4244a294ffd1f6c31b3e/request', 'Hello World!', 0);
        echo 2;
        $mqtt->disconnect();

出错

There is no problem with my MQTT service

Your exception handling is reporting an error, but your code is not terminating in case of an exception.

$mqtt->publish('/gateway/2d5181efa65c4244a294ffd1f6c31b3e/request', 'Hello World!', 0);

shouldn't be called when your client failed connecting to the broker.

Anyway, my guess is you are using an unsupported protocol to connect to the broker (default is MQTT 3.1, not MQTT 3.1.1). What broker and version are you using?

It doesn't actually run up here
$mqtt->publish('/gateway/2d5181efa65c4244a294ffd1f6c31b3e/request', 'Hello World!', 0);

I've tried version switching
123123123
This is my MQTT service

Does my code need to be deployed with the MQTT service

Sorry, I passed the test because of my port

9001 is a Webstock port

I just used 1883

Thank you

I was just about to say that... 👍