WO2023098816A1 - 基于mqtt协议的设备通信方法及装置 - Google Patents

基于mqtt协议的设备通信方法及装置 Download PDF

Info

Publication number
WO2023098816A1
WO2023098816A1 PCT/CN2022/135911 CN2022135911W WO2023098816A1 WO 2023098816 A1 WO2023098816 A1 WO 2023098816A1 CN 2022135911 W CN2022135911 W CN 2022135911W WO 2023098816 A1 WO2023098816 A1 WO 2023098816A1
Authority
WO
WIPO (PCT)
Prior art keywords
message
mqtt
topic
random
node
Prior art date
Application number
PCT/CN2022/135911
Other languages
English (en)
French (fr)
Inventor
孙一牧
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2023098816A1 publication Critical patent/WO2023098816A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/08Network architectures or network communication protocols for network security for authentication of entities
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/12Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks
    • H04L67/125Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks involving control of end-device applications over a network
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/40Network security protocols
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04QSELECTING
    • H04Q9/00Arrangements in telecontrol or telemetry systems for selectively calling a substation from a main station, in which substation desired apparatus is selected for applying a control signal thereto or for obtaining measured values therefrom

Definitions

  • the embodiments of the present invention relate to the communication field, and in particular, relate to a device communication method and device based on the Message Queuing Telemetry Transport (MQTT) protocol.
  • MQTT Message Queuing Telemetry Transport
  • the MQTT protocol is an IoT communication protocol. As a low-overhead, low-bandwidth instant messaging protocol, it has a wide range of applications in the Internet of Things, small devices, and mobile applications.
  • the MQTT protocol is based on the Publish/Subscribe (Publish/Subscribe) mode. In this mode, two IoT nodes with communication needs often communicate through agreed topics.
  • TLS Transport Layer Security
  • the illegal device can also be authenticated to access the MQTT network by extracting the corresponding authentication certificate
  • Embodiments of the present invention provide a device communication method and device based on the MQTT protocol, so as to at least solve the problem of security risks in the communication between devices based on the MQTT protocol in the related art.
  • a device communication method based on the MQTT protocol is provided, which is applied to an MQTT topic management server, including: receiving a first message reported by a controlled node, wherein the first message includes the controlled the device ID of the control node; generate a random topic corresponding to the device ID of the controlled node, and return the random topic to the controlled node; after the control node is authenticated, send the random topic to the control node, so that the control node and the controlled node perform MQTT protocol communication through the random topic.
  • the MQTT topic management server receiving the first message reported by the controlled node includes: the MQTT topic management server receiving the submission of the controlled node through Hyper Text Transfer Protocol (Hyper Text Transfer Protocol, HTTP) The first message reported by the (POST) method.
  • Hyper Text Transfer Protocol Hyper Text Transfer Protocol, HTTP
  • the MQTT topic management server generates a random topic corresponding to the device ID of the controlled node, and returns the random topic to the controlled node, including: the MQTT topic management The server invokes a random character string generator to generate a first random character string as the random subject, and caches the mapping between the device ID of the controlled node and the first random character string; the MQTT topic management server converts the A first random string is returned to the controlled node.
  • the MQTT topic management server after the MQTT topic management server returns the first random character string to the controlled node, it further includes: the MQTT topic management server sends a first subscription message to the MQTT proxy server , wherein the subscription topic in the first subscription message is a will topic, and the will topic includes the first random character string and a fixed suffix.
  • the MQTT topic management server after the MQTT topic management server returns the first random character string to the controlled node, it further includes: the controlled node sends an MQTT connection message to the MQTT proxy server, Wherein, the will topic in the MQTT connection message includes the first random character string and a fixed suffix.
  • the method further includes: after the controlled node MQTT connection is successful, sending a second subscription message to the MQTT proxy server, and the subscription topic in the second subscription message is the first A random string.
  • the MQTT topic management server before the MQTT topic management server sends the random topic to the control node, it further includes: the MQTT topic management server receives the authentication message reported by the control node through HTTP POST, and the authentication The message includes the user name and password required for the control node authentication; the MQTT topic management server sends a first reply message to the control node, wherein Cookie is set in the first reply message as an authentication mark; the The MQTT topic management server receives the second message sent by the control node, wherein the second message includes the device ID of the controlled node and the returned Cookie; the MQTT topic management server according to the second The cookie in the message confirms that the node sending the message is the control node, and according to the device ID in the message, searches for the first random character string in the mapping between the cached device ID and the first random character string, and generates a second random character string character string, and return the first random character string and the second random character string to the control node.
  • the control node after returning the first random character string and the second random character string to the control node, it further includes: the control node sends a third subscription message to the MQTT proxy server, wherein , the subject of the subscription in the third subscription message is the second random character string; after the control node receives a reply from the MQTT proxy server that the subscription is successful, it sends a first publishing message to the MQTT proxy server, The MQTT topic of the first published message is the first random character string, and the message content includes a management message and a second random character string.
  • the MQTT proxy server after the MQTT proxy server receives the first publishing message, it further includes: forwarding the first publishing message to the controlled node by the MQTT proxy server; After the node executes the management message according to the first release message, it sends a second release message to the MQTT proxy server, wherein the MQTT topic of the second release message is the second random character string, and the message content is the A reply to the management message; after receiving the second publishing message, the MQTT proxy server forwards the second publishing message to the control node based on the MQTT topic being a second random character string.
  • the method further includes: the MQTT proxy server discovers that the controlled node is offline, then sends a third publishing message to all nodes subscribing to the will topic, the third publishing message The content of the message is that the controlled node is offline.
  • the method further includes: after the MQTT topic management server receives the third MQTT publishing message, deleting the cached device ID and the first random character of the controlled node according to the random topic string map.
  • the method further includes: the MQTT topic management server receives the authentication message reported by the control node through HTTP POST, the authentication message includes the user name and password required for authentication of the control node; The MQTT topic management server sends a first reply message to the control node, wherein a Cookie is set in the first reply message as an authentication mark; the MQTT topic management server receives the second message sent by the control node , wherein, the second message includes the device ID of the controlled node and the returned Cookie; the MQTT topic management server confirms that the node sending the message is the control node according to the Cookie in the second message, And according to the device ID in the message, search for the first random character string in the mapping between the cached device ID and the first random character string, if not found, then send a second reply message to the control node, wherein, The content of the second reply message is that the controlled node cannot be found.
  • the MQTT topic management server after the MQTT topic management server sends the second reply message to the control node, it further includes: the control node discovers that the subject If the control node is offline, the management of the controlled node will be abandoned.
  • a device communication method based on the MQTT protocol which is applied to a controlled node, and the method includes: reporting a first message to the MQTT topic management server, wherein the first Including the device ID of the controlled node in the message; receiving the random topic generated by the MQTT topic management server corresponding to the device ID of the controlled node; passing the authentication of the MQTT topic management server at the control node, and from After the MQTT topic management server obtains the random topic, the controlled node and the control node perform MQTT protocol communication through the random topic.
  • an MQTT topic management server including: a first receiving module configured to receive a first message reported by a controlled node, wherein the first message includes the controlled The device ID of the node; the generation module is configured to generate a random topic corresponding to the device ID of the controlled node, and returns the random topic to the controlled node; the authentication module is configured to be used for the control node After authentication, the random topic is sent to the control node, so that the control node and the controlled node perform MQTT protocol communication through the random topic.
  • a controlled node which includes: a sending module configured to report a first message to the MQTT topic management server, wherein the first message includes the The device ID of the controlled node; the second receiving module is configured to receive the random topic generated by the MQTT topic management server corresponding to the device ID of the controlled node; the communication module is configured to pass the MQTT topic at the control node The authentication of the management server, and after obtaining the random topic from the MQTT topic management server, perform MQTT protocol communication with the control node through the random topic.
  • a computer-readable storage medium is also provided, and a computer program is stored in the computer-readable storage medium, wherein the computer program is configured to perform any one of the above methods when running Steps in the examples.
  • an electronic device including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to perform any of the above Steps in the method examples.
  • the MQTT topic of node communication is managed by the MQTT topic management server, and by randomizing the MQTT topic, malicious network nodes cannot intercept or interfere with node communication, thereby improving the performance of the MQTT protocol network.
  • the effect of inter-node communication security is achieved by the MQTT topic management server, and by randomizing the MQTT topic, malicious network nodes cannot intercept or interfere with node communication, thereby improving the performance of the MQTT protocol network.
  • FIG. 1 is a schematic diagram of a network structure according to an embodiment of the present invention.
  • Fig. 2 is a flowchart of a device communication method based on the MQTT protocol according to an embodiment of the present invention
  • Fig. 3 is a structural block diagram of an MQTT topic management server according to an embodiment of the present invention.
  • FIG. 4 is a schematic structural diagram of a controlled node according to an embodiment of the present invention.
  • FIG. 5 is a flowchart of a communication method in an online scene of a controlled node according to an embodiment of the present invention
  • Fig. 6 is a flowchart of a communication method in a controlled node offline scenario according to an embodiment of the present invention.
  • an MQTT client can subscribe to a topic, or push a message to a topic.
  • the MQTT proxy server receives a message pushed to a topic by an MQTT client, and sends the message to all other MQTT clients that subscribe to this topic.
  • this mechanism provides convenience for one-to-many communication, and on the other hand, it also makes the information of one-to-one communication easy to be obtained by other MQTT clients.
  • the MQTT client can register the will message with the MQTT proxy server, when the MQTT client disconnects the MQTT connection or no longer responds to the heartbeat.
  • the MQTT broker server will push this registered will message to the registered topic.
  • the embodiment of the present invention provides a device communication method based on the MQTT protocol.
  • the Internet of Things device nodes (ie, controlled nodes) and management nodes (ie, control nodes) in the network environment to which the embodiments of the present invention are applied are connected to the MQTT proxy server as MQTT clients to form an MQTT network.
  • the IoT device node can be connected to the MQTT topic management server, and can only report the device ID, but cannot obtain information from the MQTT topic management server.
  • the management node can connect to the MQTT topic management server through strong authentication (such as user name/password login), and can obtain the MQTT topic of secure communication with the device ID that it wants to manage.
  • the network architecture applied in the embodiment of the present invention is as follows:
  • MQTT proxy server responsible for accepting MQTT connections and forwarding MQTT messages. The message interaction between the control node and the controlled node is forwarded by the MQTT proxy server.
  • Controlled node Generally, it is an IoT device node, which accepts the configuration/information query of the control node.
  • Control node Generally, it is the management background of the IoT device or the management controlled node PP, which is responsible for the management/information collection of the IoT device.
  • MQTT topic management server accepts the HTTP connection between the controlled node and the control node.
  • the controlled node reports the device ID through the HTTP POST method, and the MQTT topic management server will generate a corresponding random topic.
  • the control node obtains the random topic corresponding to the device ID through the GET method of HTTP.
  • Random String Generator Called by the MQTT Topic Management Server to generate a random MQTT Topic and ensure that the generated random string will not repeat.
  • FIG. 2 is a flow chart of the method according to the embodiment of the present invention. As shown in FIG. 2, the process includes the following steps:
  • Step S201 The MQTT topic management server receives the first message reported by the controlled node, wherein the first message includes the device ID of the controlled node;
  • Step S202 the MQTT topic management server generates a random topic corresponding to the device ID of the controlled node, and returns the random topic to the controlled node;
  • step S203 the MQTT topic management server sends the random topic to the control node after authenticating the control node, so that the control node and the controlled node can perform MQTT protocol communication through the random topic.
  • the MQTT topic management server receives the first message reported by the controlled node through a POST method of HTTP.
  • the MQTT topic management server calls a random string generator to generate a first random string as the random topic, and caches the device ID of the controlled node and the first random character string mapping; the MQTT topic management server returns the first random string to the controlled node.
  • the MQTT topic management server after the MQTT topic management server returns the first random character string to the controlled node, it further includes: the MQTT topic management server sends a first subscription message to the MQTT proxy server , wherein the subscription topic in the first subscription message is a will topic, and the will topic includes the first random character string and a fixed suffix.
  • the MQTT topic management server after the MQTT topic management server returns the first random character string to the controlled node, it further includes: the controlled node sends an MQTT connection message to the MQTT proxy server, Wherein, the will topic in the MQTT connection message includes the first random character string and a fixed suffix.
  • the method further includes: after the controlled node MQTT connection is successful, sending a second subscription message to the MQTT proxy server, and the subscription topic in the second subscription message is the first A random string.
  • the MQTT topic management server before the MQTT topic management server sends the random topic to the control node, it further includes: the MQTT topic management server receives the authentication message reported by the control node through HTTP POST, and the authentication The message includes the user name and password required for the control node authentication; the MQTT topic management server sends a first reply message to the control node, wherein Cookie is set in the first reply message as an authentication mark; the The MQTT topic management server receives the second message sent by the control node, wherein the second message includes the device ID of the controlled node and the returned Cookie; the MQTT topic management server according to the second The cookie in the message confirms that the node sending the message is the control node, and according to the device ID in the message, searches for the first random character string in the mapping between the cached device ID and the first random character string, and generates a second random character string character string, and return the first random character string and the second random character string to the control node.
  • the control node after returning the first random character string and the second random character string to the control node, it further includes: the control node sends a third subscription message to the MQTT proxy server, wherein , the subject of the subscription in the third subscription message is the second random character string; after the control node receives a reply from the MQTT proxy server that the subscription is successful, it sends a first publishing message to the MQTT proxy server, The MQTT topic of the first published message is the first random character string, and the message content includes a management message and a second random character string.
  • the MQTT proxy server after the MQTT proxy server receives the first publishing message, it further includes: forwarding the first publishing message to the controlled node by the MQTT proxy server; After the node executes the management message according to the first release message, it sends a second release message to the MQTT proxy server, wherein the MQTT topic of the second release message is the second random character string, and the message content is the A reply to the management message; after receiving the second publishing message, the MQTT proxy server forwards the second publishing message to the control node based on the MQTT topic being a second random character string.
  • the method further includes: the MQTT proxy server discovers that the controlled node is offline, then sends a third publishing message to all nodes subscribing to the will topic, the third publishing message The content of the message is that the controlled node is offline.
  • the method further includes: after the MQTT topic management server receives the third MQTT publishing message, deleting the cached device ID and the first random character of the controlled node according to the random topic string map.
  • the method further includes: the MQTT topic management server receives the authentication message reported by the control node through HTTP POST, the authentication message includes the user name and password required for authentication of the control node; The MQTT topic management server sends a first reply message to the control node, wherein a Cookie is set in the first reply message as an authentication mark; the MQTT topic management server receives the second message sent by the control node , wherein, the second message includes the device ID of the controlled node and the returned Cookie; the MQTT topic management server confirms that the node sending the message is the control node according to the Cookie in the second message, And according to the device ID in the message, search for the first random character string in the mapping between the cached device ID and the first random character string, if not found, then send a second reply message to the control node, wherein, The content of the second reply message is that the controlled node cannot be found.
  • the MQTT topic management server after the MQTT topic management server sends the second reply message to the control node, it further includes: the control node discovers that the subject If the control node is offline, the management of the controlled node will be abandoned.
  • the MQTT topic of node communication is managed by the MQTT topic management server, and by randomizing the MQTT topic, malicious network nodes cannot intercept or interfere with node communication, thereby improving the performance of the MQTT protocol network.
  • the effect of inter-node communication security is achieved by the MQTT topic management server, and by randomizing the MQTT topic, malicious network nodes cannot intercept or interfere with node communication, thereby improving the performance of the MQTT protocol network.
  • an MQTT topic management server and a controlled node are also provided for implementing the above embodiments and preferred implementation manners, which have already been explained and will not be repeated.
  • the term "module” may be a combination of software and/or hardware that realizes a predetermined function.
  • the devices described in the following embodiments are preferably implemented in software, implementations in hardware, or a combination of software and hardware are also possible and contemplated.
  • FIG. 3 is a structural block diagram of an MQTT topic management server according to an embodiment of the present invention.
  • the MQTT topic management server 100 includes a first receiving module 10 , a generating module 20 and an authentication module 30 .
  • the first receiving module 10 is configured to receive a first message reported by the controlled node, wherein the first message includes the device ID of the controlled node.
  • the generating module 20 is configured to generate a random topic corresponding to the device ID of the controlled node, and return the random topic to the controlled node.
  • the authentication module 30 is configured to, after authenticating the control node, send the random topic to the control node, so that the control node and the controlled node perform MQTT protocol communication through the random topic.
  • FIG. 4 is a structural block diagram of a controlled node according to an embodiment of the present invention.
  • the controlled node 200 includes a sending module 40 , a second receiving module 50 and a communication module 60 .
  • the sending module 40 is configured to report a first message to the MQTT topic management server, wherein the first message includes the device ID of the controlled node.
  • the second receiving module 50 is configured to receive a random topic generated by the MQTT topic management server and corresponding to the device ID of the controlled node.
  • the communication module 60 is configured to perform MQTT protocol communication with the control node through the random topic after the control node passes the authentication of the MQTT topic management server and obtains the random topic from the MQTT topic management server.
  • the above-mentioned modules can be realized by software or hardware. For the latter, it can be realized by the following methods, but not limited to this: the above-mentioned modules are all located in the same processor; or, the above-mentioned modules can be combined in any combination The forms of are located in different processors.
  • This embodiment provides a device communication method based on the MQTT protocol.
  • the controlled node accesses the MQTT network and is managed by the control node.
  • the method of this implementation includes the following steps:
  • Step S501 the controlled node sends an HTTP POST message (message 1) to the MQTT topic management server.
  • This message contains the node device ID.
  • Step S502 after receiving the message 1, the MQTT topic management server invokes the random string generator to generate a random string 1, and caches the mapping between the device ID and the random string 1. And return the random character string 1 to the controlled node as the reply of the message 1.
  • the MQTT topic management server then sends an MQTT Subscribe message (message 2) to the MQTT proxy server, and the subscription topic is: random string 1+"Last Will". For example, if the random string is: random String, then subscribe to the topic: random String Last Will.
  • Step S504 the controlled node receives the reply of message 1, sends the MQTT CONNECT message (message 3) to the MQTT proxy server, and sets the Will Topic in the CONNECT message to random string 1+"Last Will", and the Will Message to "offline” .
  • Step S505 after the controlled node MQTT connection is successful, it sends an MQTT Subscribe message (message 4) to the MQTT proxy server, and the subscription subject is: random string 1.
  • Step S506 the control node accesses the network, and sends an HTTP POST message (message 5) to the MQTT topic management server, and the content of the message is the username/password required for the control node authentication.
  • the MQTT topic management server receives message 5, and after authenticating the user name/password, sets Cookie in the reply of message 5 as a mark of authentication.
  • step S507 the control node needs to establish a connection with the controlled node for management.
  • the control node sends an HTTP POST message (message 6) to the MQTT topic management server.
  • the message content includes the device ID of the controlled node and the Cookie returned in message 5.
  • Step S508 the MQTT topic management server receives message 6, recognizes the node sending the message as the control node according to the Cookie in the message, and then searches the mapping between the device ID in its own server and random string 1 according to the device ID in the message random string 1 and generate random string 2 at the same time. And return the random character string 1 and the random character string 2 to the control node as the reply of the message 6.
  • Step S509 the control node sends an MQTT Subscribe message (message 7) to the MQTT proxy server, and the subscribed topic is random character string 2.
  • Step S510 after receiving the reply of successful subscription from the MQTT proxy server, the control node sends an MQTT Publish message to the MQTT proxy server (message 8).
  • the MQTT topic of this message is random string 1, and the message content is management message + random string 2 .
  • the MQTT proxy server receives the message 8, because the MQTT topic is a random string 1, so according to the MQTT protocol function, it will forward this message to the controlled node.
  • step S511 the controlled node receives message 8 and executes the management message.
  • Send the Publish message to the MQTT proxy server (message 9) the MQTT topic of this message is random string 2, and the message content is the reply of the management message.
  • Step S512 the MQTT proxy server receives the message 9, because the MQTT topic is a random character string 2, so according to the function of the MQTT protocol, it will forward this message to the control node.
  • the control node receives the message 9, and completes the sending and receiving of the management message.
  • This embodiment also provides a device communication method based on the MQTT protocol.
  • the difference from Embodiment 1 is that in this embodiment, the controlled node is offline, and the control node cannot manage the controlled node.
  • the initial state of each node is between step S506 and step S507 in embodiment 1. At this time, both the controlled node and the control node have been initialized, but the control node has not started to connect to the controlled node.
  • the method of this embodiment mainly includes the following steps:
  • Step S601 the controlled node is offline.
  • the MQTT proxy server finds that the connection of the controlled node is disconnected, and sends an MQTT Publish message (message 1) to all nodes subscribing to the subject of random string 1+"LastWill", and the content of the message is "offline".
  • Step S602 because the MQTT topic management server has subscribed to the random string 1+"LastWill" topic during the controlled node random topic process, so the MQTT topic management server will receive message 1.
  • the random MQTT topic management server deletes the mapping relationship between the device ID and the random string 1 according to the random topic 1.
  • step S603 the control node establishes a connection with the controlled node for management.
  • the control node sends an HTTP POST message (message 2) to the MQTT topic management server, and the message content includes the device ID of the controlled node and the authentication cookie.
  • Step S604 the MQTT topic management server receives message 2, recognizes the node sending the message as the control node according to the Cookie in the message, and then searches the mapping between the device ID in its own server and random string 1 according to the device ID in the message The random string 1, but failed to find. Then reply message 2, the content of the message is: No device found.
  • step S605 the control node receives the reply of message 2, finds that the controlled node is offline, and immediately gives up this management.
  • the above embodiments of the present invention expand a point-to-point secure communication solution on the basis of the MQTT protocol network, and solve the point-to-point secure communication requirements of IoT devices in the MQTT network due to reasons such as configuration management/information collection.
  • Embodiments of the present invention also provide a computer-readable storage medium, in which a computer program is stored, wherein the computer program is set to execute the steps in any one of the above method embodiments when running.
  • the above-mentioned computer-readable storage medium may include but not limited to: U disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM)
  • U disk read-only memory
  • ROM read-only memory
  • RAM random access memory
  • Various media that can store computer programs such as mobile hard disks, magnetic disks, or optical disks.
  • An embodiment of the present invention also provides an electronic device, including a memory and a processor, where a computer program is stored in the memory, and the processor is configured to run the computer program to perform the steps in any one of the above method embodiments.
  • the electronic device may further include a transmission device and an input and output device, wherein the transmission device is connected to the processor, and the input and output device is connected to the processor.
  • each module or each step of the present invention described above can be realized by a general-purpose computing device, and they can be concentrated on a single computing device, or distributed in a network formed by multiple computing devices In fact, they can be implemented in program code executable by a computing device, and thus, they can be stored in a storage device to be executed by a computing device, and in some cases, can be executed in an order different from that shown here. Or described steps, or they are fabricated into individual integrated circuit modules, or multiple modules or steps among them are fabricated into a single integrated circuit module for implementation. As such, the present invention is not limited to any specific combination of hardware and software.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computing Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Health & Medical Sciences (AREA)
  • General Health & Medical Sciences (AREA)
  • Medical Informatics (AREA)
  • Computer Hardware Design (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

本发明实施例提供了一种基于MQTT协议的设备通信方法及装置,该方法应用于MQTT主题管理服务器,包括如下步骤:接收受控节点上报的第一消息,其中,所述第一消息中包括所述受控节点的设备ID;生成对应于所述受控节点的设备ID的随机主题,并将所述随机主题返回至所述受控节点;在对所述控制节点认证后,将所述随机主题发送至所述控制节点,以便所述控制节点与受控节点通过所述随机主题进行MQTT协议通信。在本发明中,通过MQTT主题管理服务器来管理节点通信的MQTT主题,并通过将MQTT主题随机化,使得恶意网络节点无法侦听或干扰到节点通信,从而提高了MQTT协议网络的节点间的通信安全。

Description

基于MQTT协议的设备通信方法及装置 技术领域
本发明实施例涉及通信领域,具体而言,涉及一种基于消息队列遥测传输(Message Queuing Telemetry Transport,MQTT)协议的设备通信方法及装置。
背景技术
MQTT协议是一种物联网通讯协议。作为一种低开销、低带宽占用的即时通讯协议,使其在物联网、小型设备、移动应用等方面有较广泛的应用。
物联网系统中,常存在有点对点的设备配置/信息查询需求。而MQTT协议基于发布/订阅(Publish/Subscribe)模式,在这种模式下,有通讯需求的两个物联网节点之间往往通过约定的主题进行通讯。
在此种机制下,如果网络中存在知晓约定主题的恶意MQTT节点,即可通过订阅特定的主题来窃取隐私信息,或向特定主题发布错误的配置信息。造成了巨大的信息安全风险。
目前常见的防范此类安全问题的做法是,禁止非法节点接入MQTT网络。如在MQTT协议下层使用传输层安全(Transport Layer Security,TLS)协议的双向认证功能来确保只有合法设备可以接入MQTT网络。但是此方案有如下缺陷:
1、若物联网设备的软件被破解,通过提取对应的认证证书,非法设备也可以认证接入MQTT网络;
2、网络攻击者可以通过物联网设备的其他网络服务,入侵已经接入MQTT网络的物联网设备,达到非法入侵MQTT网络的目的。
发明内容
本发明实施例提供了一种基于MQTT协议的设备通信方法及装置,以至少解决相关技术中基于MQTT协议的设备间通信存在安全风险的问题。
根据本发明的一个实施例,提供了一种基于MQTT协议的设备通信方法,应用于MQTT主题管理服务器包括:接收受控节点上报的第一消息,其中,所述第一消息中包括所述受控节点的设备ID;生成对应于所述受控节点的设备ID的随机主题,并将所述随机主题返回至所述受控节点;在对所述控制节点认证后,将所述随机主题发送至所述控制节点,以便所述控制节点与受控节点通过所述随机主题进行MQTT协议通信。
在一个示例性实施例中,MQTT主题管理服务器接收受控节点上报的第一消息包括:所述MQTT主题管理服务器接收所述受控节点通过超文本传输协议(Hyper Text Transfer Protocol,HTTP)的提交(POST)方法上报的所述第一消息。
在一个示例性实施例中,所述MQTT主题管理服务器生成对应于所述受控节点的设备ID的随机主题,并将所述随机主题返回至所述受控节点,包括:所述MQTT主题管理服务器调用随机字符串生成器,生成第一随机字符串作为所述随机主题,并缓存所述受控节点的设备ID 与所述第一随机字符串的映射;所述MQTT主题管理服务器将所述第一随机字符串返回至所述受控节点。
在一个示例性实施例中,在所述MQTT主题管理服务器将所述第一随机字符串返回至所述受控节点之后,还包括:所述MQTT主题管理服务器向MQTT代理服务器发送第一订阅消息,其中,所述第一订阅消息中的订阅主题为遗嘱主题,所述遗嘱主题包含所述第一随机字符串和固定后缀。
在一个示例性实施例中,所述MQTT主题管理服务器将所述第一随机字符串返回至所述受控节点之后,还包括:所述受控节点向所述MQTT代理服务器发送MQTT连接消息,其中,所述MQTT连接消息中的遗嘱主题包含所述第一随机字符串和固定后缀。
在一个示例性实施例中,所述方法还包括:所述受控节点MQTT连接成功后,向所述MQTT代理服务器发送第二订阅消息,所述第二订阅消息中的订阅主题为所述第一随机字符串。
在一个示例性实施例中,所述MQTT主题管理服务器将所述随机主题发送至控制节点之前,还包括:MQTT主题管理服务器接收所述控制节点通过HTTP的POST方式上报的认证消息,所述认证消息中包括所述控制节点认证需要的用户名和密码;所述MQTT主题管理服务器对所述控制节点发送第一回复消息,其中,在所述第一回复消息中设置Cookie作为认证的标记;所述MQTT主题管理服务器接收所述控制节点发送的第二消息,其中,所述第二消息中包含所述受控节点的设备ID以及所述返回的Cookie;所述MQTT主题管理服务器根据所述第二消息中Cookie确认发消息的节点为所述控制节点,并根据消息中的设备ID,在缓存的设备ID与第一随机字符串的映射中查找所述第一随机字符串.并生成第二随机字符串,并将所述第一随机字符串和第二随机字符串返回给所述控制节点。
在一个示例性实施例中,将所述第一随机字符串和第二随机字符串返回给所述控制节点之后,还包括:所述控制节点发送第三订阅消息给所述MQTT代理服务器,其中,所述第三订阅消息中的订阅的主题为所述第二随机字符串;所述控制节点收到所述MQTT代理服务器订阅成功的回复后,发送第一发布消息给所述MQTT代理服务器,所述第一发布消息的MQTT主题为所述第一随机字符串,消息内容包括管理消息和第二随机字符串。
在一个示例性实施例中,所述MQTT代理服务器收到所述第一发布消息之后,还包括:所述MQTT代理服务器将所述第一发布消息转发给所述受控节点;所述受控节点根据所述第一发布消息执行完管理消息后,发送第二发布消息给所述MQTT代理服务器,其中,所述第二发布消息的MQTT主题为所述第二随机字符串,消息内容为所述管理消息的回复;所述MQTT代理服务器接收到所述第二发布消息后,基于所述MQTT主题为第二随机字符串,将所述第二发布消息转发给所述控制节点。
在一个示例性实施例中,所述方法还包括:所述MQTT代理服务器发现所述受控节点离线,则向所有订阅所述遗嘱主题的节点发送第三发布消息,所述第三发布消息的消息内容为所述受控节点离线。
在一个示例性实施例中,所述方法还包括:所述MQTT主题管理服务器接收到所述第三MQTT发布消息后,根据随机主题删除缓存的所述受控节点的设备ID与第一随机字符串的映射。
在一个示例性实施例中,所述方法还包括:MQTT主题管理服务器接收所述控制节点通过HTTP的POST方式上报的认证消息,所述认证消息中包括所述控制节点认证需要的用户名和 密码;所述MQTT主题管理服务器对所述控制节点发送第一回复消息,其中,在所述第一回复消息中设置Cookie作为认证的标记;所述MQTT主题管理服务器接收所述控制节点发送的第二消息,其中,所述第二消息中包含所述受控节点的设备ID以及所述返回的Cookie;所述MQTT主题管理服务器根据所述第二消息中Cookie确认发消息的节点为所述控制节点,并根据消息中的设备ID,在缓存的设备ID与第一随机字符串的映射中查找所述第一随机字符串,如果未能找到,则发送第二回复消息至所述控制节点,其中,所述第二回复消息的内容为未能找到所述受控节点。
在一个示例性实施例中,所述MQTT主题管理服务器发送所述第二回复消息至所述控制节点之后,还包括:所述控制节点根据接收到的所述第二回复消息,发现所述受控节点已离线,则放弃此次对受控节点的管理。
根据本发明的另一个实施例,还提供了一种基于MQTT协议的设备通信方法,应用于受控节点,该方法包括:向所述MQTT主题管理服务器上报第一消息,其中,所述第一消息中包括所述受控节点的设备ID;接收所述MQTT主题管理服务器生成的对应于所述受控节点的设备ID的随机主题;在控制节点通过所述MQTT主题管理服务器的认证,并从所述MQTT主题管理服务器获得所述随机主题之后,所述受控节点与控制节点通过所述随机主题进行MQTT协议通信。
根据本发明的另一个实施例,提供了一种MQTT主题管理服务器,包括:第一接收模块,设置为接收受控节点上报的第一消息,其中,所述第一消息中包括所述受控节点的设备ID;生成模块,设置为生成对应于所述受控节点的设备ID的随机主题,并将所述随机主题返回至所述受控节点;认证模块,设置为在对所述控制节点认证后,将所述随机主题发送至所述控制节点,以便所述控制节点与受控节点通过所述随机主题进行MQTT协议通信。
根据本发明的另一个实施例,还提供了一种受控节点,其中,包括:发送模块,设置为向所述MQTT主题管理服务器上报第一消息,其中,所述第一消息中包括所述受控节点的设备ID;第二接收模块,设置为接收所述MQTT主题管理服务器生成的对应于所述受控节点的设备ID的随机主题;通信模块,设置为在控制节点通过所述MQTT主题管理服务器的认证,并从所述MQTT主题管理服务器获得所述随机主题之后,通过所述随机主题与所述控制节点进行MQTT协议通信。
根据本发明的又一个实施例,还提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机程序,其中,所述计算机程序被设置为运行时执行上述任一项方法实施例中的步骤。
根据本发明的又一个实施例,还提供了一种电子装置,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为运行所述计算机程序以执行上述任一项方法实施例中的步骤。
在本发明的上述实施例中,通过MQTT主题管理服务器来管理节点通信的MQTT主题,并通过将MQTT主题随机化,使得恶意网络节点无法侦听或干扰到节点通信,从而达到提高MQTT协议网络的节点间通信安全的效果。
附图说明
图1是根据本发明实施例的网络结构示意图;
图2是根据本发明实施例的基于MQTT协议的设备通信方法流程图;
图3是根据本发明实施例的MQTT主题管理服务器的结构框图;
图4是根据本发明实施例的受控节点的结构示意图;
图5是根据本发明实施例的受控节点在线场景的通信方法流程图;
图6是根据本发明实施例的受控节点离线场景的通信方法流程图。
具体实施方式
下文中将参考附图并结合实施例来详细说明本发明的实施例。
需要说明的是,本发明的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。
在MQTT网络中,MQTT客户端可以订阅主题,或向某个主题推送消息。MQTT代理服务器收到某个MQTT客户端推送到某主题的消息,会将此消息发送到其他所有订阅此主题的MQTT客户端。此种机制一方面为单对多通讯提供了便利,另一方面也使得单对单通讯的信息,容易被其他MQTT客户端获得。同时MQTT客户端可以向MQTT代理服务器注册遗嘱消息,在MQTT客户端断开MQTT链接或者不再响应心跳时。MQTT代理服务器将向注册的主题推送此注册的遗嘱消息。
为此本发明实施例提供了一种基于MQTT协议的设备通信方法。本发明实施例所应用的网络环境中的物联网设备节点(即,受控节点)和管理节点(即,控制节点)均作为MQTT客户端连接到MQTT代理服务器,组成MQTT网络。
在本实施例中,物联网设备节点可以连接到MQTT主题管理服务器,并只能上报设备ID,不能从MQTT主题管理服务器获取信息。管理节点可以通过强认证方式(如用户名/密码登录)连接到MQTT主题管理服务器,并可以以想要管理的设备ID来获得安全通信的MQTT主题。
如图1所示,本发明实施例所应用的网络架构如下:
MQTT代理服务器:负责接受MQTT连接,转发MQTT消息。控制节点与受控节点的消息交互均由MQTT代理服务器转发。
受控节点:一般为物联网设备节点,接受控制节点的配置/信息查询。
控制节点:一般为物联网设备的管理后台或管理受控节点PP,负责对物联网设备的管理/信息收集。
MQTT主题管理服务器:接受受控节点与控制节点的HTTP连接。受控节点通过HTTP的POST方法上报设备ID,MQTT主题管理服务器会生成对应的随机主题。控制节点通过HTTP的GET方法获取设备ID对应的随机主题。
随机字符串生成器:受MQTT主题管理服务器调用,生成随机MQTT主题,并保证生成的随机字符串不会重复。
本发明实施例提供的基于MQTT协议的设备通信方法可以运行于图1所示的网络架构上,图2是根据本发明实施例的方法流程图,如图2所示,该流程包括如下步骤:
步骤S201MQTT主题管理服务器接收受控节点上报的第一消息,其中,所述第一消息中包括所述受控节点的设备ID;
步骤S202,所述MQTT主题管理服务器生成对应于所述受控节点的设备ID的随机主题,并将所述随机主题返回至所述受控节点;
步骤S203,所述MQTT主题管理服务器在对所述控制节点认证后,将所述随机主题发送至所述控制节点,以便所述控制节点与受控节点通过所述随机主题进行MQTT协议通信。
在一个示例性实施例中,所述MQTT主题管理服务器接收所述受控节点通过HTTP的POST方法上报的所述第一消息。
在一个示例性实施例中,所述MQTT主题管理服务器调用随机字符串生成器,生成第一随机字符串作为所述随机主题,并缓存所述受控节点的设备ID与所述第一随机字符串的映射;所述MQTT主题管理服务器将所述第一随机字符串返回至所述受控节点。
在一个示例性实施例中,在所述MQTT主题管理服务器将所述第一随机字符串返回至所述受控节点之后,还包括:所述MQTT主题管理服务器向MQTT代理服务器发送第一订阅消息,其中,所述第一订阅消息中的订阅主题为遗嘱主题,所述遗嘱主题包含所述第一随机字符串和固定后缀。
在一个示例性实施例中,所述MQTT主题管理服务器将所述第一随机字符串返回至所述受控节点之后,还包括:所述受控节点向所述MQTT代理服务器发送MQTT连接消息,其中,所述MQTT连接消息中的遗嘱主题包含所述第一随机字符串和固定后缀。
在一个示例性实施例中,所述方法还包括:所述受控节点MQTT连接成功后,向所述MQTT代理服务器发送第二订阅消息,所述第二订阅消息中的订阅主题为所述第一随机字符串。
在一个示例性实施例中,所述MQTT主题管理服务器将所述随机主题发送至控制节点之前,还包括:MQTT主题管理服务器接收所述控制节点通过HTTP的POST方式上报的认证消息,所述认证消息中包括所述控制节点认证需要的用户名和密码;所述MQTT主题管理服务器对所述控制节点发送第一回复消息,其中,在所述第一回复消息中设置Cookie作为认证的标记;所述MQTT主题管理服务器接收所述控制节点发送的第二消息,其中,所述第二消息中包含所述受控节点的设备ID以及所述返回的Cookie;所述MQTT主题管理服务器根据所述第二消息中Cookie确认发消息的节点为所述控制节点,并根据消息中的设备ID,在缓存的设备ID与第一随机字符串的映射中查找所述第一随机字符串.并生成第二随机字符串,并将所述第一随机字符串和第二随机字符串返回给所述控制节点。
在一个示例性实施例中,将所述第一随机字符串和第二随机字符串返回给所述控制节点之后,还包括:所述控制节点发送第三订阅消息给所述MQTT代理服务器,其中,所述第三订阅消息中的订阅的主题为所述第二随机字符串;所述控制节点收到所述MQTT代理服务器订阅成功的回复后,发送第一发布消息给所述MQTT代理服务器,所述第一发布消息的MQTT主题为所述第一随机字符串,消息内容包括管理消息和第二随机字符串。
在一个示例性实施例中,所述MQTT代理服务器收到所述第一发布消息之后,还包括:所述MQTT代理服务器将所述第一发布消息转发给所述受控节点;所述受控节点根据所述第一发布消息执行完管理消息后,发送第二发布消息给所述MQTT代理服务器,其中,所述第二发布消息的MQTT主题为所述第二随机字符串,消息内容为所述管理消息的回复;所述MQTT代理服务器接收到所述第二发布消息后,基于所述MQTT主题为第二随机字符串,将所述第二发布消息转发给所述控制节点。
在一个示例性实施例中,所述方法还包括:所述MQTT代理服务器发现所述受控节点离线,则向所有订阅所述遗嘱主题的节点发送第三发布消息,所述第三发布消息的消息内容为所述受控节点离线。
在一个示例性实施例中,所述方法还包括:所述MQTT主题管理服务器接收到所述第三MQTT发布消息后,根据随机主题删除缓存的所述受控节点的设备ID与第一随机字符串的映射。
在一个示例性实施例中,所述方法还包括:MQTT主题管理服务器接收所述控制节点通过HTTP的POST方式上报的认证消息,所述认证消息中包括所述控制节点认证需要的用户名和密码;所述MQTT主题管理服务器对所述控制节点发送第一回复消息,其中,在所述第一回复消息中设置Cookie作为认证的标记;所述MQTT主题管理服务器接收所述控制节点发送的第二消息,其中,所述第二消息中包含所述受控节点的设备ID以及所述返回的Cookie;所述MQTT主题管理服务器根据所述第二消息中Cookie确认发消息的节点为所述控制节点,并根据消息中的设备ID,在缓存的设备ID与第一随机字符串的映射中查找所述第一随机字符串,如果未能找到,则发送第二回复消息至所述控制节点,其中,所述第二回复消息的内容为未能找到所述受控节点。
在一个示例性实施例中,所述MQTT主题管理服务器发送所述第二回复消息至所述控制节点之后,还包括:所述控制节点根据接收到的所述第二回复消息,发现所述受控节点已离线,则放弃此次对受控节点的管理。
在本发明的上述实施例中,通过MQTT主题管理服务器来管理节点通信的MQTT主题,并通过将MQTT主题随机化,使得恶意网络节点无法侦听或干扰到节点通信,从而达到提高MQTT协议网络的节点间通信安全的效果。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到根据上述实施例的方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本发明各个实施例所述的方法。
在本实施例中还提供了一种MQTT主题管理服务器和受控节点,用于实现上述实施例及优选实施方式,已经进行过说明的不再赘述。如以下所使用的,术语“模块”可以实现预定功能的软件和/或硬件的组合。尽管以下实施例所描述的装置较佳地以软件来实现,但是硬件,或者软件和硬件的组合的实现也是可能并被构想的。
图3是根据本发明实施例的MQTT主题管理服务器的结构框图,如图3所示,该MQTT主题管理服务器100包括第一接收模块10、生成模块20和认证模块30。
第一接收模块10,设置为接收受控节点上报的第一消息,其中,所述第一消息中包括所述受控节点的设备ID。
生成模块20,设置为生成对应于所述受控节点的设备ID的随机主题,并将所述随机主题返回至所述受控节点。
认证模块30,设置为在对所述控制节点认证后,将所述随机主题发送至所述控制节点,以便所述控制节点与受控节点通过所述随机主题进行MQTT协议通信。
图4是根据本发明实施例的受控节点的结构框图,如图4所示,该受控节点200包括发送模块40、第二接收模块50和通信模块60。
发送模块40,设置为向所述MQTT主题管理服务器上报第一消息,其中,所述第一消息 中包括所述受控节点的设备ID。
第二接收模块50,设置为接收所述MQTT主题管理服务器生成的对应于所述受控节点的设备ID的随机主题。
通信模块60,设置为在控制节点通过所述MQTT主题管理服务器的认证,并从所述MQTT主题管理服务器获得所述随机主题之后,通过所述随机主题与所述控制节点进行MQTT协议通信。
需要说明的是,上述各个模块是可以通过软件或硬件来实现的,对于后者,可以通过以下方式实现,但不限于此:上述模块均位于同一处理器中;或者,上述各个模块以任意组合的形式分别位于不同的处理器中。
为了便于对本发明所提供的技术方案的理解,下面将结合具体应用场景的实施例进行详细描述:
实施例1
本实施例提供了一种基于MQTT协议的设备通信方法,在本实施例中,受控节点接入MQTT网络,并由控制节点管理。如图5所示,本实施的方法包括如下步骤:
步骤S501,受控节点发送HTTP POST消息(消息1)给MQTT主题管理服务器。此消息中包含节点设备ID。
步骤S502,MQTT主题管理服务器收到消息1后,调用随机字符串生成器,生成随机字符串1,并缓存设备ID与随机字符串1的映射。并将随机字符串1作为消息1的回复返回给受控节点。
步骤S503,MQTT主题管理服务器随后向MQTT代理服务器发送MQTT Subscribe消息(消息2),订阅主题为:随机字符串1+“Last Will”。例如,如果随机字符串为:random String,则订阅主题为:random String Last Will。
步骤S504,受控节点收到消息1的回复,向MQTT代理服务器发送MQTT CONNECT消息(消息3),并设置CONNECT消息中Will Topic为随机字符串1+“Last Will”,Will Message为“offline”。
步骤S505,受控节点MQTT连接成功后,向MQTT代理服务器发送MQTT Subscribe消息(消息4),订阅主题为:随机字符串1。
步骤S506,控制节点接入网络,发送HTTP POST消息(消息5)给MQTT主题管理服务器,消息内容为控制节点认证需要的用户名/密码。MQTT主题管理服务器收到消息5,认证用户名/密码后,在消息5的回复中设置Cookie,作为认证的标记。
步骤S507,控制节点需要与受控节点建立连接,进行管理。首先控制节点发送HTTP POST消息(消息6)给MQTT主题管理服务器,消息内容包含受控节点的设备ID、以及消息5中返回的Cookie。
步骤S508,MQTT主题管理服务器收到消息6,根据消息中Cookie认可发消息的节点为控制节点,随即根据消息中的设备ID,在自身服务器中的设备ID与随机字符串1的映射中查找对应的随机字符串1,同时生成随机字符串2。并将随机字符串1和随机字符串2作为消息6的回复返回给控制节点。
步骤S509,控制节点发送MQTT Subscribe消息(消息7)给MQTT代理服务器,订阅的 主题为随机字符串2。
步骤S510,收到MQTT代理服务器订阅成功的回复后,控制节点发送MQTT Publish消息给MQTT代理服务器(消息8),此消息的MQTT主题为随机字符串1,消息内容为管理消息+随机字符串2。MQTT代理服务器收到消息8,因为MQTT主题为随机字符串1,故根据MQTT协议功能,会将此消息转发给受控节点。
步骤S511,受控节点收到消息8,执行完管理消息后。发送Publish消息给MQTT代理服务器(消息9),此消息的MQTT主题为随机字符串2,消息内容为管理消息的回复。
步骤S512,MQTT代理服务器收到消息9,因为MQTT主题为随机字符串2,故根据MQTT协议功能,会将此消息转发给控制节点。控制节点收到消息9,完成了管理消息的收发。
本实施例中的消息示例如表1所示:
表1
Figure PCTCN2022135911-appb-000001
Figure PCTCN2022135911-appb-000002
实施例2
本实施例还提供了一种基于MQTT协议的设备通信方法。与实施例1的不同之处在于,在本实施例中,受控节点离线,控制节点无法管理受控节点。
在本实施例中,各节点的初始状态位于实施例1中的步骤S506与步骤S507之间的状态,此时受控节点和控制节点均已初始化完成,但是控制节点尚未开始连接受控节点。
如图6所示,本实施例的方法主要包括如下步骤:
步骤S601,受控节点离线,根据MQTT协议,MQTT代理服务器发现受控节点的连接断开,向所有订阅随机字符串1+“LastWill”主题的节点发送MQTT Publish消息(消息1),消息内容为“offline”。
步骤S602,因MQTT主题管理服务器在受控节点随机主题过程中订阅过随机字符串1+“LastWill”主题,所以MQTT主题管理服务器会收到消息1。随机MQTT主题管理服务器根据随机主题1,删除设备ID与随机字符串1的映射关系。
步骤S603,控制节点与受控节点建立连接,进行管理。控制节点发送HTTP POST消息(消息2)给MQTT主题管理服务器,消息内容包含受控节点的设备ID、以及认证的Cookie。
步骤S604,MQTT主题管理服务器收到消息2,根据消息中Cookie认可发消息的节点为控制节点,随即根据消息中的设备ID,在自身服务器中的设备ID与随机字符串1的映射中查找对应的随机字符串1,但是未能找到。随即回复消息2,消息内容为:未找到设备。
步骤S605,控制节点收到消息2的回复,发现受控节点已离线,随即放弃此次管理。
本实施例中的消息示例如表2所示:
表2
Figure PCTCN2022135911-appb-000003
本发明的上述实施例,在MQTT协议网络的基础上,拓展了一种点对点的安全通信方案,解决了物联网设备在MQTT网络中由于配置管理/信息收集等原因产生的点对点安全通信的需求。
本发明的实施例还提供了一种计算机可读存储介质,该计算机可读存储介质中存储有计算机程序,其中,该计算机程序被设置为运行时执行上述任一项方法实施例中的步骤。
在一个示例性实施例中,上述计算机可读存储介质可以包括但不限于:U盘、只读存储器(Read-Only Memory,简称为ROM)、随机存取存储器(Random Access Memory,简称为RAM)、 移动硬盘、磁碟或者光盘等各种可以存储计算机程序的介质。
本发明的实施例还提供了一种电子装置,包括存储器和处理器,该存储器中存储有计算机程序,该处理器被设置为运行计算机程序以执行上述任一项方法实施例中的步骤。
在一个示例性实施例中,上述电子装置还可以包括传输设备以及输入输出设备,其中,该传输设备和上述处理器连接,该输入输出设备和上述处理器连接。
本实施例中的具体示例可以参考上述实施例及示例性实施方式中所描述的示例,本实施例在此不再赘述。
显然,本领域的技术人员应该明白,上述的本发明的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本发明不限制于任何特定的硬件和软件结合。
以上所述仅为本发明的优选实施例而已,并不用于限制本发明,对于本领域的技术人员来说,本发明可以有各种更改和变化。凡在本发明的原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。

Claims (18)

  1. 一种基于MQTT协议的设备通信方法,应用于MQTT主题管理服务器,包括:
    接收受控节点上报的第一消息,其中,所述第一消息中包括所述受控节点的设备ID;
    生成对应于所述受控节点的设备ID的随机主题,并将所述随机主题返回至所述受控节点;
    在对控制节点认证后,将所述随机主题发送至所述控制节点,以便所述控制节点与受控节点通过所述随机主题进行MQTT协议通信。
  2. 根据权利要求1所述的方法,其中,MQTT主题管理服务器接收受控节点上报的第一消息包括:
    所述MQTT主题管理服务器接收所述受控节点通过HTTP的POST方法上报的所述第一消息。
  3. 根据权利要求1所述的方法,其中,所述MQTT主题管理服务器生成对应于所述受控节点的设备ID的随机主题,并将所述随机主题返回至所述受控节点,包括:
    所述MQTT主题管理服务器调用随机字符串生成器,生成第一随机字符串作为所述随机主题,并缓存所述受控节点的设备ID与所述第一随机字符串的映射;
    所述MQTT主题管理服务器将所述第一随机字符串返回至所述受控节点。
  4. 根据权利要求3所述的方法,其中,在所述MQTT主题管理服务器将所述第一随机字符串返回至所述受控节点之后,还包括:
    所述MQTT主题管理服务器向MQTT代理服务器发送第一订阅消息,其中,所述第一订阅消息中的订阅主题为遗嘱主题,所述遗嘱主题包含所述第一随机字符串和固定后缀。
  5. 根据权利要求4所述的方法,其中,所述MQTT主题管理服务器将所述第一随机字符串返回至所述受控节点之后,还包括:
    所述受控节点向所述MQTT代理服务器发送MQTT连接消息,其中,所述MQTT连接消息中的遗嘱主题包含所述第一随机字符串和固定后缀。
  6. 根据权利要求5所述的方法,还包括:
    所述受控节点MQTT连接成功后,向所述MQTT代理服务器发送第二订阅消息,所述第二订阅消息中的订阅主题为所述第一随机字符串。
  7. 根据权利要求3所述的方法,其中,所述MQTT主题管理服务器将所述随机主题发送至控制节点之前,还包括:
    MQTT主题管理服务器接收所述控制节点通过HTTP的POST方式上报的认证消息,所述认证消息中包括所述控制节点认证需要的用户名和密码;
    所述MQTT主题管理服务器对所述控制节点发送第一回复消息,其中,在所述第一回复消息中设置Cookie作为认证的标记;
    所述MQTT主题管理服务器接收所述控制节点发送的第二消息,其中,所述第二消息中包 含所述受控节点的设备ID以及所述返回的Cookie;
    所述MQTT主题管理服务器根据所述第二消息中Cookie确认发消息的节点为所述控制节点,并根据消息中的设备ID,在缓存的设备ID与第一随机字符串的映射中查找所述第一随机字符串.并生成第二随机字符串,并将所述第一随机字符串和第二随机字符串返回给所述控制节点。
  8. 根据权利要求7所述的方法,其中,将所述第一随机字符串和第二随机字符串返回给所述控制节点之后,还包括:
    所述控制节点发送第三订阅消息给所述MQTT代理服务器,其中,所述第三订阅消息中的订阅的主题为所述第二随机字符串;
    所述控制节点收到所述MQTT代理服务器订阅成功的回复后,发送第一发布消息给所述MQTT代理服务器,所述第一发布消息的MQTT主题为所述第一随机字符串,消息内容包括管理消息和第二随机字符串。
  9. 根据权利要求8所述的方法,其中,所述MQTT代理服务器收到所述第一发布消息之后,还包括:
    所述MQTT代理服务器将所述第一发布消息转发给所述受控节点;
    所述受控节点根据所述第一发布消息执行完管理消息后,发送第二发布消息给所述MQTT代理服务器,其中,所述第二发布消息的MQTT主题为所述第二随机字符串,消息内容为所述管理消息的回复;
    所述MQTT代理服务器接收到所述第二发布消息后,基于所述MQTT主题为第二随机字符串,将所述第二发布消息转发给所述控制节点。
  10. 根据权利要求6所述的方法,还包括:
    所述MQTT代理服务器发现所述受控节点离线,则向所有订阅所述遗嘱主题的节点发送第三发布消息,所述第三发布消息的消息内容为所述受控节点离线。
  11. 根据权利要求10所述的方法,还包括:
    所述MQTT主题管理服务器接收到所述第三发布消息后,根据随机主题删除缓存的所述受控节点的设备ID与第一随机字符串的映射。
  12. 根据权利要求11所述的方法,还包括:
    MQTT主题管理服务器接收所述控制节点通过HTTP的POST方式上报的认证消息,所述认证消息中包括所述控制节点认证需要的用户名和密码;
    所述MQTT主题管理服务器对所述控制节点发送第一回复消息,其中,在所述第一回复消息中设置Cookie作为认证的标记;
    所述MQTT主题管理服务器接收所述控制节点发送的第二消息,其中,所述第二消息中包含所述受控节点的设备ID以及所述返回的Cookie;
    所述MQTT主题管理服务器根据所述第二消息中Cookie确认发消息的节点为所述控制节点,并根据消息中的设备ID,在缓存的设备ID与第一随机字符串的映射中查找所述第一随机字符串,如果未能找到,则发送第二回复消息至所述控制节点,其中,所述第二回复消息的内容为未能找到所述受控节点。
  13. 根据权利要求12所述的方法,其中,所述MQTT主题管理服务器发送所述第二回复消息至所述控制节点之后,还包括:
    所述控制节点根据接收到的所述第二回复消息,发现所述受控节点已离线,则放弃此次对受控节点的管理。
  14. 一种基于MQTT协议的设备通信方法,应用于受控节点,包括:
    向所述MQTT主题管理服务器上报第一消息,其中,所述第一消息中包括所述受控节点的设备ID;
    接收所述MQTT主题管理服务器生成的对应于所述受控节点的设备ID的随机主题;
    在控制节点通过所述MQTT主题管理服务器的认证,并从所述MQTT主题管理服务器获得所述随机主题之后,所述受控节点与控制节点通过所述随机主题进行MQTT协议通信。
  15. 一种MQTT主题管理服务器,包括:
    第一接收模块,设置为接收受控节点上报的第一消息,其中,所述第一消息中包括所述受控节点的设备ID;
    生成模块,设置为生成对应于所述受控节点的设备ID的随机主题,并将所述随机主题返回至所述受控节点;
    认证模块,设置为在对所述控制节点认证后,将所述随机主题发送至所述控制节点,以便所述控制节点与受控节点通过所述随机主题进行MQTT协议通信。
  16. 一种受控节点,包括:
    发送模块,设置为向所述MQTT主题管理服务器上报第一消息,其中,所述第一消息中包括所述受控节点的设备ID;
    第二接收模块,设置为接收所述MQTT主题管理服务器生成的对应于所述受控节点的设备ID的随机主题;
    通信模块,设置为在控制节点通过所述MQTT主题管理服务器的认证,并从所述MQTT主题管理服务器获得所述随机主题之后,通过所述随机主题与所述控制节点进行MQTT协议通信。
  17. 一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机程序,其中,所述计算机程序被处理器执行时实现所述权利要求1至13任一项中所述的方法的步骤。
  18. 一种电子装置,包括存储器、处理器以及存储在所述存储器上并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现所述权利要求1至13任一项中所述的方法的步骤。
PCT/CN2022/135911 2021-12-02 2022-12-01 基于mqtt协议的设备通信方法及装置 WO2023098816A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111467757.8 2021-12-02
CN202111467757.8A CN116232616A (zh) 2021-12-02 2021-12-02 基于mqtt协议的设备通信方法及装置

Publications (1)

Publication Number Publication Date
WO2023098816A1 true WO2023098816A1 (zh) 2023-06-08

Family

ID=86583009

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/135911 WO2023098816A1 (zh) 2021-12-02 2022-12-01 基于mqtt协议的设备通信方法及装置

Country Status (2)

Country Link
CN (1) CN116232616A (zh)
WO (1) WO2023098816A1 (zh)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104980920A (zh) * 2015-05-20 2015-10-14 小米科技有限责任公司 智能终端建立通信连接的方法及装置
CN108965447A (zh) * 2018-07-27 2018-12-07 四川爱创科技有限公司 数据采集和远程控制的方法及系统
KR102093314B1 (ko) * 2018-11-05 2020-03-25 유비라커산업(주) Mqtt 프로토콜을 이용한 메시지 전달 시스템 및 그의 메시지 전달 방법
CN111274268A (zh) * 2020-01-15 2020-06-12 平安科技(深圳)有限公司 物联网数据传输方法、装置、介质及电子设备
CN112787979A (zh) * 2019-11-07 2021-05-11 北京地平线机器人技术研发有限公司 物联网设备访问控制方法及物联网设备访问控制装置

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104980920A (zh) * 2015-05-20 2015-10-14 小米科技有限责任公司 智能终端建立通信连接的方法及装置
CN108965447A (zh) * 2018-07-27 2018-12-07 四川爱创科技有限公司 数据采集和远程控制的方法及系统
KR102093314B1 (ko) * 2018-11-05 2020-03-25 유비라커산업(주) Mqtt 프로토콜을 이용한 메시지 전달 시스템 및 그의 메시지 전달 방법
CN112787979A (zh) * 2019-11-07 2021-05-11 北京地平线机器人技术研发有限公司 物联网设备访问控制方法及物联网设备访问控制装置
CN111274268A (zh) * 2020-01-15 2020-06-12 平安科技(深圳)有限公司 物联网数据传输方法、装置、介质及电子设备

Also Published As

Publication number Publication date
CN116232616A (zh) 2023-06-06

Similar Documents

Publication Publication Date Title
US9866556B2 (en) Common internet file system proxy authentication of multiple servers
US9356928B2 (en) Mechanisms to use network session identifiers for software-as-a-service authentication
US11394703B2 (en) Methods for facilitating federated single sign-on (SSO) for internal web applications and devices thereof
RU2580097C2 (ru) Способ и система для надежного туннелирования протокола по нттр
US20180007144A1 (en) Event queuing and distribution system
US8332626B2 (en) Method and apparatus for authentication token-based service redirection
EP2129081A1 (en) SIP network-based content sharing method and system
KR20090074021A (ko) 피어 투 피어 네트워크에 캐싱되어 있는 데이터를 안전하게리트리브 및 제공하기 위한 방법, 피어 투 피어 네트워크에서 데이터를 캐싱하기 위한 방법, 컴퓨터 판독 가능 매체 및 컴퓨터 제어되는 장치
US10846658B2 (en) Establishing a communication event
US8793383B2 (en) Transparent transfer of a two-way communication
WO2015172629A1 (zh) 一种消息传输的方法、装置及系统
JP2018101424A (ja) ダイレクト電子メール
Ramachandran et al. Authenticated out-of-band communication over social links
US9979722B2 (en) Method and apparatus for processing a RTCWEB authentication
WO2023098816A1 (zh) 基于mqtt协议的设备通信方法及装置
US20060031418A1 (en) Authenticating client-to-client communication
EP3031196B1 (en) Mirror presence between websites
Werner Peer-to-peer networking using open web technologies
WO2014101388A1 (zh) 传送附件的方法、装置及系统
Skvortsov et al. Backplane Identity Scenario
WO2006015050A2 (en) Authenticating client-to-client communication

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22900620

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

ENP Entry into the national phase

Ref document number: 2022900620

Country of ref document: EP

Effective date: 20240702