Do you really understand the network process of IoT terminal devices connecting to the IoT platform?

Do you really understand the network process of IoT terminal devices connecting to the IoT platform?

Nowadays, we use a large number of IoT devices in our daily lives, such as smart door locks, subway barcode scanning gates, breakfast shop payment announcement speakers, car charging piles, face recognition clocking in at work, etc. As a developer in the field of IoT, have you ever thought about the complete network communication process behind it?

With the help of Wireshark, the most widely used open source packet capture software by developers around the world, you can capture the communication packets of the terminal device network card and everything will be clear at a glance.

You will find that the terminal device first performs DNS resolution, then establishes an MQTT persistent connection channel, subscribes to business topics, reports collected data, keeps the connection alive by sending heartbeat packets, and actively disconnects the persistent connection after the business is processed.

1. DNS resolution

DNS service is the abbreviation of Domain Name Service, which is composed of domain name resolver and domain name server. Domain name server refers to a server that stores the domain names and corresponding IP addresses of all hosts in the network and has the function of converting domain names into IP addresses. A domain name must correspond to an IP address, but an IP address does not necessarily have a domain name.

Observe the DNS network packet, and you will find that the terminal device first requests the IP address corresponding to the MQTT-Broker server domain name. In the DNS Answer, the terminal device obtains the addr value for the subsequent TCP/IP network connection.

2. TCP three-way handshake

Before the terminal device establishes an MQTT persistent connection, it needs to first establish a TCP connection, that is, a three-way handshake between the terminal device and the MQTT-Broker server.

3.MQTT establishes a connection CONNECT

MQTT (Message Queue Telemetry Transport) is a messaging protocol built on the TCP/IP protocol stack that supports asynchronous communication between parties. MQTT separates message senders and receivers in space and time, so it can scale in unreliable network environments and uses a publish and subscribe (Pub/Sub) model.

Based on the TCP connection, the terminal device actively initiates the MQTT CONNECT instruction, which includes the protocol version v3.1.1, the heartbeat time of 60s, the connection identifier ClientId, and the Username and Password for authentication, as shown in the following figure.

After the MQTT-Broker server receives the connection request from the terminal device and passes the identity authentication, it responds with a CONNACK message with ReturnCode 0, as shown in the following figure.

4.MQTT subscription topic SUBSCRIBE

After the terminal device establishes the MQTT connection, it needs to actively subscribe to the business topic to receive control instructions issued by the cloud, as shown in the following figure.

After the MQTT-Broker server successfully establishes a subscription relationship, it will respond SUBACK to the terminal device, as shown in the following figure.

5. MQTT reports data to PUBLISH

After the terminal device collects the data, it can actively send the data to the cloud through PUBLISH, and set the message topic, data packet payload, and QoS, as shown in the following figure.

After the MQTT-Broker server successfully receives the data, if it is a QoS=1 message, it will respond with PUBACK, as shown in the figure below.

6.MQTT Heartbeat PINGREQ

When there is no business packet interaction between the terminal device and the MQTT-Broker server for a long time, the heartbeat packet PINGREQ/PINGRESP is needed to keep the network long connection channel alive.

The terminal device sends a PINGREQ message, as shown below.

The MQTT-Broker server responds to the PINGRESP message, as shown below.

7.MQTT Heartbeat DISCONNECT

When the terminal device needs to disconnect the MQTT persistent connection, the MQTT-Broker server can actively send a DISCONNECT message, as shown in the following figure.

8. TCP connection disconnected

When the MQTT persistent connection of the terminal device is disconnected, TCP will also be destroyed, as shown in the following figure.

The above is how to use the Wireshark network packet capture tool to capture packets and analyze the complete network communication process of IoT devices from the perspective of terminal devices. I hope it will be helpful to you!

<<:  Reshaping Wi-Fi Infrastructure for the Future of IoT

>>:  Automotive Ethernet: Solving complex wiring harnesses and supporting more data

Recommend

Out-of-the-box infrastructure connectivity options

When it comes to connecting network devices acros...

Wi-Fi is getting harder to hack: How to keep your new router secure

With the development of WiFi technology, WiFi has...

Network literacy: Understanding DNS in one article

[[328762]] Hello everyone, I am Brother Ming. Dur...

Where can I find the IP address of my router?

When we need to set up a wireless router, we need...

9 classic cases, online teaching how to troubleshoot network failures

Network failure is the most common and difficult ...

Let's talk about short links

Introduction I am working on a promotion system r...

Did you know? The 5G market started with B2B

The two major obstacles to the popularization of ...

Can IPFS subvert the HTTP protocol?

How many people knew about IPFS before August 201...