我是参考 https://github.com/bluerhinos/phpMQTT
执行范例接收MQTT没问题,但改用CodeIgniter去接收就不行
请问要怎么改才能运作?<?php
defined('BASEPATH') OR exit('No direct script access allowed');include_once(__DIR__ . '/../third_party/phpMQTT.php');class MQTT_subscribe extends CI_Controller { public function __construct()
{
parent::__construct();
} public function MQTTSubscribe()
{
$server = "IP"; // change if necessary
$port = 1883; // change if necessary
$username = "XXX"; // set your username
$password = "XXX"; // set your password
$client_id = "phpMQTT-subscriber"; // make sure this is unique for connecting to sever - you could use uniqid() $mqtt = new phpMQTT($server, $port, $client_id); if(!$mqtt->connect(true, NULL, $username, $password)) {
goto err_out;
} $topics['bluerhinos/phpMQTT/examples/publishtest'] = array("qos" => 0, "function" => "procmsg"); $mqtt->subscribe($topics, 0); while($mqtt->proc()){
}
$mqtt->close(); err_out:
return ;
}
function procmsg($topic, $msg){
//echo "Msg Recieved: " . date("r") . "\n";
//echo "Topic: {$topic}\n\n";
//echo "\t$msg\n\n"; err_out:
return $msg;
}
}
执行范例接收MQTT没问题,但改用CodeIgniter去接收就不行
请问要怎么改才能运作?<?php
defined('BASEPATH') OR exit('No direct script access allowed');include_once(__DIR__ . '/../third_party/phpMQTT.php');class MQTT_subscribe extends CI_Controller { public function __construct()
{
parent::__construct();
} public function MQTTSubscribe()
{
$server = "IP"; // change if necessary
$port = 1883; // change if necessary
$username = "XXX"; // set your username
$password = "XXX"; // set your password
$client_id = "phpMQTT-subscriber"; // make sure this is unique for connecting to sever - you could use uniqid() $mqtt = new phpMQTT($server, $port, $client_id); if(!$mqtt->connect(true, NULL, $username, $password)) {
goto err_out;
} $topics['bluerhinos/phpMQTT/examples/publishtest'] = array("qos" => 0, "function" => "procmsg"); $mqtt->subscribe($topics, 0); while($mqtt->proc()){
}
$mqtt->close(); err_out:
return ;
}
function procmsg($topic, $msg){
//echo "Msg Recieved: " . date("r") . "\n";
//echo "Topic: {$topic}\n\n";
//echo "\t$msg\n\n"; err_out:
return $msg;
}
}
但function procmsg沒被呼叫
并没有提示错误