Disclosure of Invention
In view of this, embodiments of the present application provide an access method and apparatus for internet of things devices and an MQTT gateway, so as to solve the problems in the prior art that, because different internet of things servers cannot form a cluster, the stability of a service cannot be improved in a high-concurrency scenario, and access support cannot be effectively provided for more internet of things devices.
A first aspect of an embodiment of the present application provides an access method for an internet of things device, where the internet of things device accesses an internet of things server through an MQTT gateway, and the access method includes:
the MQTT gateway receives an access request of the Internet of things equipment, wherein the access request comprises an identifier of the Internet of things equipment;
the MQTT gateway determines an Internet of things server corresponding to the Internet of things equipment in the Internet of things server cluster according to the identification of the Internet of things equipment;
and the MQTT gateway sends a redirection message to the Internet of things equipment according to the determined Internet of things server so that the Internet of things equipment is accessed to the determined Internet of things server.
With reference to the first aspect, in a first possible implementation manner of the first aspect, the accessing request includes configuration information of the internet of things device, and the determining, by the MQTT gateway, an internet of things server corresponding to the internet of things device in an internet of things server cluster according to the identifier of the internet of things device includes:
the MQTT gateway detects whether the Internet of things equipment has access records according to the identification of the Internet of things equipment;
and when the Internet of things equipment does not have an access record, the MQTT gateway searches a corresponding Internet of things server according to the configuration information of the Internet of things equipment.
With reference to the first possible implementation manner of the first aspect, in a second possible implementation manner of the first aspect, the method further includes:
when the Internet of things equipment has an access record, the MQTT gateway determines that an Internet of things server in the access record is the Internet of things server accessed by the Internet of things equipment.
With reference to the second possible implementation manner of the first aspect, in a third possible implementation manner of the first aspect,
with reference to the first aspect, the first possible implementation manner of the first aspect, the second possible implementation manner of the first aspect, or the third possible implementation manner of the first aspect, in a fourth possible implementation manner of the first aspect, when an access record exists in the internet of things device, determining that the internet of things server in the access record is an internet of things server accessed by the internet of things device includes:
when the Internet of things equipment has an access record and the Internet of things servers in the access record comprise two or more than two, the MQTT gateway acquires the state information of the Internet of things servers in the access record;
and according to the acquired state information of the Internet of things server, the MQTT gateway determines the corresponding Internet of things server of the Internet of things equipment in the Internet of things server cluster.
With reference to the third possible implementation manner of the first aspect, in a fourth possible implementation manner of the first aspect, the status information of the internet of things server includes status information of whether the internet of things server is working normally and/or load status information of the internet of things server.
With reference to the first possible implementation manner of the first aspect, in a fifth possible implementation manner of the first aspect, the searching for the corresponding internet of things server according to the configuration information of the internet of things device includes:
and searching the Internet of things server corresponding to the Internet of things equipment by the MQTT gateway according to the equipment attribute and the equipment classification of the Internet of things equipment.
With reference to the first aspect, in a sixth possible implementation manner of the first aspect, the method further includes:
the MQTT gateway receives a configuration updating request sent by a configuration terminal, wherein the configuration updating request comprises an identification of the Internet of things equipment and corresponding information accessed to an Internet of things server;
and according to the configuration updating request, the MQTT gateway updates the stored configuration information.
A second aspect of the embodiments of the present application provides an access device for an internet of things device, the internet of things device accesses an internet of things server through an MQTT gateway, the access device includes:
a request receiving unit, configured to receive, by the MQTT gateway, an access request of the internet of things device, where the access request includes an identifier of the internet of things device;
the Internet of things server determining unit is used for determining the corresponding Internet of things server of the Internet of things equipment in the Internet of things server cluster by the MQTT gateway according to the identification of the Internet of things equipment;
and the redirection unit is used for sending a redirection message to the Internet of things equipment by the MQTT gateway according to the determined Internet of things server so that the Internet of things equipment is accessed to the determined Internet of things server.
A third aspect of the embodiments of the present application provides an MQTT gateway, including a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps of the method according to any one of the first aspect when executing the computer program.
A fourth aspect of embodiments of the present application provides a computer-readable storage medium, in which a computer program is stored, which, when executed by a processor, performs the steps of the method according to any one of the first aspect.
A fifth aspect of the embodiments of the present application provides an access method for an internet of things device, where the internet of things device accesses an internet of things server through an MQTT gateway, and the method includes:
the Internet of things equipment sends an access request to the MQTT gateway, wherein the access request comprises the identification of the Internet of things equipment, so that the MQTT gateway determines an Internet of things server corresponding to the Internet of things equipment according to the identification;
the Internet of things equipment receives a redirection message returned by the MQTT gateway, wherein the redirection message comprises the determined Internet of things server;
and sending an access request to the determined Internet of things server according to the received redirection message.
Compared with the prior art, the embodiment of the application has the advantages that: the MQTT gateway is arranged on the Internet of things equipment and the Internet of things server, the access request of the Internet of things equipment is received through the MQTT, the corresponding Internet of things server of the Internet of things equipment in the Internet of things server cluster is determined according to the Internet of things identification in the access request, and the MQTT gateway sends the redirection message to the Internet of things equipment according to the determined Internet of things server, so that the Internet of things equipment is accessed into the determined Internet of things equipment according to the redirection message, different types of Internet of things server clusters can be effectively realized, the stability of the access service is improved, and the access support is favorably provided for more Internet of things equipment.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
At present, services accessed by different internet of things devices generally need to meet the requirement that the services in a cluster are in the same implementation mode or the same implementation type. For example, servers such as EMQ (open source internet of things MQTT message server developed based on Erlang/OTP platform), mosquitto (proxy server (Broker) that implements MQTT protocol with C language) and the like may each construct their own cluster. However, because of the different development languages, mosquitto was developed using the C language, while EMQ was developed using Nodejs. If servers of different development languages are clustered, the clustered servers may not be able to provide services for different internet of things devices. Moreover, even if the server types are the same, such as all EMQ server types, different authentication methods may be included, such as ID authentication and username-password authentication, respectively. Due to different authentication or authorization methods, servers of the same server type may not constitute a server cluster. Therefore, the current server cluster is usually limited to a server cluster formed by MQTT servers of the same brand, and the synchronization mode of the formed server cluster usually adopts a mode of copying messages among nodes, and the same message may need to be copied and forwarded for many times, which causes waste of server cluster resources and network resources.
In order to solve the above problems, the present application provides an access method for an internet of things device, as shown in fig. 1, an implementation scenario diagram of the access method for the internet of things device provided in the embodiment of the present application is provided, as shown in fig. 1, the implementation scenario of the access method for the internet of things device includes an internet of things device, an MQTT gateway, and an internet of things server cluster. Wherein:
the internet of things device can comprise one or more devices. And the access address of the MQTT gateway and the identification of the Internet of things equipment are stored in the Internet of things equipment. The identification of the internet of things equipment is used for uniquely determining the internet of things equipment. And through the stored access address of the MQTT gateway, the Internet of things equipment can establish communication connection with the MQTT gateway and send the identification of the Internet of things equipment to the MQTT gateway. In a possible implementation manner, the internet of things device further includes configuration information of the internet of things device, where the configuration information may include a device attribute, a device classification, and the like of the internet of things device.
The MQTT gateway stores the corresponding relation between the identification of the Internet of things equipment and the access record of the Internet of things equipment, the corresponding relation between the configuration information of the Internet of things equipment and the Internet of things server, or the corresponding rules between the configuration information of the Internet of things server and the configuration information of the Internet of things equipment and the Internet of things server. The MQTT gateway can be in communication connection with the control terminal, and configuration information of an Internet of things server and configuration information of Internet of things equipment in the MQTT gateway can be modified through the control terminal. Or, the MQTT gateway may further include a correspondence between an identifier of the internet of things device and configuration information of the internet of things device, and the configuration information of the internet of things device may be found by obtaining the identifier of the internet of things device, so that when the internet of things device is upgraded and updated, the corresponding configuration information may be quickly modified by the control terminal.
The internet of things server cluster may include different types of internet of things servers. The state information of the internet of things server can be updated to the MQTT gateway according to the request of the MQTT gateway, or can be updated to the MQTT gateway according to a preset updating period. The configuration information of the internet of things server can be updated to the MQTT gateway through the control terminal, or the configuration information of the internet of things server in the server cluster can also be updated in a communication mode of the internet of things server and the MQTT gateway, or a registration mode of the internet of things server at the MQTT gateway.
Fig. 2 is a schematic view of an implementation flow of an access method of an internet of things device provided in an embodiment of the present application, where based on the implementation scenario shown in fig. 1, the access method of the internet of things device includes:
s101, the MQTT gateway receives an access request of the Internet of things equipment, wherein the access request comprises an identifier of the Internet of things equipment.
The Internet of things equipment is provided with a wireless communication module and an access address of an MQTT gateway. When the Internet of things equipment is powered on, the Internet of things equipment is automatically started, automatically accesses the set MQTT gateway through the wireless communication module according to the stored access address, and sends an access request to the MQTT gateway.
Generally, the internet of things equipment does not have a display device due to cost consideration, and modification of information built in the internet of things equipment is troublesome. If an address of an internet of things server for access is built in the internet of things equipment, if the internet of things server breaks down or the communication of the internet of things server is blocked, it is troublesome to modify data information built in the internet of things equipment. In order to solve the problem, an identifier for uniquely marking the internet of things equipment is set in the internet of things equipment in the embodiment of the application, and data information corresponding to the identifier of the internet of things equipment is stored in the MQTT gateway. Therefore, when the data information in the internet of things equipment needs to be updated, the MQTT gateway can establish communication connection with the control terminal, receive the update information about the data in the internet of things equipment sent by the control terminal, and store the update information in the MQTT gateway. When the MQTT gateway stores the updating information, the corresponding relation between the identification of the Internet of things and the updating information is stored.
S102, the MQTT gateway determines the corresponding Internet of things server of the Internet of things equipment in the Internet of things server cluster according to the identification of the Internet of things equipment.
In this embodiment of the application, when the MQTT gateway determines the corresponding internet of things server in the server cluster according to the identifier of the internet of things device, the following method may be included:
the first method is as follows:
when the access record corresponding to the identifier of the internet of things is stored in the MQTT gateway, the corresponding internet of things server in the internet of things server cluster can be determined according to the access address or the access address of the internet of things server in the access record.
In a possible implementation mode, after the internet of things server corresponding to the internet of things equipment is determined through the historical records, the state information of the determined internet of things server can be obtained, and if the internet of things server is in a normal working state, the internet of things server can be accessed through the redirection function of the MQTT gateway. When the determined internet of things server is in an abnormal working state, for example, the internet of things server fails, or the load of the internet of things server exceeds a predetermined requirement, the configuration information of the internet of things equipment can be determined according to the identifier of the internet of things equipment, or the internet of things server matched with the configuration information is searched in a server cluster according to the acquired configuration information by receiving the configuration information of the internet of things equipment, and the searched internet of things server is used as the internet of things server corresponding to the internet of things equipment.
In a possible implementation manner, when the internet of things server corresponding to the internet of things device is determined through the history record, the possible history record includes the access records of the plurality of internet of things servers, the state information of the plurality of internet of things servers in the access records, including whether the internet of things servers work normally or the load state of the internet of things servers, can be acquired, and the internet of things server corresponding to the internet of things device is determined according to the state information. For example, the internet of things server in a normal working state and with the smallest load may be selected as the internet of things server corresponding to the internet of things device.
Mode two
When the access record corresponding to the internet of things equipment is not stored in the MQTT gateway, the configuration information of the internet of things equipment, including information such as equipment attributes and equipment classification of the internet of things equipment, can be acquired, and the internet of things server corresponding to the internet of things equipment is determined according to the configuration information of the internet of things equipment and by combining the predetermined corresponding relation between the configuration information and the internet of things equipment.
Or, according to the acquired configuration information of the internet of things device and the configuration information of the internet of things servers stored in advance, one or more internet of things servers corresponding to the internet of things device are searched in combination with a preset matching rule, and then the state information of the searched internet of things services is further combined to determine the internet of things server corresponding to the internet of things device.
In order to improve the success rate of accessing the internet of things device, different types of internet of things servers may be included in the server cluster, and each type of internet of things server may include two or more than two. When an access request of the internet of things equipment is received, a matched internet of things server can be searched in the server cluster according to identification or configuration information of the internet of things equipment, and a better internet of things server is selected according to the searched internet of things server, for example, when the working state is normal, the internet of things server with a smaller load is selected, or when the load is the same, the internet of things server with better stability is selected, and the like.
S103, the MQTT gateway sends a redirection message to the Internet of things equipment according to the determined Internet of things server, so that the Internet of things equipment is accessed to the determined Internet of things server.
After the internet of things server needing to be accessed is determined, the MQTT gateway can send a redirection message to the internet of things device according to a redirection function of a protocol, for example, a redirection function supported by an MQTT5.0 protocol, where the redirection message includes the determined internet of things server. After receiving the redirection message sent by the MQTT gateway, the Internet of things equipment sends an access request to the determined Internet of things server according to the information of the Internet of things server carried in the redirection message, so that the Internet of things equipment is accessed to the determined Internet of things server, and the required service is provided for the Internet of things equipment.
Because the server cluster in the application can comprise different types of Internet of things servers to provide services for the Internet of things equipment, the cluster of the different types of Internet of things servers can be effectively realized.
In addition, the clustered Internet of things server does not need to realize message synchronization through copying and forwarding, can directly realize communication synchronization with the MQTT gateway, is favorable for reducing the resource consumption of the Internet of things server, and improves the broadband utilization efficiency.
In addition, when information in the internet of things equipment needs to be updated, communication connection can be established with the MQTT gateway through the control terminal, and the information needing to be updated can be written into the MQTT gateway, so that the information in the internet of things equipment can be prevented from being updated one by one, and the data updating efficiency of the internet of things equipment is greatly improved.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
Fig. 3 is a schematic view of an access apparatus of an internet of things device according to an embodiment of the present application, and as shown in fig. 3, the access apparatus includes:
arequest receiving unit 301, configured to receive, by the MQTT gateway, an access request of the internet of things device, where the access request includes an identifier of the internet of things device;
an internet of thingsserver determining unit 302, configured to determine, by the MQTT gateway, an internet of things server corresponding to the internet of things device in an internet of things server cluster according to the identifier of the internet of things device;
aredirection unit 303, configured to send, by the MQTT gateway, a redirection message to the internet of things device according to the determined internet of things server, so that the internet of things device accesses the determined internet of things server.
The access apparatus of the internet of things device shown in fig. 3 corresponds to the access method of the internet of things device shown in fig. 1.
Fig. 4 is a schematic diagram of an MQTT gateway according to an embodiment of the present application. As shown in fig. 4, theMQTT gateway 4 of this embodiment includes: aprocessor 40, amemory 41, and acomputer program 42, such as an access program of an internet of things device, stored in thememory 41 and operable on theprocessor 40. Theprocessor 40 executes thecomputer program 42 to implement the steps in the access method embodiments of the internet of things devices. Alternatively, theprocessor 40 implements the functions of the modules/units in the above device embodiments when executing thecomputer program 42.
Illustratively, thecomputer program 42 may be partitioned into one or more modules/units that are stored in thememory 41 and executed by theprocessor 40 to accomplish the present application. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions, which are used for describing the execution process of thecomputer program 42 in theMQTT gateway 4.
The MQTT gateway may include, but is not limited to, aprocessor 40, amemory 41. Those skilled in the art will appreciate that fig. 4 is only an example of theMQTT gateway 4, and does not constitute a limitation to theMQTT gateway 4, and may include more or less components than those shown, or combine some components, or different components, for example, the MQTT gateway may further include input and output devices, network access devices, buses, and the like.
TheProcessor 40 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Thememory 41 may be an internal storage unit of theMQTT gateway 4, such as a hard disk or a memory of theMQTT gateway 4. Thememory 41 may also be an external storage device of theMQTT gateway 4, for example, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), or the like, which is equipped on theMQTT gateway 4. Further, thememory 41 may also include both an internal storage unit and an external storage device of theMQTT gateway 4. Thememory 41 is used for storing the computer program and other programs and data required by the MQTT gateway. Thememory 41 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. For the specific working processes of the units and modules in the system, reference may be made to the corresponding processes in the foregoing method embodiments, which are not described herein again.
In the above embodiments, the description of each embodiment has its own emphasis, and reference may be made to the related description of other embodiments for parts that are not described or recited in any embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus/terminal device and method may be implemented in other ways. For example, the above-described embodiments of the apparatus/terminal device are merely illustrative, and for example, the division of the modules or units is only one type of logical function division, and other division manners may be available in actual implementation, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated modules/units, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium. Based on such understanding, all or part of the processes in the methods of the embodiments described above may be implemented by hardware related to instructions of a computer program, where the computer program may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the methods described above may be implemented. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, read-Only Memory (ROM), random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain other components which may be suitably increased or decreased as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media which may not include electrical carrier signals and telecommunications signals in accordance with legislation and patent practice.
The above-mentioned embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.