Detailed Description
Other advantages and effects of the present application will become apparent to those skilled in the art from the following disclosure, which describes the embodiments of the present application with reference to specific examples. The application may be practiced or carried out in other embodiments that depart from the specific details, and the details of the present description may be modified or varied from the spirit and scope of the present application. It should be noted that the following embodiments and features in the embodiments 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," "includes," and/or "including" specify the presence of stated features, operations, elements, components, items, categories, and/or groups, but do not preclude the presence, presence or addition of one or more other features, operations, elements, components, items, categories, and/or groups. 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 "any of the following: a, A is as follows; b, a step of preparing a composite material; c, performing operation; 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 in some way inherently mutually exclusive.
In order to solve the problems in the background art, the application provides a wake-up channel-based MQTT topic subscription method, a wake-up channel-based MQTT topic subscription device, a wake-up channel-based MQTT topic terminal and a wake-up channel-based medium, when an SDK client and an APP end do not interact in a set time, the connection between the SDK client and the MQTT is released, meanwhile, the SDK client and a cloud end are kept in long connection, and the wake-up channel of the SDK client is used as the APP end, so that the reasonable utilization of MQTT connection resources is greatly increased, the subscription of the MQTT topic is greatly improved when information is released, the subscription is canceled when no information is released, and the waste of memory and CPU resources is effectively reduced.
In order to make the objects, technical solutions and advantages of the present application more apparent, further detailed description of the technical solutions in the embodiments of the present application will be given by the following examples with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
Before explaining the present application in further detail, terms and terminology involved in the embodiments of the present application will be explained, and the terms and terminology involved in the embodiments of the present application are applicable to the following explanation:
<1> sdk (Software Development Kit): a software development kit is a collection of development tools when a software package, a software framework, a hardware platform, an operating system, etc., builds application software.
<2> mqtt (Message Queuing Telemetry Transport): the message queue telemetry transmission protocol is a communication protocol based on a publish/subscribe mode, is constructed on a TCP/IP protocol, and can provide real-time reliable message service for connecting remote equipment with little codes and limited bandwidth.
<3> websocket: the WebSocket communication protocol is a protocol for full duplex communication on a single TCP connection, so that data exchange between a client and a server can be simpler, and the server is allowed to actively push data to the client; in websocket api, the browser and the server only need to complete one handshake, and can directly create a persistent connection between the two and perform bidirectional data transmission.
The embodiment of the application 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 for storing an executable program for realizing the MQTT topic subscription method based on the wake-up channel. With respect to implementation of the wake channel-based MQTT theme subscription method, an exemplary implementation scenario of the wake channel-based MQTT theme subscription will be described in the embodiments of the present application.
As shown in fig. 1, a schematic structure diagram of an MQTT theme subscription system based on a wake-up channel in an embodiment of the present application is shown. The wake-channel-based MQTT theme subscription system 100 in this embodiment includes an SDK terminal 101, an MQTT terminal 102, a cloud service terminal 103, and an APP terminal 104.
In this embodiment, the connection between the SDK end 101 and the MQTT end 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 service end 103; after waking up the corresponding SDK terminal 101 based on the wake-up mechanism, the waken-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 the corresponding APP terminal 104 and notifies the APP terminal 104 of the subject of the release message; the APP end 104 subscribes to the MQTT end 102 for the corresponding topic after receiving the topic of the published message.
In some examples of this embodiment, the disconnecting the connection between the SDK end and the MQTT end based on the resource configuration policy includes: and if the SDK end and the MQTT end do not interact within the reasonable time of the preset resource allocation, disconnecting the connection between the SDK end and the MQTT end.
It should be noted that, the reasonable time-efficiency of the preset resource configuration can be set correspondingly according to the actual application scenario, and the time-efficiency is mainly used for describing and identifying the idle state of the SDK end. Namely: if the SDK terminal does not interact with the MQTT terminal within reasonable time of resource allocation, the SDK terminal is in an idle state, otherwise, the SDK terminal is in a busy state. Further, the interaction manner between the SDK end and the MQTT end includes, but is not limited to, that the SDK end sends data to the MQTT end and/or that the MQTT end sends instructions to the SDK end, etc.
In some examples of this embodiment, the constructing, by the cloud server, a wake channel for the APP end to wake up the SDK end includes: after the connection between the SDK end and the MQTT end is disconnected, establishing a Socket long connection 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; the awakened SDK end disconnects the awakening channel by disconnecting a Socket long connection with the cloud service end.
Note that WebSocket is a protocol provided by HTML5 for full duplex communication over a single TCP connection; in WebSocket API, the browser and the server only need to do a handshake, and then a fast channel is formed between the browser and the server, and data transfer can be directly performed between the two. The existing push technology of many websites uses Ajax polling, which refers to that at a specific time interval (for example, every 1 second), an HTTP request is sent to a server by a browser, and then the server returns the latest data to the browser of the client.
In this embodiment, any one of the following manners may be used to ensure a Socket long connection between the SDK end and the cloud service end:
mode 1) the cloud service end can send a short and small data packet to the SDK end at regular time in a Timer event, then starts a low-level thread, and continuously detects the response of the SDK end in the thread. If the response of the SDK terminal is not received within a certain time, the SDK terminal is considered to be disconnected; and similarly, 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) guarantees Socket long connection between the SDK end and the cloud service end by utilizing a 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 party that the other party is still online.
In some examples of this embodiment, waking up the corresponding SDK based on the wake mechanism includes: and the cloud service end receives an https request which contains the physical address information of the requested wake-up object from the APP end, transmits the https request after being encrypted by a certificate, symmetrically encrypted or asymmetrically encrypted, and searches and wakes up the corresponding SDK end according to the physical address information of the requested wake-up object.
It should be appreciated that the wake-up request is essentially an https request. https requests are an application layer protocol and are encrypted transmissions, and the encryption process may be encrypted using a certificate encryption algorithm, a symmetric encryption algorithm, or an asymmetric encryption algorithm, among others. The certificate encryption algorithm means that a server needs to go to a certificate issuing organization to apply for the certificate of the server before using the certificate encryption, the server side sends the certificate of the server to a client side in the HTTPS request process, and the client side performs certificate verification so as to verify the identity of the server. The symmetric encryption algorithm is that the same private key is used for encryption and decryption in the encryption and decryption process, and the private key cannot be leaked because the symmetric encryption algorithm is disclosed. The asymmetric encryption algorithm means that different 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 end subscribes to the corresponding theme from the MQTT end and cancels the subscription of the theme after the message reception is completed, so as to achieve the purpose of releasing the memory and the CPU resources.
For easy understanding, the operation principle of the MQTT theme subscription system based on the wake-up channel according to the present embodiment will be explained in detail with reference to the flowchart shown in fig. 2.
Step S21: if the SDK end 101 does not interact with the MQTT end 102 within the defined timeframe, the communication connection between the SDK end 101 and the MQTT end 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 device 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 application, for example, a sweeping robot APP, a mower APP, or other intelligent robots APP, which is not limited in this embodiment.
Step S24: after receiving the wake request, the cloud service end 103 forwards the wake request to the corresponding SDK end 101.
Specifically, the wake request sent from the APP end 104 to the cloud server 103 includes physical address information of the wake object, and the address of the device in the network is uniquely identified by the physical address. The physical address is also called a MAC address or a hardware address, and one MAC address is typically 48 bits (i.e., 6 bytes) in length, which is represented as 12 16 digits.
Step S25: the SDK terminal 101 disconnects the long connection with the cloud service terminal 103 after receiving the wake request.
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 to be a compensation mechanism for disconnecting the connection between the SDK terminal 101 and the MQTT terminal 102, in the state where the long connection between the SDK terminal 101 and the cloud service terminal 103 is established, the APP terminal 104 may initiate a wake-up request to wake up the corresponding SDK terminal 101, so that the awakened SDK terminal 101 may re-establish the connection with the MQTT terminal 102. Therefore, when 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 SDK end 101 disconnects the long connection with the cloud service end 103, the connection with the MQTT end 102 is completed and the connection is brought 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 service end 103 searches the corresponding APP terminal 104 according to the MAC address of the SDK end 101, subscribes to related topics from the MQTT end 102, and informs the APP terminal user of the topic of the published message.
Step S29: after receiving the topic of the published message, the APP terminal 104 subscribes to the corresponding topic from the MQTT102 and cancels the subscription of the topic after the message is received.
The technical content can be seen from the following: according to the technical scheme provided by the embodiment of the application, the connection between the SDK terminal and the MQTT terminal is disconnected, the WebSocket long connection is established between the SDK terminal and the cloud service terminal, the https request initiated by the APP terminal is sent to the cloud service terminal through the awakening mechanism, the corresponding SDK terminal is awakened through the cloud service terminal, the awakened SDK terminal reestablishes the connection with the MQTT terminal, and the APP terminal corresponding to the equipment is searched, so that the APP terminal is informed of the theme of the release message, and the theme subscription to the MQTT terminal is completed.
Therefore, the technical scheme provided by the embodiment of the application is a comprehensive scheme combining Socket long connection and MQTT topic subscription: the Socket long connection mode can only keep one heartbeat connection and occupy less CPU and memory resources under the condition that the terminal equipment and the cloud end do not interact; the MQTT theme subscription uses a publish/subscribe message mode to provide one-to-many message publication and decouple application programs; the Socket long connection can play a role in the utilization of idle resources, and the MQTT can play a unique advantage in the development of protocols, and the Socket long connection and the MQTT can supplement the short connection by taking the length of the Socket long connection and the short connection, so that the resources of the embodiment of the application can be utilized maximally.
Fig. 3 is a schematic flow chart of an MQTT theme subscription method based on a wake-up channel in an embodiment of the present application. The MQTT theme subscription method based on the wake-up channel in the embodiment is applied to the SDK end, and the method flow comprises the following steps:
step S31: the connection with the MQTT end is disconnected based on the resource allocation strategy.
Step S32: and a wake-up channel for the APP to wake up is formed between the APP and the cloud server.
Step S33: and after the awakening mechanism is awakened, disconnecting the awakening channel, and after the connection between the awakening channel and the MQTT end is reestablished, notifying the cloud service end of online information, so that the cloud service end searches a corresponding APP end and notifies the APP end of the topic of the release message, and the APP end subscribes the corresponding topic to the MQTT end after receiving the topic of the release message.
It should be noted that, the connection and disconnection between the SDK end and the MQTT end, and the connection and disconnection of the long connection between the SDK end and the cloud service end may be performed by one or the other of the two ends. For example, the connection and disconnection between the SDK terminal and the MQTT terminal may be implemented by the SDK terminal or by the MQTT terminal, which is not limited in this embodiment.
Referring to fig. 4, an optional hardware structure schematic diagram of an SDK terminal 400 provided by the embodiment of the application is shown, and the terminal 400 may be a mobile phone, a computer device, a tablet device, a personal digital processing device, a factory background processing device, etc. in terms of a hardware structure of the MQTT theme subscription terminal based on the wake-up channel, the MQTT theme subscription method based on the wake-up channel provided by the embodiment of the application may be implemented by a terminal side or a server side. The wake channel-based MQTT theme subscription terminal 400 includes: at least one processor 401, a 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 is understood that the bus system 405 is used to enable connected communications between these components. The bus system 405 includes a power bus, a control bus, and a status signal bus in addition to a data bus. But for clarity of illustration the various buses are labeled as bus systems in fig. 4.
The user interface 406 may include, among other things, a display, keyboard, mouse, trackball, click gun, keys, buttons, touch pad, or touch screen, etc.
It is to be appreciated that memory 402 can be either volatile memory or nonvolatile memory, and can include both volatile and nonvolatile memory. The nonvolatile Memory may be a Read Only Memory (ROM), a programmable Read Only Memory (PROM, programmable Read-Only Memory), which serves as an external cache, among others. By way of example, and not limitation, many forms of RAM are available, such as static random Access Memory (SRAM, staticRandom Access Memory), synchronous static random Access Memory (SSRAM, synchronous Static RandomAccess Memory). The memory described by embodiments of the present application is intended to comprise, without being limited to, these and any other suitable types of memory.
The memory 402 in embodiments of the present application is used to store various categories of data to support the operation of the wake channel based MQTT theme subscription terminal 400. Examples of such data include: any executable programs, such as an operating system 4021 and application programs 4022, for operating on the wake channel-based MQTT theme subscription terminal 400; the operating system 4021 contains 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 4022 may include various application programs such as a media player (MediaPlayer), a Browser (Browser), and the like for implementing various application services. The MQTT theme subscription method based on the wake-up channel provided by the embodiment of the present application may be included in the application 4022.
The method disclosed in the above embodiment of the present application 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 integrated logic circuits of hardware in the processor 401 or by instructions in the form of software. The processor 401 described above may be a general purpose processor, a digital signal processor (DSP, digital Signal Processor), 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 application. 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 application can be directly embodied as the execution completion of the hardware decoding processor or the execution completion of the hardware and software module combination execution in the decoding processor. The software modules may be located in a storage medium having memory and a processor reading information from the memory and performing the steps of the method in combination with hardware.
In an exemplary embodiment, the wake channel based MQTT theme subscription terminal 400 may be used by one or more application specific integrated circuits (ASICs, application Specific Integrated Circuit), DSPs, programmable logic devices (PLDs, programmable Logic Device), complex programmable logic devices (CPLDs, complex Programmable LogicDevice) to perform the aforementioned methods.
Fig. 5 shows a schematic flow chart of an MQTT theme subscription method based on a wake-up channel in an embodiment of the present application. The MQTT theme subscription method based on the wake-up channel is applied to the cloud server, and comprises the following steps:
step S51: and a wake-up channel for the APP to wake up is formed between the APP and the SDK.
Step S52: and after receiving the wake-up request from the APP terminal, waking up the corresponding SDK terminal based on a wake-up mechanism, and disconnecting a wake-up channel between the wake-up request and the awakened SDK terminal.
Step S53: and receiving the online information of the awakened SDK end from the MQTT end, searching a corresponding APP end, and informing the APP end of the topic of the release message so that the APP end subscribes to the corresponding topic from the MQTT end after receiving the topic of the release message.
Referring to fig. 6, an optional hardware structure schematic diagram of a cloud service end 600 provided by the embodiment of the application is shown, where 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 wake channel-based MQTT theme subscription terminal 600 includes: at least one processor 601, memory 602, at least one network interface 604, and a user interface 606. The various components in the device are coupled together by a bus system 605. It is to be appreciated that the bus system 605 is employed to enable connected communications 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 clarity of illustration the various buses are labeled as bus systems in fig. 6.
The user interface 606 may include, among other things, a display, keyboard, mouse, trackball, click gun, keys, buttons, touch pad, or touch screen, etc.
It is to be appreciated that the memory 602 can be either volatile memory or nonvolatile memory, and can include both volatile and nonvolatile memory. The nonvolatile Memory may be a Read Only Memory (ROM), a programmable Read Only Memory (PROM, programmable Read-Only Memory), which serves as an external cache, among others. By way of example, and not limitation, many forms of RAM are available, such as static random Access Memory (SRAM, staticRandom Access Memory), synchronous static random Access Memory (SSRAM, synchronous Static RandomAccess Memory). The memory described by embodiments of the present application 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 application is used to store various kinds of data to support the operation of the wake channel based MQTT theme subscription terminal 600. Examples of such data include: any executable programs for operating on the wake channel based MQTT theme subscription terminal 600, such as an operating system 6021 and application programs 6022; the operating system 6021 contains various system programs, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and handling hardware-based tasks. The application 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 theme subscription method based on the wake-up channel provided by the embodiment of the application can be contained in the application 6022.
The method disclosed in the above embodiment of the present application may be applied to the processor 601 or implemented by the processor 601. The processor 601 may be an integrated circuit chip with signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in the processor 601 or instructions in the form of software. The processor 601 may be a general purpose processor, a digital signal processor (DSP, digital Signal Processor), 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 application. The general purpose processor 601 may be a microprocessor or any conventional processor or the like. The steps of the accessory optimization method provided by the embodiment of the application can be directly embodied as the execution completion of the hardware decoding processor or the execution completion of the hardware and software module combination execution in the decoding processor. The software modules may be located in a storage medium having memory and a processor reading information from the memory and performing the steps of the method in combination with hardware.
In an exemplary embodiment, the wake channel-based MQTT theme subscription terminal 600 may be used by one or more application specific integrated circuits (ASICs, application Specific Integrated Circuit), DSPs, programmable logic devices (PLDs, programmable Logic Device), complex programmable logic devices (CPLDs, complex Programmable LogicDevice) to perform the aforementioned methods.
The embodiment of the application also provides a computer readable storage medium, on which a computer program is stored, which when being executed by a processor, realizes the MQTT theme subscription method based on the wake-up channel applied to the SDK end; or the MQTT theme subscription method based on the wake-up channel is applied to the cloud server.
Those of ordinary skill in the art will appreciate that: all or part of the steps for implementing the method embodiments described above may be performed by computer program related hardware. The aforementioned computer program may be stored in a computer readable storage medium. The program, when executed, performs steps including the method embodiments described above; and the aforementioned storage medium includes: various media that can store program code, such as ROM, RAM, magnetic or optical disks.
In the embodiments provided herein, the computer-readable 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. In addition, 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 and data storage media do not include connections, carrier waves, signals, or other transitory media, but are intended to be directed to non-transitory, tangible storage media. Disk and disc, as used herein, 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 application provides a method, a device, a terminal and a medium for subscribing the MQTT topic based on a wake-up channel, and provides a method for improving the efficiency of subscribing the MQTT topic based on the wake-up channel. 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 of the present application and its effectiveness, and are not intended to limit the application. Modifications and variations may be made to the above-described embodiments by those skilled in the art without departing from the spirit and scope of the application. Accordingly, it is intended that all equivalent modifications and variations of the application be covered by the claims, which are within the ordinary skill of the art, be within the spirit and scope of the present disclosure.