brandonhudson / Lightning

PHP micro framework for MQTT, letting you quickly connect, publish, and subscribe to topics.
Other
6 stars 1 forks source link

Can publish but nothing on subscribe #9

Open captainreptile opened 5 years ago

captainreptile commented 5 years ago

Hello,

Thanks for the gr8 module :) I've first tested it about 1.5 year ago on laravel, now i re-implementing it on other laravel and i think i have the same issue as i had before: I am able to publish, but not get the message on subscribe. (a clue i had the same issue is that i used other module for subscribe on old laravel).

Debugging the MQTT server i do see that its subscribed but for some reason the message (retained) doesn't arrive to laravel, i also tried to delay 4 seconds to give it chance but nothing:

               $host = "127.0.0.1"; 
               $port = 1883;
               $clientID = "LARAVEL-TEST".md5(uniqid());
               $username = "test"; 
               $password =  "passTest"; 
               $mqtt = new \Lightning\App($host, $port, $clientID, $username, $password);
               if (!$mqtt->connect()) {
                 // Log error to laravel Admin
               exit(1);
               }
               // Subscribe and get message              
               $mqtt->subscribe("".$GWTopic."/isonline", 0, function (\Lightning\Response $response) {
               $GW = $response->getMessage();
               }); 
                sleep(4); 
               dd($GW);    // Undefined variable: GW
              // Only send a message if $GW is 1
              If ($GW == 1) {
            $mqtt->publish("".$GWTopic."/test/".$testID."", ''.$id.' '.$tes1.' '.$tes2.'', 1); 
            $mqtt->close();  }

Much appreciated for your kind help

brandonhudson commented 5 years ago

Thanks for submitting - I'll take a look at this. I've also run into similar situations with specific multi-protocol message brokers (like Amazon's MQ).

brandonhudson commented 5 years ago

Can you pass along information about the specific broker you're using so I can attempt to replicate?

captainreptile commented 5 years ago

Thank you for your reply.

I'm using mosquitto on my server with websockets enabled (port 9001), the test was carried on the normal mqtt port 1883 do you need access?