Skip to content
This repository was archived by the owner on Dec 14, 2021. It is now read-only.

Commit 8acf076

Browse files
committed
doc: Add image for encoder function and removed some unecessary precisions
1 parent deefdb7 commit 8acf076

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

DOCUMENTATION.md

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,20 @@
1919

2020
## Description
2121

22-
This package provides you an easy way to connect to The Things Network via MQTT. First include the package in your file like this:
23-
```python
24-
from ttnmqtt import MQTTClient as mqtt
25-
```
22+
This package provides you an easy way to connect to The Things Network via MQTT.
2623

2724
### MQTTClient
2825

2926
The class constructor can be called following this scheme:
3027
```python
3128
mqtt(appID, appAccessKey, [mqttAddress])
3229
```
33-
- `appID`: **string** this the name you gave your application when you created it.
30+
- `appID`: **string** this the name given to the application when it was created.
3431
![Screenshot of the console with app section](./images/app-console.png?raw=true)
35-
- `appAccessKey`: **string** it can be found at the bottom of your application page under **ACCESS KEYS**.
32+
- `appAccessKey`: **string** this can be found at the bottom of the application page under **ACCESS KEYS**.
3633
![Screenshot of the console with accesskey section](./images/accesskey-console.png?raw=true)
37-
- `mqttAddress`: **string** this the address of the handler to which your application was registered.
38-
The constructor returns an **MQTTClient object** set up with your application informations, ready for connection.
34+
- `mqttAddress`: **string** this is the address of the handler to which the application was registered.
35+
The constructor returns an **MQTTClient object** set up with the application informations, connected to The Things Network.
3936

4037
### connect
4138
This function connect your client, in case you closed it and which to open the connection once again.
@@ -49,12 +46,6 @@ Disconnects the MQTT client from which we call the method. Also able to stop a f
4946
client.close()
5047
```
5148

52-
### startForever
53-
A background loop is started by default when creating an MQTT client but in in case you wish to start a loop as the main loop of your process. You can start a forever loop with this method. You wont be able to run anything else at the same time on this script.
54-
```python
55-
client.startForever()
56-
```
57-
5849
### start
5950
Starts a loop for the client in the background so that it's possible to run another process (such as a web server) in the same script. This loop is started by default when creating the MQTT client. So it should only be used in case the client was stopped and you wish to start it again after re-connecting.
6051
```python
@@ -69,7 +60,7 @@ client.stop()
6960

7061
### Using Callbacks
7162

72-
The callback functions are functions which are executed when a trigger event happens. They should be set right after the MQTT client creation so that they don't miss any event.
63+
The callback functions are functions which are executed when a trigger event happens.
7364

7465
#### setUplinkCallback
7566
Set the callback function, to be called when an uplink message is received.
@@ -83,16 +74,14 @@ The callback function must be declared in your script following this structure:
8374
* `msg`: **JSON object** the message received by the client
8475
* `client`: **object** the client from which the callback is executed are calling
8576

86-
On each message reception, you should see **receving message from** in the console, and the callback will be executed.
87-
8877
#### setConnectCallback
8978
Set the connection callback function to be executed when the client connect to the broker.
9079
```python
9180
client.setConnectCallback(connectCallback)
9281
```
9382
##### connectCallback
9483
- `connectCallback(res, client)`: the function which will be executed on connection to the broker.
95-
- `res`: **int** the result of the connection. If it's 0, it went well. If not, it means the connection failed.
84+
- `res`: **boolean** the result of the connection. If it's 0, it went well. If not, it means the connection failed.
9685
- `client`: **object** the TTN client from which we call the callback.
9786

9887
#### setDownlinkCallback
@@ -112,16 +101,17 @@ client.setCloseCallback(closeCallback)
112101
```
113102
##### closeCallback
114103
- `closeCallback(res, client)`: the function which will be executed when the connection is closed.
115-
- `res`: **int** the result of the disconnection. If it's 0, it went well. If not, it means the disconnection was unexpected.
104+
- `res`: **boolean** the result of the disconnection. If it's 0, it went well. If not, it means the disconnection was unexpected.
116105
- `client`: **object** the TTN client from which we call the callback.
117106

118107
### send
119-
Publishes a message to the MQTT broker.
108+
Sends a downlink to the device.
120109
```python
121110
client.send(deviceID, payload, [port], [confirmation], [schedule])
122111
```
123112
- `deviceID`: **string** the ID of the device you wish to send the message to.
124-
- `payload`: the payload of the message to be published to the broker. It can be an hexadecimal **string** like `AQ==` (this will send the raw payload `00` to your device) or an object with several fields following the **JSON** standard.
113+
- `payload`: the payload of the message to be published to the broker. It can be an hexadecimal **string**, a base64 **string** like `AQ==` (this will send the raw payload `01` to your device) or an object with several fields following the **JSON** standard. In case it's a **JSON** object with fields, please make sure the **encoder** function (Payload Formats section) of the application is set to make sense of the informations transmitted in each field.
114+
![Screenshot of an encoder function in the console](./images/encoder-function.png?raw=true)
125115
- `port`: **int** the port of the device to which you wish to send the message. Default value to 1.
126-
- `confirmation`: **boolean** this boolean indicates if you wish to receive a confirmation after sending the downlink message. Default value to False.
127-
- `schedule`: **string** this string provide the type of schedule on which the message should be sent it can take values such as `first` or `last`. Default value to `replace`.
116+
- `confirmation`: **boolean** This boolean indicates if you wish to receive a confirmation after sending the downlink message. Default value to False.
117+
- `schedule`: **string** this string provide the type of schedule on which the message should be sent. It can take values such as `first` or `last`. Default value to `replace`.

images/encoder-function.png

25.5 KB
Loading

0 commit comments

Comments
 (0)