iot-admin/app/mqtt/Publish.php
2023-12-01 10:30:07 +08:00

22 lines
577 B
PHP

<?php
namespace app\mqtt;
class Publish
{
public static function onWorkerStart()
{
$mqtt = new \Workerman\Mqtt\Client('mqtt://ceshi-mqtt.lihaink.cn/tcp', array(
"username"=>"demo2",
"password"=>"123456",
"client_id"=>"mqttx_4fde83eb"
));
$mqtt->onConnect = function($mqtt) {
$mqtt->publish('demo', 'hello workerman mqtt');
};
// $mqtt->onMessage = function($topic, $content) {
// echo "topic:$topic content:$content\n";
// };
$mqtt->connect();
}
}