pdf-icon

MQTT

What is MQTT?

MQTT (Message Queuing Telemetry Transport). >MQTT (Message Queuing Telemetry Transport) is a "lightweight" communication protocol based on the publish/subscribe model. The protocol is built on the TCP/IP protocol, as a low-overhead, low-bandwidth instant messaging protocol, so that it has a wide range of applications in the Internet of Things, small devices, mobile applications and so on.

UIFlow and MQTT

In UIFlow, we can use the MQTT function to achieve communication and interaction between two or more COREs, so as to achieve powerful remote control functions.

MQTT server

Select MQTT service.

To use MQTT protocol for data interaction, you need server support, there are many third-party server platforms to choose from, here we demonstrate the platform for CloudMQTT.

When you have created the service support in the platform, you will get some configuration information, such as server address, username, password, etc., which will be used in the MQTT block of UIFlow.

The MQTT function.

In UIFlow's advanced features, you can find the MQTT function block, we can understand the MQTT protocol simply as two links, "publish" (Publish) and "subscribe" (Subscribe)

When the publisher publishes a message , the subscriber will get this information , so as to achieve the communication between the device .

Initialisation procedure

MQTT configuration block

Add an MQTT configuration block and connect it to the Setup block.

`Fill in the information'

Fill in your personal or third-party server information to prepare for the next connection.

Note

When you have more than one device in use at the same time, the ID name (ID "M5stack" in the picture below) is not allowed to be repeated with other options in the configuration information. >When you have more than one device at the same time, the ID name (the ID in the picture below is "M5stack") is not allowed to be duplicated with other options in the configuration information, and also not allowed to be duplicated with the ID of other devices, and only one device with the same ID name is allowed to be online in the same server at the same time, if you need to download the program to the device to run it, you need to add a Wi-Fi connection at the initialization of the program. If you need to download the program to your device, you need to add Wi-Fi connection to the program initialization.

MQTT Start

Add a Start block below the MQTT configuration block, which means that it will start running when the configuration information is available.

Publish

Function

Publish means to publish data in the newsletter, which contains two parts: "topic" and "msg".

Publish(topic)

Set a topic, when other devices want to get the content information under the topic, they need to subscribe to the matching topic name.

Publish(msg)

Set the content information to be published

Usage

When the program runs into the Publish block, it will publish the message. Example: When button A is pressed, the message is published (subject is "RGB", content is "open", when button B is pressed, the message is published (subject is "RGB", content is "close").

Subscribe

Function

Subscribe subscription refers to the process of receiving data in the newsletter, when the publisher publishes a message, the subscriber will automatically receive the subscribed topic (topic), the content of the message (msg).

Subscribe (topic)

Set the topics to subscribe to

Get topic data (msg)

Get the content of messages under this subscription

Usage

Add Subscribe block and fill in the topic to be subscribed, use Get topic data block to get it and process to analyze it, for example.

When get an "open" from Publish, light up the RGB bar, when get a "close", extinguish the RGB bar.

Use cases

Implementing Functionality

Program a simple use case with a CORE to verify the functionality, it is even the publisher (Publish), is also a subscriber (Subscribe)

`Full program'

Usage

When the A button is pressed, a message is posted (subject "RGB", content "open") and the RGB bar lights up.

When the B button is pressed, a message is posted (subject is "RGB", content is "close"), and the RGB bar goes out.

On This Page