Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ed592b

Browse files
committed
Add publish
1 parent0388347 commit2ed592b

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

‎bin/bootstrap.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* This file is part of Simps
4+
*
5+
* @link https://github.com/simps/mqtt
6+
* @contact Lu Fei <lufei@simps.io>
7+
*
8+
* For the full copyright and license information,
9+
* please view the LICENSE file that was distributed with this source code
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
foreach (
15+
[
16+
__DIR__ .'/../vendor/autoload.php',
17+
__DIR__ .'/vendor/autoload.php',
18+
__DIR__ .'/../autoload.php',
19+
]as$file
20+
) {
21+
if (file_exists($file)) {
22+
require$file;
23+
break;
24+
}
25+
}

‎bin/mqtt‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/**
4+
* This file is part of Simps
5+
*
6+
* @link https://github.com/simps/mqtt
7+
* @contact Lu Fei <lufei@simps.io>
8+
*
9+
* For the full copyright and license information,
10+
* please view the LICENSE file that was distributed with this source code
11+
*/
12+
13+
require__DIR__ .'/bootstrap.php';
14+
15+
useSymfony\Component\Console\Application;
16+
useSimps\MQTTCLI\Command\PublishCommand;
17+
useSimps\MQTTCLI\Command\SubscribeCommand;
18+
usefunctionSwoole\Coroutine\run;
19+
20+
run(function () {
21+
try {
22+
$application =newApplication('PHPMQTT CLI Tools','v1.0.0');
23+
$application->add(newPublishCommand());
24+
$application->run();
25+
}catch (\Swoole\ExitException$e) {
26+
// Ignore swoole exit exception
27+
}
28+
});

‎src/Command/PublishCommand.php‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* This file is part of Simps
4+
*
5+
* @link https://github.com/simps/mqtt
6+
* @contact Lu Fei <lufei@simps.io>
7+
*
8+
* For the full copyright and license information,
9+
* please view the LICENSE file that was distributed with this source code
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespaceSimps\MQTTCLI\Command;
15+
16+
useSymfony\Component\Console\Command\Command;
17+
useSymfony\Component\Console\Input\InputDefinition;
18+
useSymfony\Component\Console\Input\InputInterface;
19+
useSymfony\Component\Console\Input\InputOption;
20+
useSymfony\Component\Console\Output\OutputInterface;
21+
22+
class PublishCommandextends Command
23+
{
24+
protectedstatic$defaultName ='publish';
25+
26+
protectedfunctionconfigure()
27+
{
28+
$this->setDescription('Publishing simple messages')
29+
->setHelp('An MQTT version 3.1/3.1.1/5.0 client for publishing simple messages')
30+
->setDefinition(
31+
newInputDefinition([
32+
newInputOption('host','H', InputOption::VALUE_OPTIONAL,'Specify the host to connect to','localhost'),
33+
newInputOption('port','P', InputOption::VALUE_OPTIONAL,'Connect to the port specified',1883),
34+
newInputOption('topic','t', InputOption::VALUE_REQUIRED,'The MQTT topic on which to publish the message'),
35+
newInputOption('message','m', InputOption::VALUE_REQUIRED,'Send a single message from the command line'),
36+
newInputOption('id','i', InputOption::VALUE_OPTIONAL,'The id to use for this client'),
37+
newInputOption('qos',null, InputOption::VALUE_OPTIONAL,'Specify the quality of service to use for the message, from 0, 1 and 2',0),
38+
newInputOption('dup',null, InputOption::VALUE_OPTIONAL,'',0),
39+
newInputOption('retain','r', InputOption::VALUE_OPTIONAL,'',0),
40+
newInputOption('username','u', InputOption::VALUE_OPTIONAL,'Provide a username to be used for authenticating with the broker'),
41+
newInputOption('pw','p', InputOption::VALUE_OPTIONAL,'Provide a password to be used for authenticating with the broker'),
42+
newInputOption('disable-clean-session','c', InputOption::VALUE_OPTIONAL,"Disable the 'clean session' flag",false),
43+
newInputOption('level','l', InputOption::VALUE_REQUIRED,'MQTT Protocol level',3),
44+
newInputOption('keepalive','k', InputOption::VALUE_OPTIONAL,'The number of seconds between sending PING commands to the broker for the purposes of informing it we are still connected and functioning',0),
45+
newInputOption('will-topic','wt', InputOption::VALUE_OPTIONAL,'The topic on which to send a Will, in the event that the client disconnects unexpectedly'),
46+
newInputOption('will-message','wm', InputOption::VALUE_OPTIONAL,'Specify a message that will be stored by the broker and sent out if this client disconnects unexpectedly'),
47+
newInputOption('will-qos','wq', InputOption::VALUE_OPTIONAL,'The QoS to use for the Will',0),
48+
newInputOption('will-retain','wr', InputOption::VALUE_OPTIONAL,'If given, if the client disconnects unexpectedly the message sent out will be treated as a retained message',0),
49+
])
50+
);
51+
}
52+
53+
protectedfunctionexecute(InputInterface$input,OutputInterface$output)
54+
{
55+
return Command::SUCCESS;
56+
}
57+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp