MQTT 订阅问题
我是参考 https://github.com/bluerhinos/phpMQTT收MQTT没问题,但改用CI去接收就不行
请问要怎么改才能运作?
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//include_once(__DIR__ . '/../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;
}
} 报什么错呢? Hex 发表于 2019-5-29 23:35
报什么错呢?
并没有提示错误,看起来是没有呼叫function procmsg 您是怎么解决的? 解决了吗?
页:
[1]