This is an old revision of the document!
MQTT today has become an intermediary in IoT communication. It is supported by integration controller WebHMI(About how to use MQTT on WebHMI) and 7bit brand products such as Synapse, AirPoint and AirGate.
It is a lightweight, open and affordable protocol. It was designed for severe operating conditions, so it is ideal for devices with low power and limited autonomous. Such as smartphones, sensors and other devices, the number of which is constantly growing. MQTT has extremely low overhead publish/subscribe model, and bidirectional capabilities of MQTT are uniquely suited to meet the demands of industrial control systems. To understand, look at this diagram.
There is no need in direct connection which is quite fragile and entails overhead. So, the broker is the gamechanger. Any device can be both publisher and subscriber. Publishing of message is triggered only by some event, e.g. time condition. After that, the data packet is received by the broker and then sent to subscribers, which subscribed to that topic which data was published. In that way, the subscriber can get the data about events that happened on distant objects, collected from different publishers and collect it in a database to obtain further analytics. Therefore, it would be suitable to apply for electricity consumption monitoring, but also measuring non-electrical quantities.
WebHMI is able to communicate using MQTT. Using this protocol WebHMI can act as a subscriber and a broker.
To start, firstly go to “Settings” to make sure that “MQTT Server” is turned on.
There is a possibility to create a WebHMI connection to subscribe or publish MQTT messages. This allows WebHMI register mapping with certain topics on any broker. So editing register value will trigger WebHMI to publish MQTT message and vice versa: if you have an active register, receiving the message from the broker will trigger changing the value.
Acting as a client, WebHMI can connect to any broker, i.e. its own MQTT broker.
Let’s post something to the WebHMI MQTT Broker from a WebHMI MQTT Client. It is convenient to stay subscribed to the topics in “MQTT.fx”, but this time publish with a WebHMI. To start publish something to broker it is necessary to become a client, so need to create a connection to it.
Click on “New connection” and configure it with:
Device Model: MQTT Address: 192.168.1.1 (it is your IP of WebHMI with Broker ) TCP Port: 1883
After that, create a new register into that connection which will represent MQTT topic related to MQTT broker. Click “New register” and fill in the following settings: When the connection is created and active it means that connection is established with the broker, let’s create a register with “Address” filled with the same topic name “iot-test”. Also it would be useful to add Lua script alias, e.g. “mqtt_publish”. It will be used in the script later.
Connection: MQTT WebHMI Client (that one, that created before) Address: iot-test (any name, it is MQTT topic to subcribe and to publish) Script alias: mqtt_publish
Now, it is time to change registers value manually and check the result response on another client such as Android app, PC clients such as “MQTT.fx” or another WebHMI.
Using any MQTT client it is possible to be connected to WebHMI MQTT Broker. For example, freeware MQTT client “MQTT.fx” will be used.
Profile Type: "MQTT Broker Profile Name: e.g. “WebHMI” Broker Address: 192.168.1.21, this is the IP of the WebHMI. Broker Port: 1883
Press “Apply” and then “OK”.
Let’s connect to WebHMI Broker by pressing the “Connect” button.
In the Google Play Market, there is a lot of MQTT Client apps. For example, it would be shown the connection with MQTT Dashboard.
After first run it looks like this:
So, let’s add WebHMI Broker by click “Add first broker” button.
Fill in the following settings. In the address form your WebHMI IP address. In our case, it is 192.168.1.21.
Then, click the “Save” button in the bottom centre position.
Now, we have an empty connection. It is time to subscribe to a topic. It is also an option to publish to it. To do this, let’s click the “+” button in the bottom centre part of the screen.
To demonstrate how the function works, the “Standard” format will suffice.
Fill in the “Subscribe topic” form the “iot-test” value and then press “Copy” symbol near “Publish topic” to copy the topics name to this form also. In the end, click the “Save” icon in the bottom centre position.
The text message was sent through the MQTT protocol to WebHMI broker and the sent to the Android app.