andrerolfs.github.io

View on GitHub

20200321 Why MQTT

MQTT is a client server system meant for communicating data.

The name part Telemtry does not mean you may only use it for that or may only publish numbers, as I have read here, Facebook are using MQTT as part of their transfer protocol for the Facebook Messenger.

Some people start learning MQTT by writing their own messenger as first example.

My aim is to use MQTT for all kinds of interprocess communication, instead of socket communication.

If you have read my ideas about my automation framework CISystem you may have seen I have spend quite some time on the theory of using Socket communication, but till now I did not write much code for it, because I feel it is like re-inventing the wheel once more. I just want to communicate, I don’t want to implement a protocol for communication plus a language how to interpret what to do with the data.

MQTT helps me a lot, because there I only need to think of the language describing what the data means.

Roughly summarized, MQTT works like this :

  1. You have a server where you can plublish data
  2. You have clients connecting to the server for publishig data and/or subscribing to topics
  3. The topics are trees of addresses like a/b/c/d/…
  4. The clients can subscribe for single topics or whole branches

There are free libraries for all computer languages to implement clients with.

There are free servers for all computer operation systems.

There are free client applications you can use to

Especially the last point is extremely cool, it speeds up the debugging process very much compared to what you have to do to debug socket communication code.

Yes, all of this depends on having a MQTT server and most likely the libraries for client software have a larger footprint than coding socket communication with native OS functions, but then why is MQTT the default communication protocol on Arduino devices, e.g. for home automation? Let’s just say, even if it has a bigger footprint, this is currently not an issue for me.

So for using MQTT I only need to decide the language, means the topics and their branch structure, I want to use to exchange data between my clients.