The basic rule
A topic should describe what is measured and where – not with what. The metering point stays, the device gets replaced. A topic that contains the serial number is worthless after the first defect.
This order, from coarse to fine, has proven itself:
| Level 1 | Property or site |
|---|---|
| Level 2 | Building or wing |
| Level 3 | Floor, zone or unit |
| Level 4 | Metering point by plant designation |
| Level 5 | Measured quantity |
Example: plant-north/hall-2/zone-east/mdb-feeder-04/active-energy-import
Why the order matters
MQTT subscriptions use wildcards: + for exactly one level, # for everything below. These wildcards only work properly when the hierarchy runs from coarse to fine.
plant-north/# delivers everything from the plant. plant-north/+/+/+/active-energy-import delivers all active energy import values, regardless of hall and zone. With a structure that starts with the measured quantity, none of these queries works.
Five pitfalls that cost money later
- Serial number in the topic. Does not survive the first device replacement.
- Unit in the topic, for example
.../energy-kwh. If the scaling changes, the topic changes. Units belong in the payload. - Special characters, spaces and capital letters. Often technically allowed, in practice a source of unnoticed problems. Use lower case and hyphens.
- Time in the topic, for example a date per day. Creates an endless number of topics and makes subscriptions impossible.
- No spare level. When a second building is added, the whole structure has to be rebuilt.
What belongs in the payload
The topic says where. The payload says what and when. For energy data, a small JSON object with value, unit, timestamp and a status field has proven itself.
The timestamp in the payload is not optional. It separates the time of measurement from the time of delivery – and makes it possible to detect duplicates from QoS 1 and to place values delivered late correctly. Without it, a value delivered after a broker outage cannot be told apart from a current one.
The EMU M-Center allows freely configurable topics and QoS; the MQTT function requires a licence and is TLS-encrypted.
Settle before the first publish
- Scheme in writing, agreed with the receiving system
- Naming rules: lower case, hyphens, no special characters
- One spare level for future sites or buildings
- Payload format with value, unit, timestamp, status
- Who may publish, who may subscribe
The same principle applies to BACnet object names – except that renaming there is even more expensive.