[Solved] Received subscribe acknowledgement with invalid QoS values from the broker

Server: emqx

Client: php-mqtt/client 3.x

PHP≥7.4

  • need
    • The project needs to customize the offline and online of the subscription client
  • code
    $server   = 'emqx server url';
    $port     = 1883;
    $clientId = 'sys_client';
    $username = 'test';
    $password = '12345678';
    $topics='$SYS/brokers/+/clients/#';//Subscription client online and offline
    $mqtt = new \PhpMqtt\Client\MqttClient($server, $port, $clientId);
    $connectionSettings = (new \PhpMqtt\Client\ConnectionSettings)
        ->setUsername($username)
        ->setPassword($password);
    
    $mqtt->connect($connectionSettings, true);
    $mqtt->subscribe($topics, function ($topic, $message) {
    			echo sprintf("Received message on topic [%s]: %s\n", $topic, $message);
    		}, 0);
    $mqtt->loop(true);
    $mqtt->disconnect();
    
  • Why is there an exception?
    Received subscribe acknowledgement with invalid QoS values from the broker.
    
  • How to solve it?
    • Refer to the ACL documentation of EMQX for rule setting: https://www.emqx.io/docs/zh/v4.3/advanced/acl-file.html
    • Default acl.conf
      {allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.
       
      {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
       
      {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
       
      {allow, all}.
      
    • Modify acl.conf, for the sake of security, I only allow the specified ip subscription here$SYS/brokers/+/clients/#
      {allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.
       
      {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
      
      #Specify ip subscription
      {allow, {ipaddr, "127.0.0.1"}, subscribe, ["$SYS/brokers/+/clients/#"]}.
      #Allow all clients to subscribe
      #{allow, all, subscribe, ["$SYS/brokers/+/clients/#"]}.
      
      {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
       
      {allow, all}.
      
    • Then, run it through the command line, it should not report an error

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *