Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Nov 17, 2020
1 parent 2c82287 commit 621aac3
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 7 deletions.
12 changes: 5 additions & 7 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ composer require simps/mqtt
Simps\MQTT\Client::__construct(array $config, array $swConfig = [], int $type = SWOOLE_SOCK_TCP)
```

* 参数 `array $config`
* 参数`array $config`

客户端选项数组,可以设置以下选项:

Expand All @@ -49,7 +49,7 @@ $config = [

* 参数`array $swConfig`

用于设置`Swoole\Coroutine\Client`参数,请参考Swoole文档[set()](https://wiki.swoole.com/#/coroutine_client/client?id=set)
用于设置`Swoole\Coroutine\Client`的配置,请参考Swoole文档[set()](https://wiki.swoole.com/#/coroutine_client/client?id=set)

### connect()

Expand Down Expand Up @@ -141,16 +141,14 @@ Simps\MQTT\Client->close()
接收消息

```php
Simps\MQTT\Client->recv()
Simps\MQTT\Client->recv(): bool|arary|string
```

返回值可能为`bool``array``string`

### send()

发送消息

```
```php
Simps\MQTT\Client->send(array $data, $response = true)
```

Expand All @@ -160,7 +158,7 @@ Simps\MQTT\Client->send(array $data, $response = true)

* 参数`bool $response`

是否需要回执如果为`true`,会调用一次`recv()`
是否需要回执如果为`true`,会调用一次`recv()`

### ping()

Expand Down
155 changes: 155 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,158 @@ MQTT Protocol Analysis and Coroutine Client for PHP.
[![Total Downloads](https://poser.pugx.org/simps/mqtt/downloads)](//packagist.org/packages/simps/mqtt)
[![Latest Unstable Version](https://poser.pugx.org/simps/mqtt/v/unstable)](//packagist.org/packages/simps/mqtt)
[![License](https://poser.pugx.org/simps/mqtt/license)](LICENSE)

## Install

```bash
composer require simps/mqtt
```

## Examples

see [examples](./examples)

## Methods

### __construct()

Create a MQTT client instance

```php
Simps\MQTT\Client::__construct(array $config, array $swConfig = [], int $type = SWOOLE_SOCK_TCP)
```

* `array $config`

An array of client options, you can set the following options:

```php
$config = [
'host' => '127.0.0.1',
'port' => 1883,
'time_out' => 5,
'user_name' => '',
'password' => '',
'client_id' => '',
'keep_alive' => 10,
'protocol_name' => 'MQTT', // or MQIsdp
'protocol_level' => 4, // or 3
];
```

* `array $swConfig`

To set the configuration of `Swoole\Coroutine\Client`, please see Swoole document: [set()](https://www.swoole.co.uk/docs/modules/swoole-coroutine-client-set)

### connect()

Connect Broker

```php
Simps\MQTT\Client->connect(bool $clean = true, array $will = [])
```

* `bool $clean`

Clean session. default is `true`. see [Clean Session](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc442180843)

* `array $will`

When a client is disconnected, Broker will automatically send a will message to other clients

```php
$will = [
'topic' => '',
'qos' => 1,
'retain' => 0,
'content' => '',
];
```

### publish()

push a message to a topic

```php
Simps\MQTT\Client->publish($topic, $content, $qos = 0, $dup = 0, $retain = 0)
```

### subscribe()

Subscribe to one topic or multiple topics

```php
Simps\MQTT\Client->subscribe(array $topics)
```

* `array $topics`

```php
$topics = [
// topic => Qos
'topic1' => 0,
'topic2' => 1,
];
```

### unSubscribe()

Unsubscribe from a topic or multiple topics

```php
Simps\MQTT\Client->unSubscribe(array $topics)
```

* `array $topics`

```php
$topics = ['topic1', 'topic2'];
```

### close()

Disconnect from Broker connect. The `DISCONNECT(14)` message is send to Broker

```php
Simps\MQTT\Client->close()
```

### recv()

Receive messages

```php
Simps\MQTT\Client->recv(): bool|arary|string
```

### send()

Send messages

```php
Simps\MQTT\Client->send(array $data, $response = true)
```

* `array $data`

`$data` is the data to be sent and must contain information such as `type`

* `bool $response`

Are acknowledgements required. If `true`, `recv()` is called once

### ping()

Send a heartbeat

```php
Simps\MQTT\Client->ping()
```

### buildMessageId()

Generate MessageId

```php
Simps\MQTT\Client->buildMessageId()
```

0 comments on commit 621aac3

Please sign in to comment.