"Lung linh bóng nước con đò, Nhớ sao Chợ Mới câu hò thủy chung
Quê tôi miền đất anh hùng, Hôm nay vẫn đẹp vô cùng ai ơi!"

"Giờ thăm lại trường xưa trong khoảnh khắc
Cảnh còn đây người đi mất từ lâu..."

"對我而言台灣留下非常深刻的印象,我所去的每一個地方,我所見過的每一個人,這都是緣分!
再見大家,再見台灣!"

A greeting from Vietnam.

Thursday, February 1, 2018

MQTT Protocol

MQTT Protocol Overview

MQTT protocol is a power-saving M2M protocol widely used in Internet of things. MQTT protocol is used to send and receive data from smart objects.
This protocol used publish-subscriber paradigm in contrast to HTTP based on request/response paradigm. It uses binary messages to exchange information with a low overhead. MQTT uses TCP stack as transmission substrate.

Message Pattern

MQTT protocol implements publish-subscriber paradigm. This paradigm decouples a client that publishes a message (“publisher”) to other clients that receive the message (“subscribers”). Moreover, MQTT is asynchronous protocol, that means that it does not block the client while it waits for the message. In contrast to HTTP protocol, that is mainly a synchronous protocol. Another interesting property of MQTT protocol is that it does not require that the client (“subscriber”) and the publisher are connected at the same time.

MQTT Publisher-Subscriber Pattern (MQTT Broker, MQTT Client)

The key component in MQTT is the MQTT broker, which dispatches messages to the MQTT clients (“subscribers”). In other words, the MQTT broker receives messages from publisher and dispatches these messages to the subscribers. While it dispatches messages, the MQTT broker uses the topic to filter the MQTT clients that will receive the message.
A topic is a virtual channel that connects a publisher to its subscribers. This topic is managed by the MQTT broker. Through this virtual channel, the publisher is decoupled from the subscribers and the MQTT clients (publishers or subscribers) do not have to know each other to exchange data. This makes this protocol highly scalable without a direct dependency from the message producer (“publisher”) and the message consumer (“subscriber”).
The schema below describes the MQTT architecture:

How To Use MQTT Protocol

There are several implementations of MQTT, for example, Mosquitto, an implementation developed by Eclipse. The first step is installing the MQTT broker.
The MQTT server (aka MQTT broker) is installed on Raspberry Pi. This server is our MQTT broker. Then we need to install the client, or in other words, the publisher and the subscriber. You can install client and server on the same Raspberry, or install it on a different pc/server or IoT board.

How To Send An MQTT Message

We have installed and configured the client and the server, now we can register a subscriber to a specific topic and wait for an incoming message from a publisher.