
Examples: IOT protocols with transparent mode
Get started with MQTT
Digi XBee® 3 Cellular LTE-M/NB-IoT Global Smart Modem User Guide
71
Get started with MQTT
MQ Telemetry Transport (MQTT) is a messaging protocol that is ideal for the Internet of Things (IoT)
due to a light footprint and its use of the publish-subscribe model. In this model, a client connects to a
broker, a server machine responsible for receiving all messages, filtering them, and then sending
messages to the appropriate clients.
The first two MQTT examples do not involve the XBee Smart Modem. They demonstrate using the
MQTT libraries because those libraries are required for
Use MQTT over the XBee Cellular Modem with
.
The examples in this guide assume:
n
Some knowledge of Python.
n
An integrated development environment (IDE) such as PyCharm, IDLE or something similar.
The examples require:
n
An XBee Smart Modem.
n
A compatible development board.
n
XCTU. See
n
That you install Python on your computer. You can download Python from:
https://www.python.org/downloads/
.
n
That you install the
pyserial
and
paho-mqtt
libraries to the Python environment. If you use
Python 2, install these libraries from the command line with
pip install pyserial
and
pip
install paho-mqtt
. If you use Python 3, use
pip3 install pyserial
and
pip3 install paho-mqtt
.
n
The full MQTT library source code, which includes examples and tests, which is available in the
paho-mqtt github repository at
https://github.com/eclipse/paho.mqtt.python
. To download this
repository you must have Git installed.
Example: MQTT connect
This example provides insight into the structure of packets in MQTT as well as the interaction
between the client and broker. MQTT uses different packets to accomplish tasks such as connecting,
subscribing, and publishing. You can use XCTU to perform a basic example of sending a broker a
connect packet and receiving the response from the server, without requiring any coding. This is a
good way to see how the client interacts with the broker and what a packet looks like. The following
table is an example connect packet:
Description
Hex value
CONNECT packet fixed header
byte 1
Control packet type
0x10
byte 2
Remaining length
0x10
CONNECT packet variable header
Protocol name