MQTT (Message Queuing Telemetry Transport) is a "lightweight" communication protocol based on publish/subscribe (publish/subscribe) mode.
The protocol was built on the TCP/IP protocol and was released by IBM in 1999.
The biggest advantage of MQTT is that it can provide real-time and reliable message service for connecting remote devices with very little code and limited bandwidth.
As a low-overhead, low-bandwidth instant messaging protocol, it has a wide range of applications in the Internet of Things, small devices, and mobile applications.
In UIFlow, we can use MQTT function to realize communication and interaction between two or more COREs, thus achieving powerful remote control functions.
To use the MQTT protocol for data interaction, you need server support. There are many third-party server platforms to choose from. The platform we demonstrate here is CloudMQTT.
When you have created service support on the platform, you will get some configuration information, such as server address, username, password, etc., which will be used in UIFlow's MQTT block.
In the advanced functions of UIFlow, you can find the MQTT function block. We can simply understand the MQTT protocol as two links, "Publish" and "Subscribe".
When the publisher posts a message, the subscriber will get this information to enable communication between devices
Add an MQTT configuration block and connect to the Setup block
Fill in the server information on your personal or third-party server platform to prepare for the next connection
Add a Start block below the MQTT configuration block, which means that it will start running after the configuration information.
Publish refers to the link in the communication to publish data, including two parts for the content of the publication "topic", "content" (msg)
Set a publishing theme, when other devices want to get the content information under the theme, you need to subscribe to the matching theme name
Set content information to be published
When the program runs to the Publish release block, the message is released. example:
When the A button is pressed, a message is posted (the subject is "RGB" and the content is "open")
When the B button is pressed, a message is posted (the subject is "RGB" and the content is "close")
Subscribe subscription refers to the process of receiving data in the communication. When the publisher publishes the information, the subscriber will automatically receive the subscribed topic (message), message content (msg)
Set the topic to subscribe to
Get the message content under this subscription
Add a Subscribe block, fill in the topic to be subscribed, use the Get topic data block to get, and process the analysis, for example:
When an "open" is obtained from Publish, the RGB bar is lit, and when "close" is obtained, the RGB bar is extinguished.
Use a CORE to program a simple use case to verify functionality, it’s not inly a publisher (Publish), but a subscriber (Subscribe) as well
When the A button is pressed, a message is posted (the subject is "RGB", the content is "open"), and the RGB bar lights up.
When the B button is pressed, a message is posted (the subject is "RGB", the content is "close"), and the RGB bar is extinguished.