walkor / mqtt Goto Github PK
View Code? Open in Web Editor NEWAsynchronous MQTT client for PHP based on workerman.
Asynchronous MQTT client for PHP based on workerman.
连续new 两个对象会报错
for($i=0;$i<2;$i++){
$mqtt = new Workerman\Mqtt\Client(...)
}
PHP Warning: Cannot declare class \Workerman\Protocols\Mqtt, because the name is already in use in
For Subscribe how do i set QoS => 1 on $option?
$mqtt = new Workerman\Mqtt\Client($mqtt_link, array( 'debug' => true, 'clean_session' => false, 'qos' => 1, "client_id" => "mqtt-client-cronjob", "username" => $mqtt_user, "password" => $mqtt_pass ));
but i got qos:0 on return
laravel 中使用只能使用一个进程,多了无法使用
use \Workerman\Lib\Timer;
加密MQTT使用场景越来越多,是否可以考虑像WSS一样加入证书支持?
I've altered the chatroom example to let the user exit the chatroom:
$console = new TcpConnection(STDIN);
$console->onMessage = function($console, $message) use ($mqtt){
$message=trim($message);
if ($message=="exit") {
$mqtt->disconnect();
die;
} else {
$mqtt->publish('testRoom', $message);
}
};
When the user enters "exit" I want the worker to stop but it reconnects always. I've tried using "$mqtt->doNotReconnect=true;" but it doesn't work.
Anyone knows how to do this?
硬件问题,已经解决
`public function handle()
{
global $argv;
$action = $this->argument('action');
if (!in_array($action, ['start', 'stop'])) {
$this->error('Error Arguments');
exit;
}
$argv[0] = 'workerman:httpserver';
$argv[1] = $action;
$argv[2] = $this->option('daemonize') ? '-d' : '';
$worker = new Worker();
$worker->onWorkerStart = function () {
// $mqtt = new Client('mqtt://192.168.0.247:1883');
$mqtt = new \Workerman\Mqtt\Client('mqtt://192.168.0.247:1883');
Log::info(1);
$mqtt->onConnect = function ($mqtt) {
$mqtt->subscribe('test');
$this->info(2);
};
$mqtt->onMessage = function ($topic, $content) {
var_dump($topic, $content);
$this->info($content);
};
};
Worker::runAll();
}`
I have integrated workerman mqtt in the CodeIgniter framework.
I am running the code from the terminal as following:
php index.php controller function start
In the function, I have added the workerman mqtt code. I have to change the argument key for command in "Worker.php" file as following:
$command = trim($argv[3]);
$command2 = isset($argv[4]) ? $argv[4] : '';
Replaced $argv[1] with $argv[3] and $argv[2] with $argv[4]. It is working fine.
When I run php index.php controller function start -d
, The code that I put into onMessage function is not working. Which is working fine in DEBUG mode.
Following is the output when I run in DEAMON mode
Input "php index.php stop" to stop. Start success.
Hello! I am using bunny to work with RabbitMQ, the code is:
$client = (new Bunny\Client())->connect()->channel();
// ...
$channel->run(function(Message $message, Channel $channel, Client $client) {
// --> here i need to send a message to MQTT broker;
}, 'hello', '', FALSE, TRUE);
It is infinite loop, so i need to send message and return to loop, is it possible?
在 trait 上调用 static 元素 ¶
在 trait 上直接调用 static 方法、直接访问 static 属性的行为已被废弃。静态方法和属性只能在使用了 trait 的类上被访问。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.