UM016005E MQTT UserManual 20190730 Eng
UM016005E MQTT UserManual 20190730 Eng
UM016005E MQTT UserManual 20190730 Eng
MQTT
V3.00
Table of Contents
1. Overview ................................................................................................................. 1
Weintek HMI and MQTT ............................................................................................ 1
2. EasyBuilder Pro Settings ......................................................................................... 3
Server Settings ........................................................................................................... 3
System Topic............................................................................................................... 5
Topic Publisher Settings ............................................................................................. 6
Content formats ......................................................................................................... 7
Topic Subscriber Settings ........................................................................................... 9
Project and Application ............................................................................................ 10
3. Choosing an MQTT Server .................................................................................... 11
Using Built-in MQTT Server on HMI ......................................................................... 11
Using a Public Cloud MQTT Server .......................................................................... 11
Using Self-build MQTT Server .................................................................................. 11
4. References ............................................................................................................ 12
MQTT
1. Overview
Designed to be light weight, open, and simple, MQTT is a subscriber/publisher
messaging transport protocol that is considered a great solution for applications
where small code footprint is required and/or network bandwidth is scarce. It is
particularly suitable for continuous monitoring of sensory data such as temperature,
pressure, water level, energy monitoring…etc.
Publisher, Subscriber, and Server (or Broker) are three important roles in MQTT
communication protocol. The relationship between these roles is shown in the
following figure. After the subscriber subscribes to a topic, when the Publisher
publishes a message to the Server, the Server will deliver the message to the
subscriber.
Laptop
(Subscriber)
Publish: speed=30 MQTT
Sensor
Server
(Publisher)
(Broker)
Laptop
(Subscriber)
1
MQTT
2
MQTT
To manage access privileges to the server, please select [Authentication] and enter
the username and password.
4
MQTT
System Topic
When HMI is the publisher and is connected to the MQTT Server for the first time,
two system topics at QoS2 will be sent from HMI.
1. iot-2/type/mt/id/<Client ID>/evt/topics_update/fmt/json
This topic contains the all topics originating from the HMI, and whether the
messages are compressed.
2. iot-2/type/mt/id/<Client ID>/evt/status/fmt/json
This topic shows the connection status between HMI and the server.
When using an MQTT Server that has restrictions to the topics (e.g. public cloud
service), please do not enable System Topic, in order to avoid connection error.
5
MQTT
The name of the Topic can be user-defined, and by using the character % followed by
certain codes, HMI name/Server setting can be used in Topic name as well.
%0: HMI name can be found by opening System Settings on HMI, or use system
register LW-10884.
%1: Client ID for Server
%(DYNAMIC): Dynamic String
%%: character %
The next step is to select a Sending Mode from: Address (Auto.), Address (Bit trigger)
or Event (Alarm) Log.
[Address (Auto.)]:
1. Value-trigger-based: MQTT message is sent when any value in the Topic changes.
2. Time-based: Data is published at a fixed time interval.
[Address (Bit trigger)]: MQTT message is sent when a designated bit address is
triggered.
[Event (Alarm) Log]: MQTT message is sent when a selected event occurs. The event
should be configured in Event Log first.
When the sending mode is [Address], in Address tab, set the data composition that
will be contained in the topic. The addresses can be consecutive or nonconsecutive,
and of different data types and lengths.
6
MQTT
MQTT provides three levels of delivery reliability, which are known as qualities of
service (QoS). The reliability of the message determines the persistence of the
message.
QoS 0: At most once, messages are not persistent.
QoS 1: At least once.
QoS 2: Exactly once.
For more information on QoS, click here.
[Compressed transmission]: The message will be compressed before being sent, and
decompression is needed before reading the message. Supported compression
algorithms are zlib, gzip, and DEFLATE .
[Content format]: The supported formats include: Raw data, JSON (Simple) and JSON
(Advanced).
Content formats
Raw data:
When publishing four values in the following address formats:
7
MQTT
JSON (Simple):
When publishing four values in the following address formats:
"d" : {
"value 1" : [ false ],
"value 2" : [ 2 ],
},
"ts" : "2017-04-18T17:36:52.501856"
The data published will be in the common key:value format when [Include time
stamp] and [Use top-level key “d” for all addresses] options are both disabled in the
General tab, and [Remove JSON array bracket “[“ and “]”.] option is selected for each
address.
Example data:
{
"W": 7,
"B": true
JSON (Advanced): This mode allows users to configure more complex JSON format,
including nested format.
As shown in the following illustration, settings on the left will generate the JSON
formatted data on the right.
8
MQTT
[Verify timestamp]: With this option selected, whether the timestamp of each JSON
message is increasing will be checked. Only when the time stamp does increase will
the data be written into the corresponding addresses after receiving the message.
For example, if the topic subscribed contains data with the following address formats:
Bit, 16bit-unsigned, String (length 4). The address settings should be:
9
MQTT
In this example, the order from value 1 to 3 should be exactly Bit, 16bit-unsigned,
String.
The order cannot be changed, and the name and address element count should be
identical to the message source.
10
MQTT
At the first time using HMI’s MQTT server, please downloaded it to HMI using
EasyBuilder Pro. Please select [Runtime] when downloading MQTT server.
2. EMQ (http://emqtt.io/)
Please visit their respective official websites for details on installation and
restrictions.
11
MQTT
4. References
HMI MQTT is integrated into AWS IoT, allowing users to use AWS IoT in the following
ways:
1. Use AWS IoT as a standard MQTT server.
2. Use AWS IoT as an entrance for data to be transmitted to other AWS cloud
services.
3. Deep integration with AWS IoT Thing Shadow service.
12