MQTT (Message Queue Telemetry Transport) is a simple TCP/IP-based messaging protocol which enables the transmission of messages from devices to the server. A distinction is made between the MQTT server (“Broker”) and the MQTT clients. MQTT is particularly suitable for automation solutions.
Simple schematic example:
The client connects to an MQTT server via TCP/IP, usually requiring a user name and password. The client can easily send messages with a topic to the MQTT server. The content of the messages is not specified, for example, it can be a simple text message or a structured message consisting of several fields.
The client can also receive messages by registering for special topics. The broker then forwards messages for the registered topics to existing MQTT clients, provided they are connected at the time of the message. Basically, the client can be a very simple device or even a server that wants to receive and send messages.
The MQTT broker is a server that can be seen as a messaging center for all MQTT participants. The MQTT broker also manages users and access rights. The broker does not actively establish connections to other MQTT devices but the MQTT clients must log on to the broker. As long as the connection is established, the broker can send and receive messages to the client. A TCP/IP connection is used to transport the data. Depending on what brokers and clients support, the connection can be SSL-encrypted.
MQTT works even if clients installed behind a DSL router in private networks log on to the broker.
MQTT Topics, Subscribe and Publish
Topics can be seen as a kind of subject subdivision of messages. This is usually a line of text that is often separated by a “/”. Only if a client has registered for one or more topics, messages for these topics are forwarded by the broker to the registered clients.
Example of various topics:
MQTT clients can register for one or more topics. This process is called Subscribe.
MQTT clients can send a message with a topic to the broker. This process is called Publish. It can only be ensured that the broker is connected and receives the message. However, whether the broker forwards this message to other clients is unknown at first.