MQTT: An Introduction to the Lightweight Messaging Protocol

Eden Ko·2023년 5월 10일
0

what is MQTT?

MQTT, which stands for Message Queuing Telemetry Transport, is a lightweight messaging protocol designed for the Internet of Things (IoT). It was first developed in 1999 by Dr. Andy Stanford-Clark of IBM and Arlen Nipper of Arcom Control Systems.

MQTT is designed to be a simple, efficient, and reliable protocol for connecting devices and sensors over a network. It is particularly well-suited for IoT applications where bandwidth and power are limited, and where devices need to communicate in real-time.

features of MQTT

One of the key features of MQTT is its lightweight nature. The protocol uses a publish/subscribe messaging model, which means that devices can send and receive messages without establishing a continuous connection. This reduces the amount of data that needs to be transmitted and saves power, making MQTT an ideal protocol for battery-powered devices.

MQTT is also designed to be scalable and flexible. It supports multiple quality-of-service levels for message delivery, and can be used over a variety of network protocols including TCP/IP, WebSockets, and MQTT-SN (MQTT for Sensor Networks). This makes it a versatile protocol that can be used in a wide range of applications.

MQTT is widely used in a variety of industries, including healthcare, automotive, smart homes, and industrial automation. It is also used by popular IoT platforms such as Amazon Web Services (AWS) IoT and Microsoft Azure IoT.

In conclusion, MQTT is a powerful and lightweight messaging protocol that is well-suited for IoT applications. Its simplicity, scalability, and flexibility make it an ideal choice for connecting devices and sensors over a network, and its low power requirements make it ideal for battery-powered devices. As the IoT continues to grow, MQTT is likely to play an increasingly important role in the development of new applications and services.

To use MQTT

To use MQTT, devices must connect to a broker, which acts as a mediator between publishers and subscribers. The broker receives messages from publishers and forwards them to all subscribers that have subscribed to the relevant topic. Subscribers can filter messages by subscribing to specific topics, allowing them to receive only the messages that are relevant to their needs.


MQTT란?

메시지 큐 텔레메트리 전송의 약자인 MQTT는 사물 인터넷(IoT)을 위해 설계된 경량 메시징 프로토콜입니다. 1999년에 IBM의 앤디 스탠포드-클락 박사와 Arcom Control Systems의 알렌 니퍼가 처음 개발했습니다.

MQTT는 네트워크를 통해 장치와 센서를 연결하기 위한 간단하고 효율적이며 신뢰할 수 있는 프로토콜로 설계되었습니다. 대역폭과 전력이 제한되어 있고 디바이스가 실시간으로 통신해야 하는 IoT 애플리케이션에 특히 적합합니다.

MQTT 특징

MQTT의 주요 특징 중 하나는 경량성이라는 점입니다. 이 프로토콜은 게시/구독 메시징 모델을 사용하므로 기기가 지속적인 연결을 설정하지 않고도 메시지를 주고받을 수 있습니다. 따라서 전송해야 하는 데이터의 양이 줄어들고 전력을 절약할 수 있어 배터리로 구동되는 디바이스에 이상적인 프로토콜입니다.

또한 MQTT는 확장성과 유연성을 갖추도록 설계되었습니다. 메시지 전송을 위한 다양한 서비스 품질 수준을 지원하며, TCP/IP, 웹소켓, MQTT-SN(센서 네트워크용 MQTT) 등 다양한 네트워크 프로토콜을 통해 사용할 수 있습니다. 따라서 다양한 애플리케이션에서 사용할 수 있는 다목적 프로토콜입니다.

MQTT는 의료, 자동차, 스마트 홈, 산업 자동화 등 다양한 산업 분야에서 널리 사용되고 있습니다. 또한 Amazon Web Services(AWS) IoT 및 Microsoft Azure IoT와 같은 인기 있는 IoT 플랫폼에서도 사용됩니다.

결론적으로 MQTT는 IoT 애플리케이션에 적합한 강력하고 가벼운 메시징 프로토콜입니다. 단순성, 확장성, 유연성 덕분에 네트워크를 통해 디바이스와 센서를 연결하는 데 이상적인 선택이며, 전력 소모량이 적어 배터리로 구동되는 디바이스에 이상적입니다. IoT가 계속 성장함에 따라 새로운 애플리케이션과 서비스 개발에서 MQTT의 역할이 점점 더 중요해질 것입니다.

MQTT 사용

MQTT를 사용하려면 디바이스가 퍼블리셔와 구독자 사이의 중개자 역할을 하는 브로커에 연결해야 합니다. 브로커는 퍼블리셔로부터 메시지를 수신하여 관련 토픽을 구독한 모든 구독자에게 전달합니다. 구독자는 특정 토픽을 구독하여 메시지를 필터링할 수 있으며, 이를 통해 자신의 필요와 관련된 메시지만 수신할 수 있습니다.


Mosquitto MQTT broker

Mosquitto 브로커 설치

broker.local # apt-get install mosquitto 
broker.local # netstat -nap | grep mosquitto
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      1512/mosquitto  
tcp6       0      0 :::1883                 :::*                    LISTEN      1512/mosquitto

Mosquitto 클라이언트 설치

# apt-get install mosquitto-clients

Pub/Sub 테스트

hello/hi 토픽을 subscribing.

# mosquitto_sub -d -t hello/hi
Received CONNACK
Received SUBACK
Subscribed (mid: 1): 0

hello/hi 토픽에 Publishing.

# mosquitto_pub -d -t hello/hi -m "Hello World"
Received CONNACK
Sending PUBLISH (d0, q0, r0, m1, 'hello/hi', ... (11 bytes))

Sub 클라이언트는 "Hello World"를 전송 받는다.

  • modquitto_sub를 하나 더 실행 한다음 "Hello World"를 publishing 해보자. 토픽에 subscribing한 모든 클라이언트에 메시지가 전달되는 걸 확인할 수 있다.

https://www.joinc.co.kr/w/man/12/MQTT/Tutorial
https://12bme.tistory.com/18

profile
Junior Developer

0개의 댓글