Searching...

Matching results

    Introduction to MQTT

    Initializing Table Of Contents...

    What is MQTT?

    MQTT (MQ Telemetry Transport) is a publish/subscribe protocol for M2M applications. It’s now an OASIS standard. It’s a simple protocol, easy to implement for any client.

    This procotol supplies:

    • Open source clients available in multiple languages;
    • Small bandwidth footprint;
    • Define configuration for secure transport through TLS;
    • Add support for registering MQTT-only device on AirVantage;
    • WebSocket transport for connecting directly from a web page;

    The supported version is 3.1.1

    Security

    MQTT must be secured using TLS (Transport Layer Security) the successor of SSL. TLS will create a secure tunnel between your client and the server. The server will be authenticated using a X.509 certificate (like for HTTPS websites).

    Publish/Subscribe

    MQTT uses the publish/subscribe paradigm. Clients connect to a “broker”, in our case the AirVantage server. Clients can publish messages on “topics”. All the subscribers to this topic will receive the messages. A client can connect to any topic. This allows one-to-one, many-to-one or one-to-many communication patterns.

    Topics

    A topic name is an UTF-8 string. It’s used by the broker for matching publisher and subscribers. Topics can be composed using “/” separators. A topic doesn’t need to be created upfront, just publish a message on a given topic.

    AirVantage Reserved topics

    AirVantage uses some specific topics to be used if you want to publish data in the AirVantage data store, define alerts, visualize the data or stream it to your servers. Specific topics are also used for receiving operation tasks (like read, write, commands) from AirVantage operations. This is described in the page Using MQTT with AirVantage .

    Subscription wildcards

    A client can use wildcards for subscribing to a set of topics. Wildcards are not allowed in publish topics, only for subscribing.

    Wildcards are used with topic hierarchy. The topic hierarchy is defined by the “/” used for separating the different sections of a topic.

    The possible wildcards are:

    • ”+” for a single level in the topic hierarchy, can be used multiple time in a subscription topic
    • ”#” for matching multiple levels in the hierarchy, but it needs to be the last character of the topic subscription

    Quality-of-Service (QoS) levels

    You can send MQTT publish or subscribe messages with a QoS level (0, 1 or 2).

    Each different level provides different guarantees of delivery priority.

    • QoS 0: At most one-time delivery. Your data can be lost. No retransmission outside of TCP.
    • QoS 1: At least one-time delivery. Your data will be retransmitted if needed. The message can be received more than once.
    • QoS 2: Exactly one-time delivery. The message will be delivered exactly once but the communication overhead is high (multiple acknowledgement messages).

    Retained messages

    When you publish a message on a topic you can ask the broker to retain the last value for this topic. When a client subscribes to this topic it will receive the last retained value.

    Last will and testament

    When a client connects it can ask the broker to publish a specified message on a specified topic if the client disconnects abruptly (without sending the MQTT disconnect message).

    Persistent session

    A client connecting to the broker can specify if it wants a persistent session. This type of session will make the broker keep the undelivered message with QoS 1 or 2. So if the client disconnects, the server will keep the messages and send them at the next reconnection with the same “client ID”.

    Protocol Configuration

    • Port: 8883 (SSL/TLS) or 1883 (but without security!)
    • url: tcp://eu.airvantage.net
    • Username: Serial Number (but IMEI can be used as well)

    Payload Format

    MQTT is payload-agnostic, so you can use any format as payload.

    However we have defined a format for you to use with the MQTT protocol to connect your embedded application to Using MQTT with AirVantage .

    Troubleshooting communications

    Using MQTT with AirVantage : The MQTT Errors section explains how to receive trace logs of the data you are sending and how to troubleshoot communications with AirVantage.

    More on MQTT

    MQTT.org

    Eclipse Paho

    MQTT standard at OASIS

    Understand the MQTT protocol

    Connect your hardware to AirVantage with MQTT

    TOP