Skip to content

Usage of MQTT nodes

The most important terms in the MQTT telemetry protocol are explained below.

Note

  • Use MQTT nodes for productive use cases only or you can connect with MindSphere connectivity features. For more information on MindSphere Connectivity, see Connectivity.
  • These MQTT nodes are used with some limitations. For more information on limitations, see Technical specifications.
  • MQTT is now enabled for subtenants also.
  • MQTT nodes are not available for Region Europe 2.

MQTT message

A message with MQTT consists of several parts:

  • A defined subject ("Topic")
  • An assigned criterion for "Quality of Service"
  • The message text

MQTT Client

An MQTT Client is a program or device that uses MQTT. A client always actively establishes the connection to the broker. A client can perform the following functions:

  • Send messages with a defined subject ("Topic"), in which other clients might be interested, to the MQTT Broker (Publish mechanism)
  • Subscribe messages which follow a certain topic (Subscriber mechanism) at the MQTT Broker
  • Unsubscribe yourself from subscribed messages
  • Disconnect from the broker

On-boarding process

To onboard MQTT client, follow these steps:

  1. In Visual Flow Creator, click menu bar and select "MQTT Management" MQTT User management
  2. Create the credentials for the client.
  3. Enter the credentials from the client side.
    • Credential limitations: Username begin with in MQTT User Management.
    • Client ID starts with that could be selected by user.

Note

  • Adhere with all the client's unique identifiers to connect with the client.

  • Only Visual Flow Creator admin can use "MQTT User Management" page.

MQTT Broker

An MQTT Broker is the central component of MQTT and can be a program or a device. The MQTT Broker acts as an intermediary between the sending MQTT Client and the subscribing MQTT Client. The MQTT Broker manages the topics including the messages contained therein and regulates the access to the topics. The MQTT Broker has the following functions:

  • Accept network connections from the MQTT Clients
  • Receive messages from an MQTT Client
  • Edit subscription requests from MQTT Clients
  • Forward messages to the MQTT Clients that match your subscription

Note

Visual Flow Creator provides you the own MQTT broker with address .

Topics

MQTT messages are organized in topics. A topic "describes" a subject area. The topics can be subscribed to by the MQTT Clients (subscriber mechanism). The sender of a message (Publisher mechanism) is responsible for defining content and topic when sending the message. The broker then takes care that the Subscribers get the news from the subscribed topics. The topics follow a defined scheme. They are similar to a directory path and represent a hierarchy.

Note

The client can only subscribe on the topics and publish the topics that starts from vfc//.

MQTT ports

MQTT defines an OASIS or ISO standard (ISO/IEC PRF 20922). Depending on the protocols used, MQTT runs on different access ports. Visual Flow Creator offers the following ports:

8883: MQTT, encrypted

443: MQTT via WebSockets, encrypted

Architecture

The MQTT is a publish and subscribe protocol. This mechanism decouples a client sending messages (Publishers) from one or more clients receiving the messages (Subscribers). This also means that the "Publishers" know nothing about the existence of the "Subscribers" (and vice versa). There is a third component in the MQTT architecture, the MQTT Broker. The MQTT Broker is located between "Publisher" and "Subscriber". The MQTT Broker controls the communication.

Quality of Service (QoS)

The MQTT specification provides three service qualities for message transmission quality assurance:

  • QoS "0": The lowest level 0 is a "fire'n'forget" method. This means that there is no guarantee that the message will arrive at all.
  • QoS "1": The QoS level 1 ensures that the message ends up in the topic queue at least once. The MQTT Broker acknowledges receipt of the message.
  • QoS "2": In the highest level 2, the MQTT Broker guarantees by multiple handshake with the MQTT Client that the message is exactly filed once.

Last will

MQTT supports the "Last Will and Testament" feature. This feature is used to notify other MQTT Clients if the connection to a MQTT Client has been disconnected accidentally.

Each MQTT Client can specify its last will while connecting to the MQTT Broker and notify the MQTT Broker. This last will is built like a normal MQTT message, including topic, QoS and payload. The MQTT Broker saves the last will. As soon as the MQTT Broker notices that the connection with the MQTT Client in question has been abruptly terminated, the MQTT Broker sends the last will as an MQTT message to all subscribers who have registered for the topic. In this way, the subscribers also learn that the MQTT Client has been disconnected.

Keep-Alive

MQTT supports the "Keep-Alive" feature. This ensures that the connection is still open and the MQTT Client and MQTT Broker are connected.

For the Keep-Alive, the MQTT Clients define a time interval and communicate it to the MQTT Broker during their connection setup. This interval is the largest possible tolerated time period in which the MQTT Client and the MQTT Broker may remain without contact. If the time is exceeded, the MQTT Broker must disconnect.

That means that, as long as the MQTT Client periodically sends messages to the broker within the Keep-Alive interval, the MQTT Client does not need to take any special action to maintain the connection. However, if the MQTT Client does not send any messages within the Keep-Alive interval, they must ping the MQTT Broker before the deadline expires. With this ping, the MQTT Client signals to the MQTT Broker that it is still available.

When a message or a ping packet has been sent to the MQTT Broker, timing for the Keep-Alive interval begins again.

Message persistence

If the connection to an MQTT Client is interrupted, the broker can cache new messages for this client for later delivery.

Retained messages

The first time an MQTT Client subscribes to a topic, it usually gets a message only when another MQTT Client sends a message with the subscribed topic the next time. With "Retained messages", the subscriber receives the last value sent to the topic prior to its subscription request, delivered immediately.

MQTT IN

mqtt in

The MQTT IN node allows you to subscribe to the specfied topic.

MQTT OUT

mqtt out

The MQTT OUT node allows you to publish the messages to MQTT broker. The following properties are avaialble for MQTT5 and Visual Flow Creator supports MQTT5.

Node property Description
User Properties It allows to appear multiple times to represent multiple names and value pairs in the "Object" format
Response topic It is used as the topic name for a response message in the "String" format
Correlation Data It is used to identify the Response Message as per the "Request Message" received in the "String" format
Content Type It describes the content of the application message in the following formats:
- application/json
- application/octet-stream
- text/csv
- text/html
- text/plain
- other
Expiry (secs) It is the process time of the application message in seconds

Example for MQTT IN

The following example shows to subscribe to the messages from the specified topic using the MQTT IN node:

  1. Create the flow as shown below:

    Create flow

  2. Edit mqtt in node properties and enter the details:

    Edit mqtt in node

    Note

    The subscription topic can include MQTT wildcards, "+" for one level, "#" for multiple levels.

  3. Save and execute the flow.

Result

The specified topic is successfully subscribed.

Example for MQTT OUT

The following example shows to publish the messages using the MQTT OUT node:

  1. Create the flow as shown below:

    VFC

  2. Edit inject node properties:

    • Payload (string): VFC MQTT
  3. Edit mqtt out node properties and enter the details:

    edit mqtt out node

  4. Save and execute the flow.

Result

The output is displayed in the message payload:

Message payload

Any questions left?

Ask the community


Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.


Last update: July 13, 2022