iot-admin/app/mqtt/Subscribe.php
2023-11-30 22:53:01 +08:00

29 lines
617 B
PHP

<?php
namespace app;
use Workerman\Worker;
class Subscribe
{
public static function onWorkerStart()
{
$mqtt = new \Workerman\Mqtt\Client('mqtt://127.0.0.1:1883', array(
//'debug' => true,
"username"=>"admin",
"password"=>"admin123456",
"client_id"=>"admin"
));
$mqtt->onConnect = function($mqtt) {
$mqtt->publish('test', 'hello workerman mqtt');
};
// $mqtt->onMessage = function($topic, $content) {
// echo "topic:$topic content:$content\n";
// };
$mqtt->connect();
}
}