26 lines
583 B
PHP
26 lines
583 B
PHP
<?php
|
|
|
|
namespace app\mqtt;
|
|
|
|
class Subscribe
|
|
{
|
|
|
|
public static function onWorkerStart()
|
|
{
|
|
$mqtt = new \Workerman\Mqtt\Client('mqtt://ceshi-mqtt.lihaink.cn/tcp', array(
|
|
// 'debug' => true,
|
|
"username"=>"demo2",
|
|
"password"=>"123456",
|
|
"client_id"=>"mqttx_4fde83eb"
|
|
));
|
|
$mqtt->onConnect = function($mqtt) {
|
|
$mqtt->subscribe('demo');
|
|
};
|
|
$mqtt->onMessage = function($topic, $content) {
|
|
echo "topic:$topic content:$content\n";
|
|
};
|
|
$mqtt->connect();
|
|
}
|
|
|
|
|
|
} |