You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 14, 2021. It is now read-only.
Copy file name to clipboardExpand all lines: DOCUMENTATION.md
+13-23Lines changed: 13 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -19,23 +19,20 @@
19
19
20
20
## Description
21
21
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.
26
23
27
24
### MQTTClient
28
25
29
26
The class constructor can be called following this scheme:
30
27
```python
31
28
mqtt(appID, appAccessKey, [mqttAddress])
32
29
```
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.
34
31

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**.
36
33

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.
39
36
40
37
### connect
41
38
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
49
46
client.close()
50
47
```
51
48
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
-
58
49
### start
59
50
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.
60
51
```python
@@ -69,7 +60,7 @@ client.stop()
69
60
70
61
### Using Callbacks
71
62
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.
73
64
74
65
#### setUplinkCallback
75
66
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:
83
74
*`msg`: **JSON object** the message received by the client
84
75
*`client`: **object** the client from which the callback is executed are calling
85
76
86
-
On each message reception, you should see **receving message from** in the console, and the callback will be executed.
87
-
88
77
#### setConnectCallback
89
78
Set the connection callback function to be executed when the client connect to the broker.
90
79
```python
91
80
client.setConnectCallback(connectCallback)
92
81
```
93
82
##### connectCallback
94
83
-`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.
96
85
-`client`: **object** the TTN client from which we call the callback.
-`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
+

125
115
-`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`.
0 commit comments