Disclosure of Invention
In view of this, embodiments of the present disclosure provide a method and a system for connecting data of an internet of things, where the method and the system are mainly directed at multiple terminals and multiple servers in an application of the internet of things, and under a condition that server resources and network resources are limited, the terminals of the internet of things can automatically select a connected server to report data, balance server loads and network loads, and optimize resource allocation.
In order to achieve the above purpose, the invention provides the following technical scheme:
a data connection method of the Internet of things comprises the following steps: the method comprises the steps that a plurality of server terminals monitor in real time and generate a load index p value of a server and a connection delay index q value of the server and an Internet of things terminal, the sum p + q value of the load index p value and the connection delay index q value is sent to the Internet of things terminal, the Internet of things terminal sorts the obtained p + q values from small to large, and a server address corresponding to the smallest p + q value is preferentially selected for connection; and the load index p value and the connection delay index q value of the server end in the initial state are both defined as zero.
Further, the internet of things terminal stores the acquired p + q value and sequence of each server and updates the values in real time during each data connection.
Further, if a plurality of servers with the same minimum p + q values exist, the internet of things terminal preferentially selects the address of the first storage server to connect according to the storage sequence.
Further, the address sequence of the server stored in the internet of things terminal is randomly generated by the burning upper computer, and the address of the server can be increased or decreased under the control of the server side.
The invention also provides an internet of things data connection system, which comprises a plurality of servers and a plurality of internet of things terminals, wherein each server comprises a load monitoring module, a connection monitoring module and a terminal communication module;
the load monitoring module is used for monitoring the current running state of the server and generating a load index p value in real time;
the connection monitoring module is used for calculating the time for returning the terminal package after the data package is sent when the terminal of the Internet of things is connected with the server, and generating a connection delay index q value;
the terminal communication module is used for receiving a communication request from the terminal of the Internet of things, acquiring a connection index p + q value obtained by the load monitoring module and the connection monitoring module, and returning the connection index p + q value to the terminal of the Internet of things;
the Internet of things terminal comprises a cloud communication module and a connection control module, wherein the connection control module is used for initiating an Internet of things connection request, selecting a server address corresponding to the minimum connection index p + q value, transmitting the server address to the cloud communication module, and simultaneously initiating a connection instruction to the cloud communication module;
the cloud communication module is used for receiving server address information corresponding to the minimum connection index p + q value sent by the connection control module and initiating a communication request to the terminal communication module.
Further, the internet of things terminal further comprises a storage module, and the storage module is used for storing the currently connected server address information and the connection index p + q value information corresponding to the server address.
Further, the cloud communication module is further configured to receive connection index p + q value information from the server, and send the connection index p + q value information to the connection control module.
Further, the connection control module is further configured to obtain a connection index p + q value returned by the current connection server from the cloud communication module, and send the connection index p + q value to the storage module for updating and storing.
The invention discloses a data connection method and a data connection system of an Internet of things, which have the beneficial effects that:
(1) according to the invention, aiming at the application scene of multiple terminals and multiple servers, the terminals of the Internet of things automatically select the connected servers, so that the server load is more balanced and the network load is balanced, and the terminals can preferably select the servers with shorter connection time to a certain extent.
(2) The detection of load and the detection of time are carried out at the server side, and fewer peripheral resources are required to be consumed by the terminal.
(3) The selection of the final connection is performed by the terminal, reducing the consumption of computing resources in the server set.
(4) The connection decision algorithm is simple, the limited chip can meet the requirement of computing resources, and the cost of the terminal is reduced.
(5) The connection decision takes time delay factors into consideration, so that the terminal of the Internet of things can be connected with the server more quickly.
(6) And dynamic updating optimization can be carried out according to the load and time delay.
Detailed Description
The embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
The embodiments of the present disclosure are described below with specific examples, and other advantages and effects of the present disclosure will be readily apparent to those skilled in the art from the disclosure in the specification. It is to be understood that the described embodiments are merely illustrative of some, and not restrictive, of the embodiments of the disclosure. The disclosure may be embodied or carried out in various other specific embodiments, and various modifications and changes may be made in the details within the description without departing from the spirit of the disclosure. It is to be noted that the features in the following embodiments and examples may be combined with each other without conflict. All other embodiments, which can be derived by a person skilled in the art from the embodiments disclosed herein without making any creative effort, shall fall within the protection scope of the present disclosure.
It is noted that various aspects of the embodiments are described below within the scope of the appended claims. It should be apparent that the aspects described herein may be embodied in a wide variety of forms and that any specific structure and/or function described herein is merely illustrative. Based on the disclosure, one skilled in the art should appreciate that one aspect described herein may be implemented independently of any other aspects and that two or more of these aspects may be combined in various ways. For example, an apparatus may be implemented and/or a method practiced using any number of the aspects set forth herein. Additionally, such an apparatus may be implemented and/or such a method may be practiced using other structure and/or functionality in addition to one or more of the aspects set forth herein.
It should be noted that the drawings provided in the following embodiments are only for illustrating the basic idea of the present disclosure, and the drawings only show the components related to the present disclosure rather than the number, shape and size of the components in actual implementation, and the type, amount and ratio of the components in actual implementation may be changed arbitrarily, and the layout of the components may be more complicated.
In addition, in the following description, specific details are provided to facilitate a thorough understanding of the examples. However, it will be understood by those skilled in the art that the aspects may be practiced without these specific details.
As shown in fig. 1, an embodiment of the present disclosure provides an internet of things data connection method, including: the method comprises the steps that a plurality of server terminals monitor in real time and generate a load index p value of a server and a connection delay index q value of the server and an Internet of things terminal, the sum p + q value of the load index p value and the connection delay index q value is sent to the Internet of things terminal, the Internet of things terminal sorts the obtained p + q values from small to large, and a server address corresponding to the smallest p + q value is preferentially selected for connection; and the terminal of the internet of things stores the acquired p + q value and sequence of each server and updates the values in real time during each data connection. And the load index p value and the connection delay index q value of the server end in the initial state are both defined as zero.
The method is mainly used for the scene that the terminal of the Internet of things is automatically connected with the server to report data under the condition of multiple terminals and multiple servers in the application of the Internet of things. Because the internet of things terminal leaves the factory and has the addresses of a plurality of servers, the server needing to be reported needs to be appointed when data is reported every time. The method of the invention is characterized in that the server-free address stored by the terminal of the Internet of things is stored and the priority level of the server-free address is correspondingly stored. The initial connection indexes corresponding to all the servers are all 0 (or defined as minimum), the sequence of the server addresses written in the factory is randomly generated by the burning upper computer, and the server addresses can be increased or decreased under the control of the server side.
When the terminal of the Internet of things is connected with the server, the server with the minimum connection index is preferentially selected, and if a plurality of servers with the same minimum index p + q value exist, the terminal of the Internet of things preferentially selects the address of the first storage server according to the storage sequence of the internet of things to connect. (because of the random generation used in the process of production testing and burning, the first connection of the internet of things terminal cannot be the same server).
When the terminal of the internet of things is connected with a server every time, the server side has a load monitoring module and a connection monitoring module for detecting a load index p of the server and a connection delay index q with the terminal and sending the value of p + q to the terminal of the internet of things; the internet of things terminal saves the p + q value as a corresponding connection index of the corresponding server address, sorts the p + q values of the connection indexes from small to large, preferentially selects the server address corresponding to the minimum p + q value of the connection index for connection, updates the p + q value of the terminal after each connection, then updates the sorting of the p + q value, and defaults to connect the server with the minimum p + q value.
The following objects are achieved by the above method of the invention:
1. the server address connected with the terminal of the internet of things is randomly generated during production in an initial state, and theoretically, the connection number received by each server is the same when a large number of terminals exist.
2. Because the initial connection index of the terminal of the internet of things is 0, the connection index of the corresponding server address can be modified after one connection, and the modified index is larger than 0, so that the terminal of the internet of things can be connected with each server.
3. The dynamic update is possible because each connection selects the server connection with the smallest index. If a certain server is congested or the load becomes large, other servers can be connected.
As shown in fig. 2, the present invention further provides an internet of things data connection system, which includes a plurality of servers 1 and a plurality of internet ofthings terminals 2, where the server 1 includes a load monitoring module 11, aconnection monitoring module 12, and aterminal communication module 13;
the load monitoring module 11 is used for monitoring the current running state of the server and generating a load index p value in real time;
theconnection monitoring module 12 is configured to calculate a terminal repackaging time after the data packet is sent when the internet of things terminal 2 is connected to the server 1, that is, the server 1 receives the repackaging time of the internet of things terminal 2 after sending the data packet to the internet of things terminal 2, so as to obtain a network congestion situation at the time, and generate a connection delay index q value based on the network congestion situation;
theterminal communication module 13 is configured to receive a communication request from the internet of things terminal 2, obtain a connection index p + q value obtained by the load monitoring module 11 and theconnection monitoring module 12, and return the connection index p + q value to the internet of things terminal 2;
the internet of things terminal 2 comprises a cloud communication module 21, aconnection control module 22 and astorage module 23, wherein theconnection control module 22 is used for initiating an internet of things connection request, selecting a server address corresponding to a minimum connection index p + q value, transmitting the server address to the cloud communication module 21, and simultaneously initiating a connection instruction to the cloud communication module 21; theconnection control module 22 is further configured to obtain a connection index p + q value returned by the current connection server from the cloud communication module 21, and send the connection index p + q value to thestorage module 23 for storage.
The cloud communication module 21 is configured to receive server address information corresponding to the minimum connection index p + q value sent by theconnection control module 22, and initiate a communication request to theterminal communication module 13. The cloud communication module 21 is further configured to receive connection index p + q value information from the server 1, and send the connection index p + q value information to theconnection control module 22.
Thestorage module 23 is configured to store address information of a currently connected server and connection index p + q value information corresponding to the server address.
Example 1:
in this embodiment, the internet of things terminal stores address information of a plurality of servers in an initial state, and the address information is an address sequence randomly generated by a production testing burning tool; the corresponding address information has connection index information which is 0 initially. And the connection control module of the terminal of the Internet of things searches the minimum index from the storage module, and if the minimum index is the same, the connection control module selects the server address with the minimum storage address (the storage address refers to the FLASH address, but not the stored I P address).
And the connection control module is connected with the server through the cloud communication module according to the taken server address.
And after receiving the connection request, the terminal communication module of the server allows connection and requests a load index p and a connection time consumption index q from the load monitoring module and the connection module.
The load obtains a load index p according to the running condition of the current server, for example, the average usage percentage of a CPU (central processing unit) of the server in one minute, the memory usage percentage and the average value are obtained; the connection time-consuming index q, for example, the server sends a special data packet a to the terminal after establishing a TCP connection with the terminal, the terminal returns a response data packet b of the data packet immediately after receiving the special data packet, the time-consuming index q is equal to the time period from the sending time of the data packet a to the receiving time of the data packet b, and the time-consuming index q is always between 0 and 1 through a coefficient k.
And the terminal communication module of the server returns the value of p + q to the server as the connection index.
And the cloud communication module of the terminal sends the value of the connection index p + q to the storage module after receiving the value.
And the storage module modifies the value of the connection index p + q corresponding to the current server address and inserts the value into the original sorting queue according to the sequence from small to large of the connection index p + q.
The above description is only for the specific embodiments of the present disclosure, but the scope of the present disclosure is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present disclosure should be covered within the scope of the present disclosure. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.