diff --git a/app/mqtt/Publish.php b/app/mqtt/Publish.php index 6918a19..c337715 100644 --- a/app/mqtt/Publish.php +++ b/app/mqtt/Publish.php @@ -1,29 +1,22 @@ true, - "username"=>"admin", - "password"=>"admin123456", - "client_id"=>"admin" + $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->subscribe('test'); - }; - $mqtt->onMessage = function($topic, $content) { - echo "topic:$topic content:$content\n"; + $mqtt->publish('demo', 'hello workerman mqtt'); }; + // $mqtt->onMessage = function($topic, $content) { + // echo "topic:$topic content:$content\n"; + // }; $mqtt->connect(); } - } \ No newline at end of file diff --git a/app/mqtt/Subscribe.php b/app/mqtt/Subscribe.php index 09544e7..50c56d6 100644 --- a/app/mqtt/Subscribe.php +++ b/app/mqtt/Subscribe.php @@ -1,29 +1,26 @@ true, - "username"=>"admin", - "password"=>"admin123456", - "client_id"=>"admin" + $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->publish('test', 'hello workerman mqtt'); + $mqtt->subscribe('demo'); + }; + $mqtt->onMessage = function($topic, $content) { + echo "topic:$topic content:$content\n"; }; - // $mqtt->onMessage = function($topic, $content) { - // echo "topic:$topic content:$content\n"; - // }; $mqtt->connect(); } + } \ No newline at end of file diff --git a/config/process.php b/config/process.php index f22f488..c2c4525 100644 --- a/config/process.php +++ b/config/process.php @@ -1,4 +1,5 @@ DIRECTORY_SEPARATOR === '/', ] ] - ] + ], + // 'mqtt_push' => [ + // 'handler' => app\mqtt\Publish::class, + // 'listen' => 'websocket://0.0.0.0:8955', + // 'count' => 1, + // ], + 'mqtt_sub' => [ + 'handler' => app\mqtt\Subscribe::class, + 'listen' => 'websocket://0.0.0.0:8956', + 'count' => 1, + ], ];