Reputation: 11
I try to subscribe to a topic, I get below mentioned error:
Undefined array key "qos"
My code:
`try {
$mqtt = new Mqtt();
$mqtt->ConnectAndSubscribe('myTopic', function ($topic, $msg) {
Log::info("Mqtt Msg Received");
});
} catch (\Exception $e) {
dd($e->getMessage());
}`
(As in the example, I inserted it into a controller).
$buffer .= chr($callback["qos"]);
in vendor/salmanzafar/laravel-mqtt/src/MqttClass/MqttService.php:173
If I solve the problem adding a simple "?? 0", when I try to subscribe, it doesn't seems to work.
I'm using Laravel 8.16 with PHP 8.0 and "salmanzafar/laravel-mqtt": "^2.0".
Upvotes: 1
Views: 277
Reputation: 263
Docs: https://packagist.org/packages/salmanzafar/laravel-mqtt
Please check whether QoS is configured in your Config/mqtt.php
:
'host' => env('mqtt_host','127.0.0.1'),
'password' => env('mqtt_password',''),
'username' => env('mqtt_username',''),
'certfile' => env('mqtt_cert_file',''),
'localcert' => env('mqtt_local_cert', ''),
'localpk' => env('mqtt_local_pk', ''),
'port' => env('mqtt_port','1883'),
'debug' => env('mqtt_debug',false) //Optional Parameter to enable debugging set it to True
'qos' => env('mqtt_qos', 0), // set quality of service here
'retain' => env('mqtt_retain', 0) // it should be 0 or 1 Whether the message should be retained.- Retain Flag
Upvotes: 0