Iot device communication method and apparatus, electronic device, and readable storage medium
By using the MQTT-SN protocol and optimized data transmission methods, IoT devices communicate with gateway nodes, solving the problem of low communication efficiency of IoT devices and achieving efficient, secure, and reliable communication in resource-constrained environments.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2026-03-17
AI Technical Summary
The communication efficiency of IoT devices is low, which prevents them from providing high-quality IoT services due to limitations in resources and network design.
IoT devices communicate with gateway nodes, transmit messages via the MQTT-SN protocol, use topic identifiers corresponding to specified message topics for message transmission, combine compression and encryption algorithms to optimize data transmission, and adaptively select network topology and quality of service level in resource-constrained environments.
It improves the communication efficiency of IoT devices, reduces data transmission volume, and is particularly suitable for resource-constrained IoT device networks, providing better IoT services.
Smart Images

Figure CN119922209B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of Internet of Things (IoT) technology, and in particular to an IoT device communication method, an IoT device communication apparatus, an electronic device, and a computer-readable storage medium. Background Technology
[0002] With the rapid development of IoT technology, more and more IoT devices are connecting to the network for data exchange and information transmission.
[0003] However, due to limitations in resources or network design, IoT devices often have low communication efficiency, which prevents them from providing users with adequate IoT services. Summary of the Invention
[0004] In view of the above problems, a communication method and apparatus for Internet of Things (IoT) devices are proposed to overcome or at least partially solve the above problems. The specific technical solution is as follows:
[0005] This invention discloses a communication method for Internet of Things (IoT) devices, wherein the IoT devices and gateway nodes are communicatively connected to form an IoT device network, and the method includes:
[0006] A registration message is sent to the gateway node; the registration message includes the device information of the IoT device; the gateway node is used to authenticate the IoT device according to the device information after receiving the registration message, and generate a registration completion message after successful authentication.
[0007] After receiving the registration completion message sent by the gateway node in response to the registration message, the system transmits the message corresponding to the specified message topic with the gateway node using the topic identifier corresponding to the specified message topic.
[0008] In one embodiment of the present invention, the Internet of Things (IoT) device includes at least sensor devices, the IoT device network composed of the sensor devices is a sensor network, and the IoT device and the gateway node transmit messages using a message queue telemetry transmission protocol suitable for sensor networks.
[0009] In one embodiment of the present invention, the registration message includes device information of the IoT device for topic registration; after receiving the registration completion message sent by the gateway node in response to the registration message, the message corresponding to the specified message topic is transmitted between the gateway node and the gateway node using a topic identifier corresponding to the specified message topic, including:
[0010] The gateway node receives a registration completion message in response to the registration message; wherein the registration completion message includes a first designated message topic identifier assigned by the gateway node to the first designated message topic after generating the first designated message topic according to the device information and a preset topic naming rule;
[0011] Send a subscription message to the gateway node; the subscription message includes a second specified message topic or a second specified message topic identifier corresponding to the second specified message topic; the node gateway is used to determine that the IoT device subscribes to the second specified message topic based on the second specified message topic or the second specified message topic identifier;
[0012] Send a publication message for the first specified message topic to the gateway node using the first specified topic identifier corresponding to the first specified message topic, and or receive a publication message related to the second specified message topic subscribed by the IoT device sent by the gateway node using the second specified topic identifier corresponding to the second specified message topic.
[0013] In one embodiment of the present invention, the method further includes:
[0014] The published message is compressed using a preset compression algorithm to obtain the compressed published message;
[0015] The published message is encrypted and compressed using a preset encryption algorithm to obtain the encrypted and compressed published message.
[0016] In one embodiment of the present invention, the method further includes:
[0017] Send heartbeat messages to the gateway node at preset time intervals;
[0018] The gateway node receives a heartbeat response message sent by the gateway node in response to the heartbeat message; wherein the gateway node is configured to determine that the IoT device is offline when it does not receive the heartbeat message sent by the IoT device within a preset heartbeat time, and to cache the published messages related to the second specified topic message that the IoT device has subscribed to when the IoT device is offline;
[0019] When the IoT device comes back online, it receives a publication message from the gateway node related to the second specified topic message that the IoT device had subscribed to while it was offline.
[0020] In one embodiment of the present invention, the method further includes:
[0021] When the IoT device is not transmitting messages, it enters a low-power sleep mode.
[0022] After the IoT device enters a low-power sleep mode, it is woken up when a preset wake-up time is reached or when an external event is received.
[0023] In one embodiment of the present invention, the network topology of the Internet of Things (IoT) device network is determined based on the number of IoT devices and the usage environment; the network topology includes at least star topology, tree topology and mesh topology.
[0024] In one embodiment of the present invention, the method further includes:
[0025] Determine the quality service level corresponding to the IoT device;
[0026] If the IoT device does not receive a confirmation message from the gateway node within a preset time after sending a message to the gateway node, the message will be resent according to the quality service level corresponding to the IoT device.
[0027] In one embodiment of the present invention, the gateway node and the IoT device are used to process the received message sent by the IoT device and then send it to the cloud server; the processing includes at least data aggregation and preprocessing.
[0028] This invention also discloses an IoT device communication apparatus, wherein the IoT devices and gateway nodes are communicatively connected to form an IoT device network, and the apparatus includes:
[0029] A message sending module is used to send a registration message to the gateway node; the registration message includes device information of the IoT device; the gateway node is used to authenticate the IoT device according to the device information after receiving the registration message, and generate a registration completion message after successful authentication;
[0030] The message transmission module is used to transmit the message corresponding to the specified message topic with the gateway node after receiving the registration completion message sent by the gateway node in response to the registration message, using the topic identifier corresponding to the specified message topic.
[0031] This invention also discloses an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0032] The memory is used to store computer programs;
[0033] When the processor executes a program stored in the memory, it implements the method described in the embodiments of the present invention.
[0034] This invention also discloses a computer program product stored in a storage medium, which is executed by at least one processor to implement the method described in this invention.
[0035] This invention also discloses a computer-readable storage medium storing instructions that, when executed by one or more processors, cause the processors to perform the methods described in this invention.
[0036] The embodiments of the present invention have the following advantages:
[0037] In this embodiment of the invention, in an IoT device network composed of IoT devices and a gateway node communicating with each other, the IoT devices can send a registration message to the gateway node. The registration message may include the device information of the IoT device. After receiving the registration message, the gateway node can authenticate the IoT device based on the device information in the registration message and generate a registration completion message upon successful authentication. After receiving the registration completion message from the gateway node in response to the registration message, the IoT device can then transmit messages corresponding to the specified message topic with the gateway node using a topic identifier corresponding to the specified message topic, thus achieving IoT device communication. In this embodiment of the invention, when the IoT device and the gateway node transmit messages, they can transmit messages based on a topic identifier corresponding to the specified message topic. Compared to transmitting messages based on a specified message topic, this reduces the amount of data transmission, making it particularly suitable for resource-constrained IoT device networks, improving the communication efficiency of IoT devices, and ultimately providing users with better IoT services. Attached Figure Description
[0038] Figure 1 This is a flowchart illustrating the steps of an IoT device communication method provided in an embodiment of the present invention;
[0039] Figure 2 This is a schematic diagram of an application environment provided in an embodiment of the present invention;
[0040] Figure 3 This is a schematic diagram of a process for efficient communication between IoT devices based on the MQTT-SN protocol, provided in an embodiment of the present invention.
[0041] Figure 4 This is a structural block diagram of an IoT device communication device provided in an embodiment of the present invention;
[0042] Figure 5 This is a schematic diagram of the hardware structure of an electronic device that implements various embodiments of the present invention. Detailed Implementation
[0043] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0044] Reference Figure 1 The diagram illustrates a flowchart of a communication method for IoT devices provided in an embodiment of the present invention. The IoT devices and gateway nodes are communicatively connected to form an IoT device network. The method may specifically include the following steps:
[0045] Step 101: Send a registration message to the gateway node; the registration message includes the device information of the IoT device; the gateway node is used to authenticate the IoT device according to the device information after receiving the registration message, and generate a registration completion message after successful authentication.
[0046] Reference Figure 2 This diagram illustrates an application environment provided in an embodiment of the present invention. One or more IoT devices 201 are communicatively connected to a gateway node (gateway) 202 to form an IoT device network (IoT). The IoT devices themselves do not necessarily require complex computing capabilities. For example, IoT devices may include lighting equipment, dehumidifiers, switches, sockets, sensor devices, smoke detectors, smart door locks, and security cameras, etc. IoT devices can communicate with each other through communication protocols. In some embodiments of the present invention, in resource-constrained IoT device networks, the IoT devices may be sensor devices, such as temperature sensors, humidity sensors, and pressure sensors. An IoT device network composed of sensor devices can be called a sensor network.
[0047] In one embodiment of the present invention, devices in an IoT device network can use the MQTT (Message Queuing Telemetry Transport) protocol for message / data transmission. Specifically, MQTT is a lightweight communication protocol based on a publish / subscribe model, which can provide real-time and reliable messaging services to devices with minimal code and limited bandwidth. As a low-overhead, low-bandwidth instant messaging protocol, it can be applied in the IoT field. Furthermore, in some resource-constrained IoT network environments, when data flows into Low-Power Wide-Area Networks (LPWANs), the standard MQTT protocol may not meet the requirements for low bandwidth and low power consumption. Therefore, in the IoT device network of the present invention, especially in resource-constrained IoT device networks, devices can use the MQTT-SN (MQTT for Sensor Networks) protocol for message / data transmission. The MQTT-SN protocol, as a simplified version of the MQTT protocol, is designed specifically for resource-constrained network environments and devices, and has lower overhead and higher efficiency, making it suitable for communication between sensor devices in sensor networks. Of course, in practical applications, other communication protocols can also be used to implement message transmission between IoT devices in the IoT device network, and this embodiment of the invention does not impose any restrictions on this. In this embodiment of the invention, when configuring the gateway node, a gateway node that supports the MQTT-SN protocol can be selected to ensure that it can support and convert between the MQTT-SN protocol and the MQTT protocol. Specifically, the network parameters of the gateway node (such as IP address, port, etc.) can be configured to ensure that it can communicate with IoT platforms (such as cloud servers / central servers) and IoT devices.
[0048] In practical implementation, a message topic is a string used in the MQTT-SN protocol to identify message categories. Based on the message topic, different types of messages can be distinguished. IoT devices can send and receive messages corresponding to a given message topic by publishing and subscribing to that topic. For example, suppose IoT device A subscribes to a message topic about temperature. If IoT device B publishes a publish message 1 (e.g., temperature data) about the same message topic to the gateway node, the gateway node can send publish message 1 back to IoT device A.
[0049] In this embodiment of the invention, after the IoT device is powered on, it first registers with the gateway node via a REGISTER message using the MQTT-SN protocol, thereby achieving authentication and subscription to message topics. The registration message contains device information for the IoT device, which may include at least a unique identifier (Device ID) and a security key. Upon receiving the registration message, the gateway node verifies the identity of the IoT device based on the device information and stores the device information in its local database after successful verification. Subsequent authentication of the IoT device can be performed based on the device information stored in the local database. For example, when the gateway node receives a message from the IoT device, it can query the local database to verify the legitimacy of the IoT device and prevent unauthorized devices from accessing the IoT device network. After successfully verifying the device information in the registration message, the gateway node generates a registration completion message and sends it to the corresponding IoT device.
[0050] In one specific embodiment of the present invention, devices in an IoT device network, such as gateway nodes and IoT devices, can use TLS (Transport Layer Security) / DTLS (Datagram Transport Layer Security) protocols to encrypt data, preventing data theft or tampering. Additionally, gateway nodes or other control devices can use certificates or pre-shared keys for device authentication, ensuring that only legitimate IoT devices can access the network.
[0051] Step 102: After receiving the registration completion message sent by the gateway node in response to the registration message, transmit the message corresponding to the specified message topic with the gateway node using the topic identifier corresponding to the specified message topic.
[0052] The specified message topic can be a message topic subscribed to or published by the IoT device. Each message topic can have a unique topic identifier (topic ID). The topic identifier is two bytes, while the message topic is usually more than two bytes. Therefore, using the topic identifier for message transmission avoids transmitting the complete message topic every time, thereby improving the message transmission efficiency of IoT devices, i.e., improving the communication efficiency of IoT devices. For example, the message topic can be "home / temperature / livingroom", and the corresponding topic identifier can be "1".
[0053] In this embodiment of the invention, after the IoT device receives the registration completion message sent by the gateway node in response to the registration message, the IoT device and the gateway node can transmit messages corresponding to the specified message topic using a topic identifier corresponding to the specified message topic.
[0054] In the aforementioned IoT device communication method, within an IoT device network formed by the communication connection between the IoT device and the gateway node, the IoT device can send a registration message to the gateway node. This registration message may include the IoT device's device information. Upon receiving the registration message, the gateway node can authenticate the IoT device based on the device information and generate a registration completion message upon successful authentication. After receiving the registration completion message from the gateway node, the IoT device can then communicate with the gateway node using a topic identifier corresponding to a specified message topic, thereby achieving IoT device communication. In this embodiment of the invention, when the IoT device and the gateway node transmit messages, they can do so based on a topic identifier corresponding to a specified message topic. Compared to transmitting messages based on a specified message topic, this reduces the amount of data transmitted, making it particularly suitable for resource-constrained IoT device networks. This improves the communication efficiency of IoT devices and ultimately provides users with better IoT services.
[0055] In one embodiment of the present invention, the registration message includes device information of the IoT device for topic registration; after receiving the registration completion message sent by the gateway node in response to the registration message, the message corresponding to the specified message topic is transmitted between the gateway node and the gateway node using a topic identifier corresponding to the specified message topic, including:
[0056] The gateway node receives a registration completion message in response to the registration message; wherein the registration completion message includes a first designated message topic identifier assigned by the gateway node to the first designated message topic after generating the first designated message topic according to the device information and a preset topic naming rule;
[0057] Send a subscription message to the gateway node; the subscription message includes a second specified message topic or a second specified message topic identifier corresponding to the second specified message topic; the node gateway is used to determine that the IoT device subscribes to the second specified message topic based on the second specified message topic or the second specified message topic identifier;
[0058] Send a publication message for the first specified message topic to the gateway node using the first specified topic identifier corresponding to the first specified message topic, and or receive a publication message related to the second specified message topic subscribed by the IoT device sent by the gateway node using the second specified topic identifier corresponding to the second specified message topic.
[0059] In this embodiment of the invention, message topics can be categorized according to device type, data type, etc., for easier management and filtering. By designing reasonable topic naming rules, message management and filtering can be facilitated. For example, the design principles of topic naming rules may include: Hierarchical structure: Using a hierarchical structure to organize topics, similar to the directory structure of a file system. Each level is separated by a forward slash ( / ); Clarity: The topic name corresponding to the message topic should be as clear as possible, clearly expressing the source and type of the data; Consistency: Maintaining consistency in naming rules facilitates management and understanding; Scalability: Considering possible future expansion needs when designing topics, allowing for a certain degree of flexibility; Conciseness: While ensuring clarity, striving for conciseness and avoiding excessively long topic names for message topics.
[0060] In one example of this invention, assuming a smart home system includes temperature sensors and lighting control devices in multiple rooms, the following topic naming rules can be designed: Device Type: The first level indicates the device type, such as a sensor or a control device. Device Location: The second level indicates the location of the device, such as the room name (livingroom, bedroom, kitchen, etc.). Device Function: The third level indicates the device's function or data type, such as temperature, humidity, light, etc. Device Details: The fourth level indicates the specific device number or type to distinguish multiple devices of the same type in the same location. Taking a temperature sensor as a specific example, the message name corresponding to the message topic subscribing to the living room temperature sensor could be: sensor / livingroom / temperature.
[0061] In this embodiment of the invention, after the IoT device successfully registers with the gateway node—that is, after the IoT device completes authentication and registers a specified message topic (first specified message topic) on the gateway node—it can publish a corresponding message to the first specified message topic via a PUBLISH message to the gateway node. Simultaneously, the IoT device subscribes to a message topic of interest (second specified message topic) via a SUBSCRIBE message to receive published messages related to the second specified message topic sent by the gateway node. It should be noted that, to improve the communication efficiency of the IoT device, this embodiment of the invention assigns a corresponding topic identifier to each message topic. In the MQTT-SN protocol, the IoT device needs to first register the message topic with the gateway node and obtain the corresponding topic identifier to reduce the amount of data transmitted based on the topic identifier. For example, the first specified message topic has a corresponding first specified topic identifier, and the second specified message topic has a corresponding second specified topic identifier. Thus, when the IoT device publishes information about the first specified message topic to the gateway node, it can send a published message corresponding to the first specified message topic based on the first specified topic identifier. The gateway node can then send published messages related to the second specified message topic that the IoT device has subscribed to using the second specified topic identifier.
[0062] In one embodiment of the present invention, the method may further include:
[0063] The published message is compressed using a preset compression algorithm to obtain the compressed published message;
[0064] The published message is encrypted and compressed using a preset encryption algorithm to obtain the encrypted and compressed published message.
[0065] In this embodiment of the invention, before IoT devices and gateway nodes send messages (e.g., publish messages), the IoT devices can compress the messages using a preset lightweight compression algorithm, such as LZ77 or Huffman coding, to reduce the data volume. Simultaneously, other encryption algorithms, such as symmetric encryption algorithms (e.g., AES (Advanced Encryption Standard),) are used to encrypt the compressed messages to ensure data security. Message transmission between IoT devices based on compressed and encrypted messages can effectively reduce data volume and improve the communication efficiency of IoT devices. In some embodiments, the IoT devices and gateway nodes of this invention can merge multiple messages into a large message for batch message transmission, reducing the number of communication operations and further improving communication efficiency.
[0066] In one embodiment of the present invention, the method may further include:
[0067] Send heartbeat messages to the gateway node at preset time intervals;
[0068] The gateway node receives a heartbeat response message sent by the gateway node in response to the heartbeat message; wherein the gateway node is configured to determine that the IoT device is offline when it does not receive the heartbeat message sent by the IoT device within a preset heartbeat time, and to cache the published messages related to the second specified topic message that the IoT device has subscribed to when the IoT device is offline;
[0069] When the IoT device comes back online, it receives a publication message from the gateway node related to the second specified topic message that the IoT device had subscribed to while it was offline.
[0070] For example, the preset time interval can be 1 minute or other, and the preset heartbeat time can be 5 minutes or other.
[0071] In this embodiment of the invention, an IoT device can send a PINGREQ message (heartbeat message) to a gateway node at preset time intervals (e.g., 1 minute) to indicate that the IoT device is online. After receiving the heartbeat message, the gateway node can reply with a PINGRESP message (heartbeat response message) to the corresponding IoT device. If the gateway node does not receive a heartbeat message from the IoT device within a preset heartbeat time (e.g., 5 minutes), it considers the IoT device offline and takes corresponding measures, such as attempting to reconnect to the IoT device or locally caching published messages corresponding to the message topics subscribed to by the IoT device.
[0072] When an IoT device is offline, the gateway node can store the published messages that the IoT device has subscribed to in a local cache. When the IoT device comes back online, the gateway node can send the cached published messages (PUBLISH messages) to the IoT device, so that the IoT device can obtain all messages related to the subscribed message topics, thus ensuring the user experience of the IoT device.
[0073] In one embodiment of the present invention, the method may further include:
[0074] When the IoT device is not transmitting messages, it enters a low-power sleep mode.
[0075] After the IoT device enters a low-power sleep mode, it is woken up when a preset wake-up time is reached or when an external event is received.
[0076] In this embodiment of the invention, the IoT device can enter a low-power sleep mode when it does not need to transmit messages, thereby saving the power of the IoT device. Then, after the IoT device enters the low-power sleep mode, a timer can be used to wake up the IoT device when a preset wake-up time is reached, or the IoT device can be woken up by an external event (such as a temperature sensor detecting that the temperature exceeds a preset temperature threshold) to prompt the IoT device to perform data collection and transmission.
[0077] In one embodiment of the present invention, the network topology of the Internet of Things (IoT) device network is determined based on the number of IoT devices and the usage environment; the network topology includes at least star topology, tree topology and mesh topology.
[0078] In this embodiment of the invention, the IoT device network can adaptively select a suitable network topology based on the number of connected IoT devices and the usage environment (power consumption requirements and communication requirements). The network topology includes at least star topology, tree topology, and mesh topology. Specifically, star topology: the central node (gateway node) communicates directly with each sensor node (IoT device), suitable for scenarios with a small number of devices. Tree topology: suitable for larger-scale sensor networks, where intermediate nodes (which can be IoT devices) can act as relay devices to forward messages, reducing communication distance. Mesh topology: each node (including IoT devices and gateway nodes) can communicate with multiple nodes, providing redundant paths and improving network robustness.
[0079] In one embodiment of the present invention, the method may further include:
[0080] Determine the quality service level corresponding to the IoT device;
[0081] If the IoT device does not receive a confirmation message from the gateway node within a preset time after sending a message to the gateway node, the message will be resent according to the quality service level corresponding to the IoT device.
[0082] In the specific implementation, multiple Quality of Service (QoS) levels are defined. Gateway nodes or users can select the appropriate QoS level according to application requirements to ensure reliable message transmission. For example, QoS levels may include, but are not limited to: QoS 0: At most one transmission, no confirmation of message arrival. Suitable for scenarios where message loss is not a concern. QoS 1: At least one transmission, ensuring message arrival but possible duplication. Requires the device to retransmit the message if no confirmation is received. QoS 2: Exactly one transmission, ensuring message arrival and no duplication. Requires the device to perform a complex four-way handshake process.
[0083] In this embodiment of the invention, after an IoT device sends a message to a gateway node, if it does not receive a confirmation message from the gateway node within a preset time (e.g., after the IoT device sends a publish message to the gateway node, and the gateway node does not return a corresponding confirmation message within the preset time), the IoT device can resend the message according to the corresponding Quality of Service (QoS) level. For example, if the QoS level of the IoT device is QoS 0, then resending the message is unnecessary. Furthermore, in this embodiment of the invention, when the IoT device detects a disconnection from the gateway node, it automatically attempts to reconnect, ensuring the communication reliability of the IoT device.
[0084] In one embodiment of the present invention, the gateway node and the IoT device are used to process the received message sent by the IoT device and then send it to the cloud server; the processing includes at least data aggregation and preprocessing.
[0085] In practical implementations, an IoT device network can include a central server in addition to gateway nodes and IoT devices. Gateway nodes and IoT devices can also be edge nodes. Specifically, edge nodes refer to computing devices or sensor devices located at the network edge, typically close to the data source (such as data / messages collected by IoT devices like sensors and cameras), responsible for preliminary data processing, filtering, and transmission. A central server refers to a cluster of computing resources or a group of servers located at the center of the network, responsible for centrally processing, storing, and managing the data collected from the edge nodes.
[0086] In this embodiment of the invention, after messages are collected at the edge nodes, they can be processed before being transmitted to the central server for further processing or storage. Processing may include data aggregation and preprocessing to reduce the amount of data that needs to be transmitted. Additionally, the edge nodes can perform simple data analysis and processing on the Internet of Things (IoT) before uploading to the central server, reducing the burden on the central server. Both data aggregation and preprocessing aim to reduce data transmission volume and improve system efficiency and response speed. Specifically, data aggregation combines multiple data points (messages) into a single data point to reduce data transmission volume. Data aggregation can be performed within a fixed time window, for example, calculating the average temperature every hour. Data preprocessing involves preliminary processing of the raw data to improve data quality and the efficiency of subsequent processing. For example, normalization can be used to scale the data to a standard range.
[0087] To enable those skilled in the art to better understand, a specific example is used below to illustrate an embodiment of the present invention. Specifically, refer to... Figure 3 This is a schematic diagram of a process for efficient communication between IoT devices based on the MQTT-SN protocol, provided in an embodiment of the present invention. The specific process may include the following steps:
[0088] S1: After the IoT device powers on, it first registers with the gateway node via a REGISTER message using the MQTT-SN protocol. The registration message contains the device's unique identifier (ID) and security key. Upon receiving the registration message, the gateway node verifies the IoT device's identity and stores the device information in its local database.
[0089] S2: After successful registration, IoT devices can publish data to specified topics via PUBLISH messages. Simultaneously, IoT devices can subscribe to topics of interest via SUBSCRIBE messages to receive relevant messages. Message topics can be categorized by device type, data type, etc., for easy management and filtering.
[0090] S3: Before sending a message, IoT devices can compress the message using a lightweight compression algorithm to reduce the data size. Simultaneously, a symmetric encryption algorithm (such as AES (Advanced Encryption Standard)) is used to encrypt the compressed data to ensure data security.
[0091] S4: IoT devices send a PINGREQ message (heartbeat message) to the gateway at regular intervals (e.g., every minute) to indicate that the IoT device is online. Upon receiving the heartbeat message, the gateway node replies with a PINGRESP message (heartbeat response message). If the gateway node does not receive a heartbeat message from the IoT device within a certain time period (e.g., 5 minutes), it considers the IoT device offline and takes appropriate measures.
[0092] S5: When an IoT device is offline, the gateway node stores the messages published by the IoT device in a local cache. When the IoT device comes back online, the gateway node sends the cached messages to the IoT device via a PUBLISH message.
[0093] The above-described embodiment of the present invention provides a method for efficient communication of IoT devices based on the MQTT-SN protocol. By optimizing the communication protocol and data processing flow, it achieves efficient, secure, and reliable communication of IoT devices in resource-constrained network environments, and has broad application prospects and practical value.
[0094] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of the present invention are not limited to the described order of actions, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present invention.
[0095] Reference Figure 4 This diagram illustrates a structural block diagram of an IoT device communication apparatus provided in an embodiment of the present invention. The IoT device and the gateway node are communicatively connected to form an IoT device network. The apparatus may specifically include the following modules:
[0096] The message sending module 401 is used to send a registration message to the gateway node; the registration message includes the device information of the IoT device; the gateway node is used to authenticate the IoT device according to the device information after receiving the registration message, and generate a registration completion message after successful authentication.
[0097] The message transmission module 402 is used to transmit the message corresponding to the specified message topic with the gateway node after receiving the registration completion message sent by the gateway node in response to the registration message, using the topic identifier corresponding to the specified message topic.
[0098] In one embodiment of the present invention, the Internet of Things (IoT) device includes at least sensor devices, the IoT device network composed of the sensor devices is a sensor network, and the IoT device and the gateway node transmit messages using a message queue telemetry transmission protocol suitable for sensor networks.
[0099] In one embodiment of the present invention, the registration message includes device information of the IoT device for topic registration; the message transmission module 402 is used for:
[0100] The gateway node receives a registration completion message in response to the registration message; wherein the registration completion message includes a first designated message topic identifier assigned by the gateway node to the first designated message topic after generating the first designated message topic according to the device information and a preset topic naming rule;
[0101] Send a subscription message to the gateway node; the subscription message includes a second specified message topic or a second specified message topic identifier corresponding to the second specified message topic; the node gateway is used to determine that the IoT device subscribes to the second specified message topic based on the second specified message topic or the second specified message topic identifier;
[0102] Send a publication message for the first specified message topic to the gateway node using the first specified topic identifier corresponding to the first specified message topic, and or receive a publication message related to the second specified message topic subscribed by the IoT device sent by the gateway node using the second specified topic identifier corresponding to the second specified message topic.
[0103] In one embodiment of the present invention, the device further includes: a compression encryption module, used for:
[0104] The published message is compressed using a preset compression algorithm to obtain the compressed published message;
[0105] The published message is encrypted and compressed using a preset encryption algorithm to obtain the encrypted and compressed published message.
[0106] In one embodiment of the present invention, the device further includes: a heartbeat module, used for:
[0107] Send heartbeat messages to the gateway node at preset time intervals;
[0108] The gateway node receives a heartbeat response message sent by the gateway node in response to the heartbeat message; wherein the gateway node is configured to determine that the IoT device is offline when it does not receive the heartbeat message sent by the IoT device within a preset heartbeat time, and to cache the published messages related to the second specified topic message that the IoT device has subscribed to when the IoT device is offline;
[0109] When the IoT device comes back online, it receives a publication message from the gateway node related to the second specified topic message that the IoT device had subscribed to while it was offline.
[0110] In one embodiment of the present invention, the device further includes: a low-power module, used for:
[0111] When the IoT device is not transmitting messages, it enters a low-power sleep mode.
[0112] After the IoT device enters a low-power sleep mode, it is woken up when a preset wake-up time is reached or when an external event is received.
[0113] In one embodiment of the present invention, the network topology of the Internet of Things (IoT) device network is determined based on the number of IoT devices and the usage environment; the network topology includes at least star topology, tree topology and mesh topology.
[0114] In one embodiment of the present invention, the apparatus further includes: a message transmission module, configured to:
[0115] Determine the quality service level corresponding to the IoT device;
[0116] If the IoT device does not receive a confirmation message from the gateway node within a preset time after sending a message to the gateway node, the message will be resent according to the quality service level corresponding to the IoT device.
[0117] In one embodiment of the present invention, the gateway node and the IoT device are used to process the received message sent by the IoT device and then send it to the cloud server; the processing includes at least data aggregation and preprocessing.
[0118] In this embodiment of the invention, in an IoT device network composed of IoT devices and a gateway node, the IoT device can send a registration message to the gateway node. The registration message may include the IoT device's device information. After receiving the registration message, the gateway node can authenticate the IoT device based on the device information in the registration message and generate a registration completion message upon successful authentication. After receiving the registration completion message from the gateway node, the IoT device can then transmit messages corresponding to a specified message topic to the gateway node using a topic identifier corresponding to the specified message topic, thus achieving IoT device communication. In this embodiment of the invention, when the IoT device and the gateway node transmit messages, they can do so based on a topic identifier corresponding to a specified message topic. Compared to transmitting messages based on a specified message topic, this reduces the amount of data transmitted, making it particularly suitable for resource-constrained IoT device networks, improving the communication efficiency of IoT devices, and ultimately providing users with better IoT services.
[0119] As the apparatus embodiment is basically similar to the method embodiment, it is described in a relatively simple manner. For relevant details, please refer to the description of the method embodiment.
[0120] It should be noted that the embodiments of the present invention may involve the use of user data. In practical applications, user-specific personal data may be used in the scheme described herein within the scope permitted by applicable laws and regulations, provided that it complies with the applicable laws and regulations of the country (e.g., with the user's explicit consent, with the user being properly notified, etc.).
[0121] In addition, this invention also provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, it implements the various processes of the above-described IoT device communication method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0122] This invention also provides a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the various processes of the above-described IoT device communication method embodiments and achieves the same technical effects. To avoid repetition, it will not be described again here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0123] This invention also provides a computer program product, which is stored in a storage medium and executed by at least one processor to implement the various processes of the above-described IoT device communication method embodiments, and can achieve the same technical effects. To avoid repetition, it will not be described again here.
[0124] Figure 5 A schematic diagram of the hardware structure of an electronic device for implementing various embodiments of the present invention.
[0125] The electronic device 500 includes, but is not limited to, components such as: a radio frequency unit 501, a network module 502, an audio output unit 503, an input unit 504, a sensor 505, a display unit 506, a user input unit 507, an interface unit 508, a memory 509, a processor 510, and a power supply 511. Those skilled in the art will understand that... Figure 5 The electronic device structures shown are not intended to limit the electronic device. An electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements. In embodiments of the present invention, the electronic device includes, but is not limited to, mobile phones, tablet computers, laptops, PDAs, in-vehicle terminals, wearable devices, and pedometers.
[0126] It should be understood that, in this embodiment of the invention, the radio frequency unit 501 can be used for receiving and transmitting signals during information transmission or calls. Specifically, it receives downlink data from the base station and processes it with the processor 510; additionally, it transmits uplink data to the base station. Typically, the radio frequency unit 501 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier, a duplexer, etc. Furthermore, the radio frequency unit 501 can also communicate with networks and other devices through a wireless communication system.
[0127] The electronic device provides users with wireless broadband internet access through the network module 502, such as helping users send and receive emails, browse web pages, and access streaming media.
[0128] The audio output unit 503 can convert audio data received by the radio frequency unit 501 or the network module 502 or stored in the memory 509 into audio signals and output them as sound. Furthermore, the audio output unit 503 can also provide audio output related to specific functions performed by the electronic device 500 (e.g., call signal reception sound, message reception sound, etc.). The audio output unit 503 includes a speaker, a buzzer, and a receiver, etc.
[0129] Input unit 504 is used to receive audio or video signals. Input unit 504 may include a graphics processing unit (GPU) 5041 and a microphone 5042. The GPU 5041 processes image data of still images or videos acquired by an image capture device (such as a camera) in video capture mode or image capture mode. The processed image frames can be displayed on display unit 506. The image frames processed by GPU 5041 can be stored in memory 509 (or other storage medium) or transmitted via radio frequency unit 501 or network module 502. Microphone 5042 can receive sound and process such sound into audio data. The processed audio data can be converted into a format that can be transmitted to a mobile communication base station via radio frequency unit 501 in telephone call mode.
[0130] The electronic device 500 also includes at least one sensor 505, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display panel 5061 according to the ambient light level, and the proximity sensor can turn off the display panel 5061 and / or backlight when the electronic device 500 is moved to the ear. As a type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in various directions (generally three axes). When stationary, it can detect the magnitude and direction of gravity and can be used to identify the posture of the electronic device (such as landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc. The sensor 505 may also include a fingerprint sensor, pressure sensor, iris sensor, molecular sensor, gyroscope, barometer, hygrometer, thermometer, infrared sensor, etc., which will not be described in detail here.
[0131] The display unit 506 is used to display information input by the user or information provided to the user. The display unit 506 may include a display panel 5061, which may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.
[0132] User input unit 507 can be used to receive input numerical or character information, and to generate key signal inputs related to user settings and function control of electronic devices. Specifically, user input unit 507 includes a touch panel 5071 and other input devices 5072. Touch panel 5071, also known as a touch screen, can collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near touch panel 5071). Touch panel 5071 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch position and the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 510, which receives and executes commands from the processor 510. In addition, touch panel 5071 can be implemented using various types such as resistive, capacitive, infrared, and surface acoustic wave. Besides touch panel 5071, user input unit 507 may also include other input devices 5072. Specifically, other input devices 5072 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, joysticks, etc., which will not be described in detail here.
[0133] Furthermore, the touch panel 5071 can cover the display panel 5061. When the touch panel 5071 detects a touch operation on or near it, it transmits the information to the processor 510 to determine the type of touch event. Subsequently, the processor 510 provides corresponding visual output on the display panel 5061 based on the type of touch event. Although in Figure 5 In this embodiment, the touch panel 5071 and the display panel 5061 are two independent components to realize the input and output functions of the electronic device. However, in some embodiments, the touch panel 5071 and the display panel 5061 can be integrated to realize the input and output functions of the electronic device. The specific implementation is not limited here.
[0134] Interface unit 508 serves as an interface for connecting external devices to electronic device 500. For example, external devices may include a wired or wireless headphone port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device with an identification module, an audio input / output (I / O) port, a video I / O port, a headphone port, and so on. Interface unit 508 can be used to receive input from external devices (e.g., data, power, etc.) and transmit the received input to one or more components within electronic device 500, or it can be used to transmit data between electronic device 500 and external devices.
[0135] The memory 509 can be used to store software programs and various data. The memory 509 may primarily include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function (such as sound playback, image playback, etc.), etc.; the data storage area may store data created based on the use of the mobile phone (such as audio data, phonebook, etc.). Furthermore, the memory 509 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0136] The processor 510 is the control center of the electronic device. It connects various parts of the electronic device via various interfaces and lines. By running or executing software programs and / or modules stored in the memory 509, and by calling data stored in the memory 509, it performs various functions and processes data, thereby providing overall monitoring of the electronic device. The processor 510 may include one or more processing units; preferably, the processor 510 may integrate an application processor and a modem processor. The application processor mainly handles the operating system, user interface, and applications, while the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 510.
[0137] The electronic device 500 may also include a power supply 511 (such as a battery) that supplies power to various components. Preferably, the power supply 511 can be logically connected to the processor 510 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system.
[0138] In addition, the electronic device 500 includes some functional modules not shown, which will not be described in detail here.
[0139] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0140] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0141] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of the present invention.
[0142] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed in this invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0143] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0144] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0145] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0146] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0147] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.
[0148] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method of communicating for an Internet of Things device, the method comprising: The Internet of Things device and the gateway node are connected to form an Internet of Things device network, and the method comprises: sending a registration message to the gateway node; the registration message includes device information of the Internet of Things device; the gateway node is used to perform identity authentication on the Internet of Things device according to the device information after receiving the registration message, and generate a registration completion message after successful authentication; the registration message includes device information for topic registration of the Internet of Things device; after receiving the registration completion message sent by the gateway node for the registration message, transmitting the message corresponding to the specified message topic between the gateway node using the topic identifier corresponding to the specified message topic, comprising: receiving the registration completion message sent by the gateway node for the registration message; wherein the registration completion message includes a first specified message topic identifier allocated by the gateway node for the first specified message topic after generating a first specified message topic according to the device information according to a preset topic naming rule; sending a subscription message to the gateway node; the subscription message includes a second specified message topic or a second specified message topic identifier corresponding to the second specified message topic; the node gateway is used to determine that the Internet of Things device subscribes to the second specified message topic according to the second specified message topic or the second specified message topic identifier; sending a publishing message corresponding to the first specified message topic to the gateway node using the first specified message topic identifier corresponding to the first specified message topic, and / or receiving the publishing message related to the second specified message topic subscribed by the Internet of Things device sent by the gateway node using the second specified message topic identifier corresponding to the second specified message topic.
2. The method of claim 1, wherein, The Internet of Things device at least includes a sensor device, and the Internet of Things device network composed of the sensor device is a sensor network, and the Internet of Things device and the gateway node are used for message transmission by using a message queue telemetry transmission protocol suitable for the sensor network.
3. The method of claim 1, wherein, The method further comprises: compressing the publishing message using a preset compression algorithm to obtain a compressed publishing message; encrypting the compressed publishing message using a preset encryption algorithm to obtain an encrypted and compressed publishing message.
4. The method of claim 1, wherein, The method further comprises: sending a heartbeat message to the gateway node at a preset time interval; receiving a heartbeat response message sent by the gateway node for the heartbeat message; wherein the gateway node is used to determine that the Internet of Things device is offline when the gateway node does not receive the heartbeat message sent by the Internet of Things device within a preset heartbeat time, and cache the publishing message related to the second specified topic message subscribed by the Internet of Things device when the Internet of Things device is offline; when the Internet of Things device is reconnected, receiving the publishing message related to the second specified topic message subscribed by the Internet of Things device cached by the gateway node when the Internet of Things device is offline.
5. The method of claim 1, wherein, The method further comprises: entering a low-power sleep mode when the Internet of Things device does not transmit a message; After the Internet of Things device enters the low-power sleep mode, the Internet of Things device is woken up when a preset wake-up time is reached or an external event is received.
6. The method of claim 1, wherein, The network topology of the Internet of Things device network is determined according to the number of the Internet of Things devices and the use environment; and the network topology at least includes a star topology, a tree topology and a mesh topology.
7. The method of claim 1, wherein, The method further comprises: determining a quality of service level corresponding to the Internet of Things device; after the Internet of Things device sends a message to the gateway node, if an acknowledgement message sent by the gateway node is not received within a preset time, the message is re-sent according to the quality of service level corresponding to the Internet of Things device.
8. The method of claim 1, wherein, The gateway node and the Internet of Things device are configured to send the message sent by the Internet of Things device to the cloud server after processing; the processing at least includes data aggregation and preprocessing.
9. An Internet of Things device communication apparatus, comprising: The Internet of Things device and the gateway node are communicatively connected to form an Internet of Things device network, and the device comprises: a message sending module configured to send a registration message to the gateway node; the registration message comprises device information of the Internet of Things device; the gateway node is configured to perform identity authentication on the Internet of Things device according to the device information after receiving the registration message, and generate a registration completion message after successful authentication; the registration message comprises device information for topic registration of the Internet of Things device; a message transmission module configured to, after receiving the registration completion message sent by the gateway node for the registration message, transmit a message corresponding to a specified message topic between the gateway node using a topic identifier corresponding to the specified message topic, comprising: receiving the registration completion message sent by the gateway node for the registration message; wherein the registration completion message comprises a first specified message topic identifier allocated by the gateway node for a first specified message topic generated by the gateway node according to the device information according to a preset topic naming rule; sending a subscription message to the gateway node; the subscription message comprises a second specified message topic or a second specified message topic identifier corresponding to the second specified message topic; the node gateway is configured to determine that the Internet of Things device subscribes to the second specified message topic according to the second specified message topic or the second specified message topic identifier; sending a publishing message corresponding to the first specified message topic to the gateway node using the first specified message topic identifier corresponding to the first specified message topic, and / or receiving a publishing message related to the second specified message topic subscribed by the Internet of Things device sent by the gateway node using the second specified message topic identifier corresponding to the second specified message topic.
10. An electronic device, comprising: The device comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete communication with each other through the communication bus; The memory is configured to store a computer program; The processor is configured to execute the program stored on the memory to implement the method of any one of claims 1-8.
11. A computer-readable storage medium having stored thereon instructions that, when executed by one or more processors, cause the processors to perform the method of any one of claims 1-8.
Citation Information
Patent Citations
Message processing method and device, equipment and storage medium
CN115378974A