In Mervis IDE, the MQTT protocol is technically implemented as a client driver. However, because Mervis RT can both publish (provide) and subscribe to (receive) data, it effectively operates in both ways. It is included in the server protocols section because it acts as a data provider to other systems via the central Broker.
Data is organized using “Topics,” which are hierarchical structures that act as paths where data is published. For example, a base folder could be building/hvac, with sub-folders like building/hvac/temp.
(Note on Organization: Mervis supports Prototypes to help you systematically organize your naming conventions across large projects. While we won't cover them deeply here, they are highly recommended for keeping your variables clean.)
broker.emqx.io on port 1883. Please note: This is for testing only and should never be used for production data.building/hvac.Useful Macros When setting up your Client ID or Topics, you can use case-insensitive macros to automatically pull in system data. Using these ensures you have the full context without typing repetitive names.
| Macro | Description |
|---|---|
ClientId | Injects the defined MQTT Client ID. |
PlcName | Injects the assigned name of the PLC. |
system.rtc | Injects the system's Real-Time Clock (local time). |
system.rtcutc | Injects the system's Real-Time Clock in Coordinated Universal Time (UTC). |
Mervis RT uses Read Groups to subscribe to a topic, parse the document, and update values in your program.
Read_Group. Mervis RT uses this group to create a document and send it out to the broker.
Write_Group. foreach control block is incredibly useful for looping through multiple variables, it is not mandatory. You can write out your template entirely manually if you prefer.(Note for new users: The process of mapping data points and handling Enums here is a general feature of Mervis client channels. If you have used Modbus or other protocols in Mervis before, this process will be very familiar.)
Inside your Read_Group, create a data point for your input.
IO ⇒ ST to your target variable.$.temp for JSON) to tell Mervis exactly where to look in the incoming payload. If using CSV, use the Index property to specify the exact position of the value (using a 1-based index).
Inside your Write_Group, create a data point for your result (e.g., Total).
ST ⇒ IO to your target variable. With your communication variables mapped, you can use them in standard IEC 61131-3 logic.
In a practical application, you might map two similar MQTT inputs (for example, adding Power_Zone_1 and Power_Zone_2 together to calculate a facility's total power consumption). The math block computes the sum, and the result is written directly to your global MQTT output variable (Calculated_Total).
To ensure everything is working smoothly, use a desktop client like MQTTX to simulate real-world data traffic. This lets you see the direct results of the custom Publish Templates you created in Step 2.
broker.emqx.io:1883).building/hvac/# so you can monitor all data passing through your base topic.building/hvac/temp. Use the format you configured (e.g., JSON: {“temp”:5,“humidity”:50} or a standard CSV line).