iot-admin/app/mqtt/Subscribe.php

26 lines
583 B
PHP
Raw Normal View History

2023-11-30 22:53:01 +08:00
<?php
2023-12-01 10:30:07 +08:00
namespace app\mqtt;
2023-11-30 22:53:01 +08:00
class Subscribe
{
public static function onWorkerStart()
{
2023-12-01 10:30:07 +08:00
$mqtt = new \Workerman\Mqtt\Client('mqtt://ceshi-mqtt.lihaink.cn/tcp', array(
// 'debug' => true,
"username"=>"demo2",
"password"=>"123456",
"client_id"=>"mqttx_4fde83eb"
2023-11-30 22:53:01 +08:00
));
$mqtt->onConnect = function($mqtt) {
2023-12-01 10:30:07 +08:00
$mqtt->subscribe('demo');
};
$mqtt->onMessage = function($topic, $content) {
echo "topic:$topic content:$content\n";
2023-11-30 22:53:01 +08:00
};
$mqtt->connect();
}
2023-12-01 10:30:07 +08:00
2023-11-30 22:53:01 +08:00
}