Skip to content
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

Undefined index: qos. #46

Open
antmorm opened this issue Jul 5, 2021 · 4 comments
Open

Undefined index: qos. #46

antmorm opened this issue Jul 5, 2021 · 4 comments

Comments

@antmorm
Copy link

antmorm commented Jul 5, 2021

When I try to subscribe to a topic, I get this error:

Undefined index: qos.

Here's how I make a subscription:

Mqtt::ConnectAndSubscribe('test', function ($topic, $msg) { echo "Msg Received: \n"; echo "Topic: {$topic}\n\n"; echo "\t$msg\n\n"; });

(As in the example, I inserted it into a controller).

Taking a look I noticed that the problem is here:

$buffer .= chr($callback["qos"]);
in MqttService:175

If I solve the problem adding a simple "?? 0", when I try to subscribe, it doesn't seems to work.
It enters on
while($client->proc()) loop (Mqtt:114) but after a publish, I don't receive the message.

I'm using Laravel 5.8 with PHP 7.1.33 and "salmanzafar/laravel-mqtt": "^2.0".

@chrisbeaver
Copy link

When I receive a message on a topic I subscribe to I get this error as well.

image

@muhammadaldan
Copy link

How you fix this? i have same problem to

@chrisbeaver
Copy link

I traced through the code, and found that when you first call ConnectAndSubscribe, inside the library a call to function subscribe() is made. That Line 173 above passes because it is a single array coming in with "qos" set to zero.

Not until a message is received does it crash. And I traced through the code to find out why. Rather than an array coming in with ["qos" => 0, " "function" => $proc], it now comes back as a nested array, with key value pairs keyed with the $topic name.

I have NO CLUE AT ALL if this is CORRECTs, but it stopped breaking my code. All I did was change line 173 in Salman\Mqtt\MqttClass\MqttService to look like this. It permits the first pass, and then it permits subsequent passes in my use case.

I'm not saying it is correct, but I'm going to be working with it and testing to see if I'm getting my desired results.

$buffer .= isset($callback["qos"]) ? chr($callback["qos"]) : chr($callback[$key]["qos"]);

image

@chrisbeaver
Copy link

Spending a little more time on it, I went back and changed this line here to just set the initial value to an empty array.

https://github.com/salmanzafar949/MQTT-Laravel/blob/master/src/MqttClass/Mqtt.php#L105

However, the code in this repo is all just an older copy and paste of Bluerhinos PHP MQTT library. So I built my own that pulls in the current Bluerhinos library using Composer since I ran into additional issues that appear to have been fixed in Bluerhino's updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants