Blog/MQTT

MQTT26 May 20266 minutes

MQTT for energy data: broker, topics and QoS explained

MQTT comes from remote monitoring of pipelines: little bandwidth, unreliable connections, many measuring points. It is no coincidence that today it carries meter data from buildings – the conditions are the same.

Key points

  • The broker sits in the middle; sender and receiver do not know each other.
  • Topics are hierarchical paths, not addresses.
  • QoS 1 is the usual compromise for meter readings.
  • Retain and last will solve two typical problems of metering systems.

Publish and subscribe instead of request and response

Most fieldbus protocols follow a request-response pattern: a master asks, a device answers. MQTT turns this around. A device publishes its values without knowing whether anyone is listening. Whoever needs the values subscribes to them at the broker.

This leads to the most important property: decoupling. A second dashboard, an analytics platform or a research project can subscribe to the same values without any change to the device in the basement. With Modbus, that would be one more client polling on top.

Topics: paths, not addresses

A topic is a hierarchical path, for example site/building-a/basement/meter-03/active-energy-import. There is no central registration – a topic comes into being when someone publishes to it.

Subscriptions use wildcards: + for one level, # for everything below. site/building-a/# delivers everything from building A. This makes the structure of the topic tree the real data architecture – and explains why a well-thought-out scheme pays off. Concrete recommendations are in Planning MQTT topics.

QoS, retain and last will

QoS 0Send and forget. For values that will be sent again shortly anyway.
QoS 1Deliver at least once. Duplicates possible, loss not. The normal case for meter readings.
QoS 2Exactly once. Costly, rarely needed.
RetainThe broker keeps the last value per topic. A newly connected dashboard shows data straight away instead of an empty screen.
Last willA message the broker publishes when the connection drops unexpectedly. A failure becomes visible instead of staying silent.

The last two are underrated in metering systems. Retain solves the empty dashboard after a restart. Last will solves the bigger problem: a failed device goes unnoticed, because in a publish model silence looks like normal operation.

Why MQTT suits building data

  • Outgoing connection – no inbound firewall rule needed
  • Low overhead, works over mobile networks too
  • Several consumers without extra load on the device
  • TLS encryption
  • Copes with interrupted connections

In practice the first point is the one that decides. More in Getting meter data into the cloud.

What MQTT is not

MQTT is not storage. The broker delivers and forgets – apart from the retained message. If you need history, you need a database behind it or local buffering in front of it. The EMU M-Center has 16 GB for this purpose and can deliver missed values after an interruption.

MQTT is also not a query protocol. A value that nobody has published cannot be requested. If you need instantaneous values on demand, Modbus TCP serves you better – or use both in parallel.

Frequently asked questions


What is an MQTT broker?

The exchange between senders and receivers. Devices publish messages under a topic to the broker, and interested parties subscribe to that topic. Sender and receiver do not know each other, only the broker.

Which QoS level do I need for meter readings?

Usually QoS 1 – delivery at least once. Duplicates can occur and can be discarded using a timestamp in the payload, whereas lost values could not be recovered.

Does MQTT store my readings?

No. The broker delivers and forgets, apart from the retained message per topic. History needs a database behind it or local buffering in front of it, such as the 16 GB in the EMU M-Center.

Read more


TXTPlanning MQTT topics: a scheme that survives a device replacementBlog 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 →