Detailed Description
The following embodiments of the present application are described by specific examples, and other advantages and effects of the present application will be readily apparent to those skilled in the art from the disclosure of the present application. The present application is capable of other and different embodiments and its several details are capable of modifications and/or changes in various respects, all without departing from the spirit of the present application. It is to be noted that the features in the following embodiments and examples may be combined with each other without conflict.
As used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context indicates otherwise. It will be further understood that the terms "comprises," "comprising," and/or "comprising," when used in this specification, specify the presence of stated features, operations, elements, components, items, species, and/or groups, but do not preclude the presence, or addition of one or more other features, operations, elements, components, items, species, and/or groups thereof. The terms "or" and/or "as used herein are to be construed as inclusive or meaning any one or any combination. Thus, "A, B or C" or "A, B and/or C" means "either: a; b; c; a and B; a and C; b and C; A. b and C ". An exception to this definition will occur only when a combination of elements, functions or operations are inherently mutually exclusive in some way.
In order to solve the problems in the background art, the invention provides an MQTT topic subscription method, device, terminal and medium based on an awakening channel, when an SDK client and an APP do not interact within a set time, the connection between the SDK client and the MQTT is released, meanwhile, the SDK client and a cloud are kept in long connection to be used as the channel for awakening the SDK client by the APP, so that the reasonable utilization of MQTT connection resources is greatly increased, the subscription of the MQTT topic when messages are issued is greatly improved, the subscription is cancelled when no messages are issued, and the waste problem of memory and CPU resources is effectively reduced.
In order to make the objects, technical solutions and advantages of the present invention more apparent, the technical solutions in the embodiments of the present invention are further described in detail by the following embodiments in conjunction with the accompanying drawings. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Before the present invention is explained in further detail, terms and expressions referred to in the embodiments of the present invention are explained, and the terms and expressions referred to in the embodiments of the present invention are applicable to the following explanations:
<1> < SDK (Software Development Kit): the software development kit is a set of development tools for creating application software, such as a software package, a software framework, a hardware platform, and an operating system.
<2> MQTT (Message Queuing Telemetry Transport): the message queue telemetering transmission protocol is a communication protocol based on a publish/subscribe mode, is constructed on a TCP/IP protocol, and can provide real-time and reliable message service for a connected remote device with few codes and limited bandwidth.
<3> -WebSocket: the WebSocket communication protocol can enable data exchange between a client and a server to be simpler, and allows the server to actively push data to the client; in WebSocketAPI, the browser and the server only need to complete one handshake, and persistent connection can be directly established between the browser and the server, and bidirectional data transmission is carried out.
The embodiment of the invention provides an MQTT topic subscription method based on a wake-up channel, a system of the MQTT topic subscription method based on the wake-up channel and a storage medium storing an executable program for realizing the MQTT topic subscription method based on the wake-up channel. With respect to implementation of the MQTT topic subscription method based on the wake-up channel, the embodiment of the present invention will describe an exemplary implementation scenario of MQTT topic subscription based on the wake-up channel.
Fig. 1 shows a schematic structural diagram of an MQTT topic subscription system based on a wake-up channel in an embodiment of the present invention. The MQTT topic subscription system 100 based on the wake-up channel in this embodiment includes an SDK end 101, an MQTT end 102, a cloud service end 103, and an APP end 104.
In this embodiment, the connection between the SDK terminal 101 and the MQTT terminal 102 is disconnected based on a resource configuration policy; constructing a wake-up channel for the APP end 104 to wake up the SDK end through the cloud server 103; after waking up the corresponding SDK terminal 101 based on the wake-up mechanism, the woken-up SDK terminal 101 disconnects the wake-up channel and notifies the cloud service terminal 103 of the online information after reestablishing the connection with the MQTT terminal 102, so that the cloud service terminal 103 searches for the corresponding APP terminal 104 and notifies the APP terminal 104 of the topic of the release message; after receiving the topic of the release message, the APP terminal 104 subscribes to the corresponding topic to the MQTT terminal 102.
In some examples of this embodiment, the disconnecting the SDK peer and the MQTT peer based on the resource configuration policy includes: and if the SDK end and the MQTT end do not interact within the preset reasonable time period of resource configuration, disconnecting the connection between the SDK end and the MQTT end.
It should be noted that the preset reasonable time period for resource allocation can be set correspondingly according to the actual application scenario, and the time period is mainly used for describing and identifying the idle state of the SDK terminal. Namely: if the SDK end does not interact with the MQTT end within the reasonable time period of resource configuration, the current SDK end is in an idle state, otherwise, the current SDK end is in a busy state. Further, the interaction mode between the SDK terminal and the MQTT terminal includes, but is not limited to, the SDK terminal sending data to the MQTT terminal and/or the MQTT terminal sending instructions to the SDK terminal.
In some examples of this embodiment, the constructing, by the cloud service end, an awake channel for the APP end to awake the SDK end includes: after the connection between the SDK end and the MQTT end is disconnected, a Socket long connection is established between the SDK end and the cloud service end to be used as a wake-up channel for the APP end to wake up the corresponding SDK end; and the awakened SDK end disconnects the awakening channel by disconnecting the Socket long connection with the cloud service end.
It should be noted that WebSocket is a protocol provided by HTML5 for performing full-duplex communication on a single TCP connection; in the WebSocket API, a browser and a server only need to perform a handshake action, and then a fast channel is formed between the browser and the server, so that data can be directly transmitted between the browser and the server. The existing push technology of many websites uses Ajax polling, where polling refers to sending an HTTP request to a server by a browser at a specific time interval (e.g. every 1 second), and then returning the latest data to the browser of a client by the server, and the polling mode has a disadvantage that the browser needs to continuously send a request to the server, however, the HTTP request may contain a long header, and the really valid data may be only a small part, which may cause a large waste of bandwidth resources, so that the long connection established by WebSocket well overcomes the problem of waste of bandwidth resources and can communicate in real time.
In this embodiment, any one of the following manners may be used to ensure a Socket long connection between the SDK side and the cloud server side:
in the method 1), the cloud service end can send a short and bold data packet to the SDK end at regular time in a Timer event, and then start a low-level thread, and continuously detect the response of the SDK end in the thread. If the response of the SDK end is not received within a certain time, the SDK end is considered to be disconnected; in the same way, if the SDK end does not receive the heartbeat packet of the cloud service end within a certain time, the connection is considered to be unavailable.
Mode 2) ensures Socket long connection between the SDK end and the cloud service end by using a KeepAlive keep-alive mechanism of TCP. One of the SDK end and the cloud service end can automatically reply after receiving the heartbeat packet so as to tell the other side that the other side is still on line.
In some examples of this embodiment, the waking up the corresponding SDK terminal based on the wake-up mechanism includes: and the cloud server receives an https request which contains the physical address information of the object requested to be woken up and is transmitted after certificate encryption, symmetric encryption or asymmetric encryption from the APP terminal, and searches for and awakens the corresponding SDK terminal according to the physical address information of the object requested to be woken up.
It should be understood that the wake-up request is essentially an https request. The https request is an application layer protocol and is an encrypted transmission, and the encryption process may use a certificate encryption algorithm, a symmetric encryption algorithm, or an asymmetric encryption algorithm, for encryption. The certificate encryption algorithm means that a server needs to go to a certificate issuing organization to apply for a certificate of the server before the server uses the certificate for encryption, the server side sends the certificate of the server to a client side in the request process of HTTPS, and the client side carries out certificate verification so as to verify the identity of the server. The symmetric encryption algorithm is used for encrypting and decrypting by using the same private key in the encryption and decryption processes, and the private key cannot be leaked due to the fact that the symmetric encryption algorithm is public. The asymmetric encryption algorithm means that different secret keys are used in the encryption and decryption processes, a public key is disclosed to the outside, and a private key is only owned by a decryption end.
In some examples of this embodiment, the APP terminal subscribes to the MQTT terminal for a corresponding topic and cancels the subscription for the topic after the message reception is completed, so as to achieve the purpose of releasing memory and CPU resources.
For the sake of understanding, the following will make a detailed explanation on the operation principle of the MQTT topic subscription system based on wake-up channel provided in this embodiment with reference to the flowchart shown in fig. 2.
Step S21: if the SDK terminal 101 does not interact with the MQTT terminal 102 within a defined time period, the communication connection between the SDK terminal 101 and the MQTT terminal 102 is disconnected.
Step S22: after the SDK terminal 101 is disconnected from the MQTT terminal 102, a long connection is established with the cloud service terminal 103 through a WebSocket communication protocol.
Step S23: the APP end 104 initiates a wake-up request to the cloud server 103 according to the equipment owned by the current user.
It should be understood that the APP end in this embodiment may correspond to multiple types of devices, that is, multiple types of devices APP may be applied to the technical solution of the embodiment of the present invention, for example, a sweeping robot APP, a mower APP, or other intelligent robots APP, and the present embodiment is not limited.
Step S24: after receiving the wake-up request, the cloud server 103 forwards the wake-up request to the corresponding SDK terminal 101.
Specifically, the wake-up request sent from the APP terminal 104 to the cloud server 103 includes physical address information of a wake-up target, and the address of the device in the network is uniquely confirmed by the physical address. The physical address is also called a MAC address or a hardware address, and a MAC address is typically 48 bits (i.e., 6 bytes) in length and is represented as 12 16-ary numbers.
Step S25: after receiving the wake-up request, the SDK terminal 101 disconnects the long connection with the cloud service terminal 103.
It should be understood that, since the purpose of establishing the long connection between the SDK terminal 101 and the cloud service terminal 103 is a compensation mechanism for disconnecting the SDK terminal 101 and the MQTT terminal 102, in a state where the SDK terminal 101 and the cloud service terminal 103 establish the long connection, the APP terminal 104 may initiate a wake-up request to wake up the corresponding SDK terminal 101, so that the woken-up SDK terminal 101 establishes a connection with the MQTT terminal 102 again. Therefore, after the needed SDK terminal 101 is awakened, the long connection with the cloud service terminal 103 can be closed, so that bandwidth resources can be saved to the greatest extent, and the overall operation efficiency of the system is improved.
Step S26: after the long connection between the SDK terminal 101 and the cloud service terminal 103 is disconnected, the connection with the MQTT terminal 102 is completed and the connection is on-line.
Step S27: the MQTT terminal 102 notifies the cloud service terminal 103 of the online information of the SDK terminal 101.
Step S28: after receiving the online information, the cloud server 103 searches for a corresponding APP terminal 104 according to the MAC address of the SDK terminal 101, subscribes a related topic to the MQTT terminal 102, and notifies the APP terminal user of a published message topic.
Step S29: after receiving the published message topic, the APP terminal 104 subscribes to the MQTT102 for the corresponding topic, and cancels the subscription for the topic after the message reception is completed.
As can be seen from the above technical contents: according to the technical scheme provided by the embodiment of the invention, the connection between the SDK end and the MQTT end is disconnected, the WebSocket long connection is established between the SDK end and the cloud service end, the https request initiated by the APP end is sent to the cloud service end through the awakening mechanism, the corresponding SDK end is awakened through the cloud service end, the connection with the MQTT end is reestablished by the awakened SDK end, and the APP end is informed of the theme of the issued message through finding the APP terminal corresponding to the equipment, so that the theme subscription to the MQTT end is completed.
Therefore, the technical solution provided by the embodiment of the present invention is actually a comprehensive solution combining Socket long connection and MQTT topic subscription: the Socket long connection mode can ensure that both sides only need to keep one heartbeat connection and occupy less CPU and memory resources under the condition that the terminal equipment and the cloud end are not interacted; the MQTT topic subscription uses a publish/subscribe message mode to provide one-to-many message publishing and release application program coupling; socket long connection can greatly play a role in utilization of idle resources, MQTT can play a unique advantage in development of protocols, and both can take the length of Socket long connection and the length of Socket short connection, so that the resources of the embodiment of the invention can be utilized to the maximum extent.
Fig. 3 shows a schematic flow chart of an MQTT topic subscription method based on a wake-up channel in the embodiment of the present invention. In this embodiment, the MQTT topic subscription method based on the wake-up channel is applied to the SDK terminal, and the method flow includes:
step S31: and disconnecting the connection with the MQTT terminal based on the resource configuration strategy.
Step S32: and a wake-up channel for waking up the APP end is formed between the cloud server end and the APP end.
Step S33: and after being awakened based on an awakening mechanism, disconnecting the awakening channel and notifying online information to the cloud service end after reestablishing the connection between the awakening channel and the MQTT end so that the cloud service end can search for the corresponding APP end and notify the APP end of the topic of the published message, and the APP end can subscribe the corresponding topic to the MQTT end after receiving the topic of the published message.
It should be noted that, the connection and disconnection between the SDK terminal and the MQTT terminal, and the establishment and disconnection of the long connection between the SDK terminal and the cloud service terminal may be implemented by one or the other of the two terminals. For example, the connection and disconnection between the SDK terminal and the MQTT terminal may be implemented by the SDK terminal, or may be implemented by the MQTT terminal, which is not limited in this embodiment.
The MQTT theme subscription method based on the wake-up channel provided in the embodiment of the present invention may be implemented by a terminal side or a server side, and as for a hardware structure of the MQTT theme subscription terminal based on the wake-up channel, please refer to fig. 4, which is an optional hardware structure diagram of the SDK terminal 400 provided in the embodiment of the present invention, the terminal 400 may be a mobile phone, a computer device, a tablet device, a personal digital processing device, a factory background processing device, and the like. The MQTT topic subscription terminal 400 based on the wake-up channel includes: at least one processor 401, memory 402, at least one network interface 404, and a user interface 406. The various components in the device are coupled together by a bus system 405. It will be appreciated that the bus system 405 is used to enable communications among the components connected. The bus system 405 includes a power bus, a control bus, and a status signal bus in addition to a data bus. But for the sake of clarity the various buses are labeled as bus systems in figure 4.
The user interface 406 may include, among other things, a display, a keyboard, a mouse, a trackball, a click gun, keys, buttons, a touch pad or touch screen.
It will be appreciated that the memory 402 can be either volatile memory or nonvolatile memory, and can include both volatile and nonvolatile memory. Among them, the nonvolatile Memory may be a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), which serves as an external cache. By way of example, and not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), synchronous Static Random Access Memory (SSRAM). The described memory for embodiments of the present invention is intended to comprise, without being limited to, these and any other suitable types of memory.
The memory 402 in the embodiment of the present invention is used for storing various kinds of data to support the operation of the MQTT theme subscriber terminal 400 based on the wake-up channel. Examples of such data include: any executable programs for operating on the wake-up channel based MQTT topic subscription terminal 400, such as the operating system 4021 and the application programs 4022; the operating system 4021 includes various system programs such as a framework layer, a core library layer, a driver layer, and the like for implementing various basic services and processing hardware-based tasks. The application 4022 may include various applications such as a media player (MediaPlayer), a Browser (Browser), and the like, for implementing various application services. The method for subscribing the MQTT theme based on the wake-up channel provided by the embodiment of the invention can be included in the application 4022.
The method disclosed in the above embodiments of the present invention may be applied to the processor 401, or implemented by the processor 401. The processor 401 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by instructions in the form of hardware integrated logic circuits or software in the processor 401. The Processor 401 described above may be a general purpose Processor, a Digital Signal Processor (DSP), or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. Processor 401 may implement or perform the methods, steps, and logic blocks disclosed in embodiments of the present invention. The general purpose processor 401 may be a microprocessor or any conventional processor or the like. The steps of the accessory optimization method provided by the embodiment of the invention can be directly embodied as the execution of a hardware decoding processor, or the combination of hardware and software modules in the decoding processor. The software modules may be located in a storage medium that is located in a memory and that is read by a processor to perform the steps of the method described above in connection with its hardware.
In an exemplary embodiment, the MQTT theme subscription terminal 400 based on the wake-up channel may be used by one or more Application Specific Integrated Circuits (ASICs), DSPs, programmable Logic Devices (PLDs), complex Programmable Logic Devices (CPLDs) for performing the aforementioned methods.
Fig. 5 shows a schematic flow chart of an MQTT topic subscription method based on a wake-up channel in the embodiment of the present invention. In this embodiment, the MQTT topic subscription method based on the wake-up channel is applied to a cloud server, and the method includes:
step S51: and a wake-up channel for waking up the APP terminal is formed between the SDK terminal and the APP terminal.
Step S52: and after receiving the awakening request from the APP terminal, awakening the corresponding SDK terminal based on the awakening mechanism, and disconnecting an awakening channel between the SDK terminal and the awakened SDK terminal.
Step S53: and receiving the online information of the awakened SDK terminal from the MQTT terminal, searching the corresponding APP terminal and informing the APP terminal of the topic of the release message so that the APP terminal subscribes the corresponding topic to the MQTT terminal after receiving the topic of the release message.
The MQTT theme subscription method based on the wake-up channel provided in the embodiment of the present invention may be implemented by a terminal side or a server side, and as for a hardware structure of the MQTT theme subscription terminal based on the wake-up channel, please refer to fig. 6, which is an optional hardware structure diagram of the cloud server 600 provided in the embodiment of the present invention, the terminal 600 may be a mobile phone, a computer device, a tablet device, a personal digital processing device, a factory background processing device, and the like. The MQTT theme subscription terminal 600 based on the wake-up channel includes: at least one processor 601, memory 602, at least one network interface 604, and a user interface 606. The various components of the device are coupled together by a bus system 605. It will be appreciated that the bus system 605 is used to enable connected communication between these components. The bus system 605 includes a power bus, a control bus, and a status signal bus in addition to a data bus. But for the sake of clarity the various buses are labeled as bus systems in figure 6.
The user interface 606 may include, among other things, a display, a keyboard, a mouse, a trackball, a click gun, keys, buttons, a touch pad, or a touch screen.
It will be appreciated that the memory 602 can be either volatile memory or nonvolatile memory, and can include both volatile and nonvolatile memory. Among them, the nonvolatile Memory may be a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), which serves as an external cache. By way of example, and not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), synchronous Static Random Access Memory (SSRAM). The described memory for embodiments of the present invention is intended to comprise, without being limited to, these and any other suitable types of memory.
The memory 602 in the embodiment of the present invention is used for storing various types of data to support the operation of the MQTT theme subscriber terminal 600 based on the wake-up channel. Examples of such data include: any executable programs for operating on the wake-up channel based MQTT topic subscription terminal 600, such as an operating system 6021 and application programs 6022; the operating system 6021 includes various system programs such as a framework layer, a core library layer, a driver layer, and the like for implementing various basic services and processing hardware-based tasks. The application programs 6022 may include various application programs such as a media player (MediaPlayer), a Browser (Browser), and the like for implementing various application services. The MQTT topic subscription method based on the wake-up channel provided by the embodiment of the invention can be included in the application program 6022.
The method disclosed by the above-mentioned embodiment of the present invention can be applied to the processor 601, or implemented by the processor 601. The processor 601 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 601. The Processor 601 may be a general purpose Processor, a Digital Signal Processor (DSP), or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. Processor 601 may implement or perform the methods, steps, and logic blocks disclosed in embodiments of the present invention. The general purpose processor 601 may be a microprocessor or any conventional processor or the like. The steps of the method for optimizing the accessories provided by the embodiment of the invention can be directly embodied as the execution of a hardware decoding processor, or the combination of hardware and software modules in the decoding processor. The software modules may be located in a storage medium having a memory and a processor reading the information in the memory and combining the hardware to perform the steps of the method.
In an exemplary embodiment, the MQTT theme subscription terminal 600 based on the wake-up channel may be used by one or more Application Specific Integrated Circuits (ASICs), DSPs, programmable Logic Devices (PLDs), complex Programmable Logic Devices (CPLDs) for performing the aforementioned methods.
The embodiment of the invention also provides a computer readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the computer program realizes the MQTT topic subscription method based on the wake-up channel and applied to the SDK end; or the MQTT topic subscription method based on the wake-up channel applied to the cloud service end is realized.
Those of ordinary skill in the art will understand that: all or part of the steps for implementing the above method embodiments may be performed by hardware associated with a computer program. The aforementioned computer program may be stored in a computer readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
In the embodiments provided herein, the computer-readable and/or writable storage medium may include read-only memory, random-access memory, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage or other magnetic storage devices, flash memory, U-disk, removable hard disk, or any other medium that can be used to store desired program code in the form of instructions or data structures and that can be accessed by a computer. Also, any connection is properly termed a computer-readable medium. For example, if the instructions are transmitted from a website, server, or other remote source using a coaxial cable, fiber optic cable, twisted pair, digital Subscriber Line (DSL), or wireless technologies such as infrared, radio, and microwave, then the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of medium. It should be understood, however, that computer-readable-writable storage media and data storage media do not include connections, carrier waves, signals, or other transitory media, but are intended to be non-transitory, tangible storage media. Disk and disc, as used in this application, includes Compact Disc (CD), laser disc, optical disc, digital Versatile Disc (DVD), floppy disk and blu-ray disc where disks usually reproduce data magnetically, while discs reproduce data optically with lasers.
In summary, the present application provides a method, an apparatus, a terminal and a medium for subscribing MQTT topics based on wake-up channels, and the present invention provides a method for improving the subscription efficiency of MQTT topics based on wake-up channels. Therefore, the application effectively overcomes various defects in the prior art and has high industrial utilization value.
The above embodiments are merely illustrative of the principles and utilities of the present application and are not intended to limit the application. Any person skilled in the art can modify or change the above-described embodiments without departing from the spirit and scope of the present application. Accordingly, it is intended that all equivalent modifications or changes which can be made by those skilled in the art without departing from the spirit and technical concepts disclosed in the present application shall be covered by the claims of the present application.