I'm sorry. I don't know what went wrong
wjssk0517 opened this issue · 6 comments
wjssk0517 commented
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();
wjssk0517 commented
There is no problem with my MQTT service
Namoshek commented
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?
wjssk0517 commented
wjssk0517 commented
Does my code need to be deployed with the MQTT service
wjssk0517 commented
Sorry, I passed the test because of my port
9001 is a Webstock port
I just used 1883
Thank you
Namoshek commented
I was just about to say that... 👍