Reputation: 1
I'm using a simple MQTT client in PHP - https://github.com/sskaje/mqtt - and want to retrieve exactly one message (which is retained - always there) from broker, and then display it on a page. Everything works good, but I cannot get it to display the whole page. It displays "Test Text 1", then debugging code, then my message, and stops there, not showing "Test Text 2" nor "Test Text 3". If anyone would help me, I would be incredibly grateful, as I have no idea at all, what does not work, and have spent a lot of time working on it. Thanks!
Test Text 1
<?php
require('spMQTT.class.php');
$mqtt = new spMQTT('tcp://127.0.0.1:1883/');
spMQTTDebug::Enable();
$mqtt->setKeepalive(5);
$connected = $mqtt->connect();
if (!$connected) {
die("Not connected\n");
}
$topics['#'] = 0;
$mqtt->subscribe($topics);
$mqtt->loop('default_subscribe_callback');
$mqtt->unsubscribe(array_keys($topics));
printf("Test Text 2");
/**
* @param spMQTT $mqtt
* @param string $topic
* @param string $message
*/
function default_subscribe_callback($mqtt, $topic, $message) {
printf("Message received: Topic=%s, Message=%s\n", $topic, $message);
break;
}
?>
Test Text 3
Upvotes: 0
Views: 702
Reputation: 11618
I'm not familiar with that mqtt library, but it looks very much like the call to loop()
is blocking, so you will have to approach the problem differently.
Upvotes: 1