walkor / mqtt

Asynchronous MQTT client for PHP based on workerman.
207 stars 46 forks source link

onMessage接收多次回调数据 #24

Closed hsSam closed 3 months ago

hsSam commented 3 months ago

image

webman/plugin/webman/gateway/Events.php

`<?php

namespace plugin\webman\gateway;

use GatewayWorker\Lib\Gateway;

class Events { public static function onWorkerStart($worker) { $mqtt = new \Workerman\Mqtt\Client( 'mqtt://bltiot.vip:1883', ['username' => 'test', 'password' => 'xxxxx'] ); $mqtt->onConnect = function ($mqtt) { $mqtt->subscribe('mini/744DBD7120F2/msg/get'); }; $mqtt->onMessage = function ($topic, $content) { // var_dump($topic, bin2hex($content)); echo $topic . "\n"; echo bin2hex($content) . "\n"; }; $mqtt->connect(); } `