-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Establishing a connection to the MQTT broker failed #151
Comments
Have you changed something about the code of the |
No I didn't change anything. |
In that case, this sounds like a firewall issue. |
Actually I stopped the broker. As I said earlier I'm working on to get an email notification if the connection to broker fails.So What is supposed to be the output is just this oneline "Establishing connection to broker failed". But why I'm getting this uncaught error and stack traces? Due to this my script is not getting executed properly. |
I'm not sure what your goal is and what your current solution looks like (i.e. your code), but why don't you simply catch the exception and add some error handling? try {
$client = new \PhpMqtt\Client\MqttClient($host, $port, $clientId);
$client->connect();
// ... your MQTT logic ...
} catch (\PhpMqtt\Client\Exceptions\ConnectingToBrokerFailedException $e) {
$this->logger->error('The MQTT client could not connect to the broker.');
// Maybe add something like this as well:
// $this->notificationManager->sendAlert(...);
} |
I tried catch the error as you mentioned. now I'm getting this error. PHP Fatal error: Uncaught Error: Cannot access private property PhpMqtt\Client\MqttClient::$logger in /home/ubuntu1/mosquitto/test.php:39 Stack trace: #0 {main} thrown in /home/ubuntu1/mosquitto/test.php on line 39 |
Fixed the error. Used printf instead of this->logger->error. And put the catch statement at the end of the publish block to avoid further uncaught exceptions. Thank you so much for the timely response. |
I am using this library for my mosquitto mqtt project. When the connection to broker fails it shows some uncaught error. we are working on a project where we will get an email when the connection to broker failed." Trying to catch the error. But it is getting more complicated. If I catch the error it displays another uncaught type error. I'm attaching the image of the type error too.
The text was updated successfully, but these errors were encountered: