This article shows how to expose points that the Weble IoT Universal Gateway already reads (BACnet, Modbus, KNX, M-Bus...) to an MQTT application: a dashboard, a historian, an IoT platform. It covers the two ways of doing it with the MQTT broker/client driver, how to publish existing addresses in a few clicks, how to group several points in one JSON message, and how to secure the connection.
The reference of every setting is on the MQTT driver page; this article gives the procedure.
The MQTT driver requires the Driver MQTT Client, Driver MQTT Broker or Full licence. Without it the gateway does not start and its log shows
missing license.
| Broker mode | Client mode | |
|---|---|---|
| Who connects to whom | MQTT applications connect to the gateway | The gateway connects to an existing broker (on site or in a cloud) |
| Typical use | Local dashboard, SCADA or Node-RED on the site network | Central broker of the customer, IoT platform |
| Ports to open | Inbound to the gateway (1883, 8883...) | Outbound from the gateway only |
| Last value for a new subscriber | Sent by the gateway at subscription | Needs Retain on the address |
In both modes a topic is an address: the address %mqtt:site/ahu1/supplyTemp is the topic site/ahu1/supplyTemp. Writing a value to the address (by hand, by a route or a logic) publishes it; a message received on the topic updates the address.
mqtt. Keep Mode = broker (default).TCP on Port 1883. Keep it for a first test.scada and a user dashboard, each with its own long password.Test from a computer of the same network with any MQTT client, for example mosquitto_sub (replace the address and the password):
mosquitto_sub -h 192.168.1.99 -p 1883 -u dashboard -P '<password>' -t '#' -v
json).More details: How the broker behaves.
You do not have to type the topics. Take the points from the gateway that reads them:
Topic names. The topic is the source address without its driver prefix:
| Source address | MQTT address created | Datatype |
|---|---|---|
%bac:192.168.1.20/analogInput:3/presentValue |
%mqtt:192.168.1.20/analogInput:3/presentValue |
number (BACnet analog and binary values) |
%knx:1/2/3 |
%mqtt:1/2/3 |
after the current value: number, string, otherwise json |
If your application expects another topic tree (for example site/ahu1/supplyTemp), insert the MQTT addresses with these names (Addresses › Insert address) and create the routes in Routes. A topic level cannot contain /, + or #, and a name that does not follow this syntax is refused with Bad MQTT address.
The same drag and drop works in client mode. There, tick Retain on the addresses so that the broker keeps the last value for applications that subscribe later, and choose the QOS (0, 1 or 2).
Many applications prefer one message per equipment rather than one topic per point. Use a parent address:
%mqtt:site/ahu1 with datatype parentJson.%mqtt:site/ahu1/supplyTemp, %mqtt:site/ahu1/fanSpeed... Tick Not a topic (local, no MQTT publish) on the children so that only the parent is published.Each time a child changes, the gateway rebuilds the object and publishes it on site/ahu1, the key being the last level of the child name:
site/ahu1 {"supplyTemp":21.4,"fanSpeed":65}
It works in the other direction too: a JSON object received on site/ahu1 updates the existing children. With parentJsonAutoInsert instead of parentJson, a key without child address creates the child automatically; use it to receive a structure you do not know in advance.
Broker mode
TLS (Add interface). Its Port becomes 8883.
wss:// through the web interface. An interface of Type WS whose Port is the HTTPS port of the gateway web interface (usually 443) is reached through the web server: WebSocket connections that announce the mqtt sub-protocol are handed over to the broker. Clients then use wss://<gateway>:443 with the certificate of the web interface.TCP interface once all clients use TLS, and restrict access to the broker ports to the networks that need them (firewall or separate network). The broker listens on all network interfaces of the device. See Securing the device.Client mode
mqtts (or wss) and the TLS port of the broker (usually 8883).[hostname] is replaced by the host name of the gateway: the same configuration can be copied to many gateways, each logging in with its own identity.| Symptom | Cause | What to do |
|---|---|---|
The client gateway keeps restarting and never shows CONNECTED; log client offline, broker unreachable |
The broker cannot be reached or refuses the connection. The driver restarts and tries again after each failure. | Check Host, Port, Protocol, user name, password and, for mqtts / wss, the certificates. |
| An external client cannot connect to the broker | Wrong user or password with useAuthenticate, wrong port or interface type, firewall. | Check the user list and the Interfaces; test with mosquitto_sub from the same network. |
Log subscribe failed for topic ... - will retry in 30s (client mode) |
The broker refuses the subscription (access rights). | If the topic may only be published, tick Publish only (no subscribe) on the address. |
Bad MQTT address when saving an address |
The name does not follow the topic syntax: missing %mqtt: prefix, empty level, trailing /, # not in last position. |
Correct the name. |
| A subscribed topic stays empty (client mode) | The broker has no retained message for it. | The value arrives with the next publication; tick Retain on the publishing side. |
The log shows missing license |
No MQTT licence. | Contact support@weble.ch. |