Blog/MQTT

MQTT12 May 20265 minutes

Planning MQTT topics: a scheme that survives a device replacement

The topic scheme is a decision that takes five minutes during setup and then determines for years how usable the data is. Renaming later means re-linking every connection in every target system.

Key points

  • Structure by location and function, never by serial number.
  • Order the hierarchy from coarse to fine so that wildcards work.
  • Units and timestamps belong in the payload, not in the topic.
  • A scheme that can grow has a spare level built in.

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 1Property or site
Level 2Building or wing
Level 3Floor, zone or unit
Level 4Metering point by plant designation
Level 5Measured 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

  1. Serial number in the topic. Does not survive the first device replacement.
  2. Unit in the topic, for example .../energy-kwh. If the scaling changes, the topic changes. Units belong in the payload.
  3. Special characters, spaces and capital letters. Often technically allowed, in practice a source of unnoticed problems. Use lower case and hyphens.
  4. Time in the topic, for example a date per day. Creates an endless number of topics and makes subscriptions impossible.
  5. 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.

Frequently asked questions


How should an MQTT topic for energy data be structured?

Hierarchically from coarse to fine, and by location and function rather than by device: property, building, zone, metering point, measured quantity. That way wildcards work and the scheme survives a device replacement.

Does the unit belong in the topic?

No. Unit, timestamp and status belong in the payload. If the unit is in the topic, a change in scaling changes the path and with it every subscription.

Why does the payload need a timestamp?

It separates the time of measurement from the time of delivery. This makes it possible to detect duplicates from QoS 1 and to place values delivered after an interruption correctly.

Read more


TXTMQTT for energy data: broker, topics and QoS explainedBlog post TXTGetting meter data into the cloud: MQTT with the EMU M-CenterBlog post SEITETCP/IP interfaceInterface

Questions about your project?


Send us your meter list and the target system. We will tell you what works together – and what does not.

Phone
+41 (0)41 545 03 00

Technical support
helpdesk [at] emuag.ch
Support form →