Mainstream IoT Protocol Choice: MQTT, CoAP or LwM2M?

With the development and popularization of the Internet of Things technology, more and more smart devices have network connection and data transmission capabilities. Due to the complexity and variety of IoT scenarios, various factors such as device-side hardware conditions, network stability, traffic restrictions, device power consumption, and the number of device connections cause the message delivery of IoT devices to be very different from traditional Internet scenarios. Various IoT communication protocols.

This article will select several mainstream IoT protocols, and introduce them one by one from the technical characteristics, applicable scenarios, relative advantages and market conditions of the protocols, so as to provide reference for IoT practitioners and help you choose suitable IoT protocols in actual projects. Internet Protocol.

Protocol classification

Before the introduction, we briefly classify the IoT protocols to facilitate readers to understand their application scenarios.

From a functional point of view

From a functional point of view, we can divide them into two categories, one is the physical layer/data link layer protocol , and the other is the application layer protocol .

The physical layer/data link layer protocol is generally responsible for the networking and communication between devices, such as 2G/3G/4G/5G, NB-IoT, WiFi, ZigBee, LoRa and these long-distance communications, as well as short-range ones such as RFID, NFC, Bluetooth protocol wireless protocol and RS232, USB and other wired protocols.

The application layer protocol is mainly a device communication protocol running on the traditional Internet TCP/IP protocol. This kind of protocol supports the data exchange and communication between the device and the cloud platform through the Internet. Common ones are HTTP, MQTT, CoAP, LwM2M and XMPP etc. agreement.

From an application point of view

From the perspective of the application of protocols in IoT systems, we can divide protocols into cloud protocols and gateway protocols.

The cloud protocol is a protocol built on TCP/IP. IoT data such as sensors and control devices usually need to be transmitted to the cloud, through which users can be connected and integrated with enterprise systems.

IoT devices supporting TCP/IP can access the cloud through WIFI, cellular network and Ethernet, using HTTP, MQTT, CoAP, LwM2M and XMPP and other application layer protocols.

Device networking

The gateway protocol is a protocol suitable for short-distance communication that cannot be directly connected to the cloud, such as Bluetooth, ZigBee, LoRa, etc. Such devices need to be connected to the cloud through the TCP/IP protocol after the access gateway is converted.

Bluetooth, ZigBee, LoRa Gateway

ZigBee

Zigbee is a mesh networking wireless protocol designed for building and home automation applications and is one of the most popular mesh protocols in the IoT environment. At present, it is mainly used for connection in the local area network, and on the device side, it accesses and controls various devices as a gateway.

Protocol Features

  • Low power consumption: The transmit power is only 1mW. In the low-power standby mode, two AA batteries can be used for up to 2 years, eliminating the trouble of charging or frequent battery replacement.

  • Low cost: Due to the simple and compact protocol, the requirements for communication control are greatly reduced, thereby reducing the hardware cost, and at the same time exempting the protocol patent fee.

  • Low rate: ZigBee works at a rate of 20 to 250kbps, providing 250kbps (2.4GHz), 40kbps (915 MHz), and 20kbps (868 MHz) raw data throughput rates to meet the application requirements of low-rate data transmission.

  • Short distance: The transmission range of adjacent nodes is between 10 and 100m, which basically covers ordinary home and office environments; after increasing the transmission power, it can be increased to 1 to 3km. Through the relay of routing and inter-node communication, the transmission distance will be longer.

  • Low latency: ZigBee has a fast response speed. Generally, it only takes 15ms to switch from sleep to working state, and it only takes 30ms for nodes to connect to the network, which further saves power. In comparison, Bluetooth needs 3 to 10s, and WiFi needs 3s.

  • High capacity: ZigBee can adopt star, sheet and mesh network structures, and one master node manages several sub-nodes, and one master node can manage 254 sub-nodes at most; A large network of 65,000 nodes is formed.

  • High security: ZigBee provides CRC data packet integrity check function, supports authentication and authentication, adopts AES-128 encryption algorithm, and each application can flexibly determine its security attributes.

  • License-exempt frequency bands: Direct Sequence Spread Spectrum for Industrial Science Medical (ISM) frequency bands: 2.4GHz (Global), 915MHz (North America), 868MHz (Europe).

market conditions

Zigbee technology has outstanding advantages such as low power consumption, large node capacity, short delay, safety and reliability, which can meet the needs of smart home applications and is the core wireless networking connection technology for smart homes. Benefiting from the rapid development of China's smart home market, the number of smart home devices applying Zigbee technology continues to grow, and the pace of Zigbee technology application and promotion is accelerating.

Compared with WiFi and Bluetooth technologies, which are also wireless LAN technology systems, Zigbee technology has outstanding advantages in power consumption, node capacity, self-organizing network capability, and security, and its application scale is constantly expanding.

Reference: How much do you know about ZigBee technology?

NB-IoT

NB-IoT is a new type of cellular technology formulated by the 3GPP standardization organization. It belongs to a low-power wide-area (LPWA) Internet of Things connection. It is mainly used to connect terminals with limited bandwidth resources. Technologies such as LTE require fewer resources to collect and exchange data.

NB-IoT developed rapidly in 2017-2018, and many operators around the world have successively achieved commercial deployment. The low cost, low power consumption and wide coverage of NB-IoT enable users to realize new scenarios and applications that traditional cellular networks cannot support.

On July 9, 2020, 3GPP announced that the 5G R16 standard was frozen, and NB-IoT was officially incorporated into the 5G standard, becoming the core technology for 5G mMTC massive IoT connection scenarios.

Protocol Features

  • A low-power "sleep" mode (PSM, eDRX) was introduced.

  • It reduces the communication quality requirements and simplifies the terminal design (half-duplex mode, protocol stack simplification, etc.).

  • Two function optimization modes (CP mode, UP mode) are used to simplify the process and reduce the interaction between the terminal and the network.

  • Ultra-low coverage, the coverage is enhanced by 20dB on the basis of GPRS, and the coverage is three times that of GPRS.

market conditions

At present, NB-IoT has entered the era of 100 million connections. With the full coverage construction of commercial NB-IoT 5G networks by global operators, NB-IoT will be used in smart homes, smart agriculture, industrial manufacturing, energy meters, fire smoke Continued outbreaks in various fields such as sense, logistics tracking, and financial payment.

Taking China Telecom IoT Open Platform as an example, the platform realizes centralized access to China Telecom NB-IoT and other network IoT devices, and provides services such as IoT device management, data interface and application enablement for government and enterprise users .

EMQ has participated in the platform's construction from the very beginning, and cooperated with Tianyi IoT to develop NB-IoT device access and message routing capabilities for the platform, and also supports the access of telecom TLINK, MQTT and other protocol devices, and the overall design of the platform's access capabilities billions.

Reference: An article to understand the four key characteristics of NB-IoT and implementation technologies

LoRa

The LoRa protocol is a low-power, long-distance, wireless WAN standard protocol, and its name comes from the abbreviation of "Long Range".

Compared with other wireless communication protocols such as ZigBee, Bluetooth, and WIFI, the biggest feature of LoRa is that the propagation distance is longer under the same power consumption, and the unity of low power consumption and long distance is realized. The distance is expanded 3-5 times.

LoRa has a variety of wireless technologies in IoT applications, which can form a local area network or a wide area network. The LoRa network is mainly composed of four parts: terminal (with built-in LoRa module), gateway (or base station), server and cloud.

The data transmission rate of LoRaWAN ranges from 0.3 kbps to 37.5 kbps. In order to maximize the battery life of the terminal device and the overall network capacity, the LoRaWAN network server controls the data transmission rate and each network capacity through an Adaptive Data Rate (ADR) scheme. The RF output power of a terminal device.

Protocol Features

  • Coverage: The coverage distance of a single LoRa gateway is generally in the range of 3-5km, and even more than 15km in wide areas.

  • Low power consumption: The rechargeable battery power supply system can be supported for many years or even more than ten years.

  • High capacity: Thanks to the characteristics of the terminal without connection, the access of a large number of terminals can be guaranteed.

  • Low cost: The cost of communication network is extremely low, and it is also suitable for narrowband transmission of data.

  • Security factor: AES128 encryption, high security factor.

market conditions

LoRa is extremely flexible for rural or indoor application scenarios in smart agriculture, smart cities, Industrial Internet of Things (IIoT), smart environments, smart homes and buildings, smart utilities and metering, and smart supply chains and logistics.

LoRa is convenient for networking. Using LoRa's strong penetrating power, it can connect devices in a wide range at low cost. Compared with NB-IoT and operator SIM card access, LoRa does not need to change cards or pay fees every year. Long-term use has lower cost.

Reference: What is the advantage of IoT applications implemented with LoRa?

MQTT

The MQTT protocol is an IoT communication protocol based on the publish/subscribe model. It occupies half of the IoT protocol by virtue of its simplicity and ease of implementation, support for QoS, and small packets.

The MQTT protocol is widely used in the Internet of Things, mobile Internet, intelligent hardware, Internet of Vehicles, electricity, energy and other fields. It can not only be used as a gateway to access communication on the device side, but also can be used as a device-cloud communication protocol. Most gateway protocols such as ZigBee and LoRa are eventually converted to MQTT protocol for access to the cloud.

MQTT protocol application field

Protocol Features

  • Lightweight and reliable: MQTT packets are compact, enabling stable transmission on severely constrained hardware devices and low-bandwidth, high-latency networks.

  • Publish/subscribe model: Based on the publish/subscribe model, the advantage of the publish-subscribe model lies in the decoupling of the publisher and the subscriber: the subscriber and the publisher do not need to establish a direct connection, nor do they need to be online at the same time.

  • Born for IoT: Provides comprehensive IoT application features such as heartbeat mechanism, testament message, QoS quality level + offline message, topic and security management.

  • Better ecology: Clients and SDKs covering all language platforms, mature Broker server software, capable of supporting massive topics, tens of millions of device access, and providing rich enterprise integration capabilities.

communication mode

MQTT adopts the publish-subscribe mode of communication. The publish-subscribe mode is different from the traditional client-server mode. It separates the client (publisher) that sends messages from the client (subscriber) that receives messages, and the publisher and subscriber do not need to Make direct connections. We can allow multiple publishers to publish messages to one subscriber, or multiple subscribers to receive messages from one publisher at the same time.

MQTT publish and subscribe

market conditions

MQTT is one of the most important standard protocols in the field of IoT and is widely used in the Internet of Things, Internet of Vehicles, Industrial Internet of Things, smart homes, smart cities, power, oil and energy industries.

MQTT is the standard communication protocol for IoT platforms of top cloud manufacturers such as AWS IoT Core, Azure IoT Hub, and Alibaba Cloud IoT Platform.

As one of the most popular and mature MQTT Brokers in the world, EMQX provides a cloud-native distributed IoT access platform, an integrated distributed MQTT message service and a powerful IoT rules engine of "run anywhere, unlimited connection, and any integration". , providing power for highly reliable, high-performance IoT real-time data movement, processing and integration, helping enterprises to quickly build business-critical IoT platforms and applications.

Reference: MQTT protocol entry and advanced

CoAP

CoAP is an HTTP-like protocol in the IoT world, used on resource-constrained IoT devices, and its detailed specification is defined in RFC 7252.

Because most IoT devices are resource-constrained, such as CPU, RAM, Flash, network bandwidth, etc. For such devices, it is unrealistic to directly use TCP and HTTP of the existing network to realize information exchange. In order to allow these devices to access the network smoothly, the CoAP protocol came into being.

Protocol Features

CoAP refers to many HTTP design ideas, and also improves many design details and adds many practical functions according to the specific conditions of constrained resource-limited devices.

  • message-based model

  • The transport layer is based on the UDP protocol and supports restricted devices

  • Uses a request/response model like HTTP requests, HTTP is text format, CoAP is binary format, and is more compact than HTTP

  • Support two-way communication

  • Lightweight and low power consumption

  • Support reliable transmission, data retransmission, and block transmission to ensure that data arrives reliably

  • Support IP multicast

  • Support observation mode

  • Support asynchronous communication

market conditions

Compared with MQTT, CoAP is lighter and has lower overhead, and is more suitable for some specific devices and network environments. EMQX and some public cloud IoT platforms provide CoAP access capability, please refer to an "appointment" between MQTT and CoAP in the EMQX world .

LwM2M

LwM2M is a lightweight IoT protocol for resource-constrained end device management. The LwM2M protocol was born at the end of 2013 and was proposed and defined by OMA (Open Mobile Alliance). The current mature version number is still 1.0, and OMA experts are working hard for version 1.1.

Protocol Features

The main entities of the LwM2M protocol include LwM2M Server and LwM2M Client.

  • LwM2M Server acts as a server and is deployed at the M2M service provider or network service provider.

  • LwM2M Client acts as a client and is deployed on each LwM2M device.

In addition, LwM2M bootstrap server (Bootstrap Server) or smart card (SmartCard) can be added as required to complete the initial boot of the client.

The LwM2M protocol has the following outstanding features:

  • The protocol is based on the REST architecture.

  • The messaging of the protocol is achieved through the CoAP protocol.

  • The protocol defines a compact, efficient and extensible data model.

Considering keeping pace with the times and implementing a concise and easy-to-understand style, the LwM2M protocol adopts REST.

However, because the service object of the protocol is the terminal device with limited resources, the traditional HTTP data transmission method is too cumbersome and difficult to support limited resources. Therefore, CoAP with REST style is chosen to complete the message and data transmission. On the one hand, CoAP is based on UDP. Compared with TCP, CoAP is more flexible in environments where network resources are limited and devices cannot be guaranteed to be online all the time (for security reasons, DTLS security transmission protocol based on UDP is used). On the other hand, the message structure of CoAP itself is very simple, the message is compressed, and the main part can be made very small, without occupying too many resources.

For similar considerations, the data structure of the protocol must be simple enough. The LwM2M protocol defines a model with a resource (Resource) as the basic unit. Each resource can carry a value and can point to an address to represent each item of information available in the LwM2M client. Resources exist in the object instance (Object Instance), that is, the instantiation of the object (Object). The LwM2M protocol predefines 8 kinds of objects (Object) to meet the basic needs, namely:

Object Object ID
Security (Security Object) 0
Server (server object) 1
Access Control (Access Control Object) 2
Device (device object) 3
Connectivity Monitoring 4
Firmware (firmware object) 5
Location (Location Object) 6
Connectivity Statistics 7

Considering the extensibility, the protocol also allows more objects to be customized according to actual needs. In such a data model, resources, object instances, and objects are all represented by numerical IDs for maximum compression, so any resource can be represented in a concise way of up to 3 levels, such as /1/0 /1 represents the server short ID resource in the first instance of the server object (Server Object). In the registration phase, the LwM2M client passes the object instance carrying the resource information to the LwM2M server to notify the server of the capabilities of its own device.

EMQ also realizes the LwM2M access capability on the EMQX server, and realizes most of the functions of the LwM2M protocol. LwM2M devices can be registered on EMQX-LWM2M, so as to access and manage devices through EMQX-LWM2M, and devices can also report to EMQX-LWM2M information, and use the services of the EMQ backend to collect data.

XMPP

XMPP Scalable Message Processing Field Protocol is an XML-based instant messaging protocol. The protocol embeds communication context information into XML structured data, enabling instant communication between people, between application systems, and between people and application systems.

Protocol Features

  • All XMPP information is based on XML, the de facto standard for information exchange, and has strong expansibility.

  • The XMPP system is a distributed system where each server controls its own resources.

  • The XMPP protocol is open source and uses XML to define client and server interactions.

market conditions

XMPP is characterized by mature protocols and extended protocols, complete functions, and is specially designed for instant chat (IM) scenarios. XMPP is an old-fashioned instant chat protocol. Instant chat programs such as Google Hangouts , WhatsApp Messenger , etc. are all based on XMPP.

However, because XMPP relies on the XML protocol and is too heavy in IoT scenarios, it is basically not suitable for IoT transmission.

Epilogue

Horizontally, IoT has a wide range of application scenarios in almost all industries, and each industry has different working conditions and networking modes; vertically, IoT system covers sensor/control equipment, data access, transmission , routing switching components and data storage and processing of the entire software and hardware chain, each link has a need for reasonable and efficient technical solutions.

At present, IoT protocols are developing in a diversified manner. Different industries and scenarios apply different protocols. In the same scenario, there can be multiple protocols to choose from. No protocol can dominate the market. There are various protocols. certain complementary effects. Therefore, to realize the interconnection of IoT devices and data, the key point is not the unification of protocols, but the interconnection between different protocols and the unification of upper-layer business application layer protocols.

EMQ is committed to solving the data connection problem of IoT devices. The core product EMQX IoT message server can connect any device through the open standard MQTT, CoAP and LwM2M protocols. For complex and diverse industrial protocols such as industrial scenarios, it can also be converted into a unified MQTT protocol connection through the edge industrial protocol gateway software Neuron . It meets the data collection requirements in most IoT scenarios and provides an efficient and reliable data access layer for the IoT business of enterprises.

Copyright statement: This article is original by EMQ, please indicate the source when reprinting.

Original link: https://www.emqx.com/zh/blog/iot-protocols-mqtt-coap-lwm2m

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324154200&siteId=291194637