Skip to main content

Build Status

The Things Network

The Things Network

Table of Contents

Description

This package provides you an easy way to connect to The Things Network via MQTT. Take note that, you’ll first need to create an application with a device to run the constructor of the MQTT client because you need to provide, an applicationID and a deviceID. First include the package in your file like this:

from ttnmqtt import MQTTClient as mqtt

MQTTClient

The class constructor can be called following this scheme:

mqtt(APPID, APPEUI, PSW)
  • APPID: this the name you gave your application when you created it.

  • APPEUI: this the unique identifier of your application on the TTN platform.

  • PSW: it can be found at the bottom of your application page under ACCESS KEYS. All the above informations can be found in your The Things Network console. The constructor returns an MQTTClient object set up with your application informations, ready for connection.

connect

Connects the previously created client to the The Things Network MQTT broker by default.

client.connect([address], [port])
  • address: the address of the MQTT broker you wish to connect to. Default to eu.thethings.network

  • port: the port on which you wish to connect. Default to 1883

disconnect

Disconnects the MQTT client from which we call the method. Also able to stop a forever loop in case the client was running on a loop launched by the start() method.

client.disconnect()

start

Start a loop as the main loop of your process. You wont be able to run anything else at the same time on this script.

client.start()

Take note that a loop need to be started in order to receive uplink messages.

startBackground

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.

client.startBackground()

stopBackground

Stops a loop which was started with the startBackground() method. It also disconnect the client.

client.stopBackground()

setUplinkCallback

Set the callback function, to be called when an uplink message is received.

client.setUplinkCallback(uplinkCallback)

uplinkCallback

The callback function must be declared in your script following this structure: * uplinkCallback(msg, client) * msg: the message received by the client * client: the client from which the callback is executed are calling

On each message reception, you should see MESSAGE RECEIVED in the console, and the callback will be executed.

setConnectBehavior

Change the connect callback function, following the paho-mqtt standart.

client.setConnectBehavior(custom_function)
  • custom_function(client, userdata, flags, rc): the function which will be the new connection behavior for our MQTT client.

  • client: the MQTT client from which we call the callback.

  • userdata: the data of the user. Default to ''

  • flags: connection flags

  • rc: result from the connect method. 0 if the connection succeeded.

click here for more information on the paho-mqtt package.

setPublishCallback

Set the publish callback function, following the paho-mqtt standart.

client.setPublishCallback(publishCallback)

publishCallback

  • publishCallback(mid, client): the function which will be the new publish behavior for our MQTT client.

  • mid: it matches the mid variable returned from the publish call to allow sent messages to be tracked.

  • client: the MQTT client from which we call the callback.

publish

Publishes a message to the MQTT broker.

client.publish(deviceID, message)
  • deviceID: the ID of the device you wish to send the message to.

  • message: the message to be published to the broker. The message that’s sent to the TTN broker needs to be a string and can follow this example (it’s not mandatory but they are mostly build on this format): json {"port": 1, "confirmed": false, "payload_raw": "AA=="} This message will send the payload 00 to your device.

License

Source code for The Things Network is released under the MIT License, which can be found in the LICENSE file. A list of authors can be found in the AUTHORS file.

Metadata

Release files for ttnmqtt 0.9.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ttnmqtt 0.9.4
File Size Uploaded
ttnmqtt-0.9.4.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ttnmqtt 0.9.4
File Interpreter ABI Platform
ttnmqtt-0.9.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 11.9 kB

Release files / ttnmqtt-0.9.4.tar.gz

Download URL ttnmqtt-0.9.4.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3a7f9e7561a46e30e98a4cd370fa2adc26c112046973504a0da5a4a87faf57fc
BLAKE2b-256 checksum
How to use checksums
83e3640f517b7c9c28dfb62c3fe2e31999043270e0702019b617b4186fce05ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / ttnmqtt-0.9.4-py2.py3-none-any.whl

Download URL ttnmqtt-0.9.4-py2.py3-none-any.whl
Size 7.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e4090018e83c9e56460060c631815347e5c09601b26b7282540350b98315bbca
BLAKE2b-256 checksum
How to use checksums
2c2e20b45312b6b039cf860fc0d6b1596f0aba26dc4ec892cdc11881bf267826
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.9.4 This release

2 release files

0.9.3

1 release file

0.9.2

3 release files

0.9.1

1 release file

0.9.0

1 release file

0.8.11

1 release file

0.8.10

1 release file

0.8.9

1 release file

0.8.8

1 release file

0.8.7

1 release file

0.8.6

1 release file

0.8.5

1 release file

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.5

1 release file

0.6.4

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

2 release files

0.6

2 release files

0.5

1 release file

0.4

2 release files

0.3

2 release files

0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page