php-mqtt/client

The configured broker responded with unauthorized

Bagunda opened this issue · 5 comments

I check in console ip-address, login, password. It work.
But php page print error:

Fatal error: Uncaught PhpMqtt\Client\Exceptions\ConnectingToBrokerFailedException: [6] Establishing a connection to the MQTT broker failed: The configured broker responded with unauthorized. in /var/www/html/vendor/php-mqtt/client/src/MessageProcessors/Mqtt31MessageProcessor.php:252 Stack trace: #0 /var/www/html/vendor/php-mqtt/client/src/MqttClient.php(377): PhpMqtt\Client\MessageProcessors\Mqtt31MessageProcessor->handleConnectAcknowledgement() #1 /var/www/html/vendor/php-mqtt/client/src/MqttClient.php(158): PhpMqtt\Client\MqttClient->performConnectionHandshake() #2 /var/www/html/vendor/php-mqtt/client/src/MqttClient.php(144): PhpMqtt\Client\MqttClient->connectInternal() #3 /var/www/html/sonos_webhook.php(50): PhpMqtt\Client\MqttClient->connect() #4 {main} thrown in /var/www/html/vendor/php-mqtt/client/src/MessageProcessors/Mqtt31MessageProcessor.php on line 252
require('vendor/autoload.php');

use \PhpMqtt\Client\MqttClient;
use \PhpMqtt\Client\ConnectionSettings;

$server   = '192.168.84.66';
$port     = 1883;
$clientId = 'sonos_webhook.php';
$username = 'user1';
$password = "pass1";

$connectionSettings  = new ConnectionSettings();
$connectionSettings
  ->setUsername($username)
  ->setPassword($password);

$mqtt = new \PhpMqtt\Client\MqttClient($server, $port, $clientId);
$mqtt->connect($connectionSettings, true);
$mqtt->publish('php-mqtt/client/test', 'Hello World!', 0);
$mqtt->disconnect();

What type of broker are you using? I suspect that you are using Home Assistant with the Mosquitto plugin, which apparently seems to behave strangely as already discussed in #105. I've no solution for this as I'm unable to reproduce the issue.

Home Assistant with the Mosquitto plugin just installed

I've been trying to setup a Home Assistant instance for some tests, but I'm unable due to a lack of time and hardware. I'm still convinced it is a configuration issue on HA-side and not a problem with the library though. So I'll not be able to further assist with this issue, but I'll leave the issue open in case someone finds a solution and wants to share it.

I am having the same experience with hivemq managed broker

@squpshift This is most likely a different issue. Please create a new issue and provide details regarding your setup.