Device heartbeat interval control method, device, Internet of Things device and storage medium
By dynamically adjusting the heartbeat interval of IoT devices and using different heartbeat intervals during user operation and non-user operation according to the working status, the problem of server processing pressure and high device power consumption caused by heartbeat packets of IoT devices is solved, and the problem is achieved More efficient communication and lower power consumption.
Patent Information
- Application Number
- CN202111677782.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-31
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2041-12-31
AI Technical Summary
The heartbeat packets of IoT devices cause problems such as high server processing pressure and high device power consumption.
Obtain the reference heartbeat value from the server through the Internet of Things device, dynamically adjust the heartbeat interval according to different working states, and ensure that different heartbeat intervals are used under user operation and non-user operation to reduce server processing pressure and device power consumption.
It effectively reduces the processing pressure of the IoT server due to heartbeat packets, reduces the power consumption of the device due to heartbeats, and improves communication efficiency.
Smart Images

Figure CN114500550B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a device heartbeat interval control method, device, Internet of Things device and storage medium. Background Art
[0002] Usually, IoT devices connect to servers through long connections established through protocols such as Message Queuing Telemetry Transport (MQTT) and WebSocket. IoT servers need to process requests from a large number of devices. If it is assumed that IoT devices use a 30-second heartbeat interval, the heartbeat request rate of 1 million devices is 1 million / 30=33,300 times / second. It can be seen that the processing pressure of IoT servers due to heartbeat packets is relatively large, and the power consumption of devices due to heartbeats is also relatively large. Summary of the invention
[0003] The main purpose of the present invention is to provide a device heartbeat interval control method, device, Internet of Things device and storage medium, which can solve the problem that the processing pressure of the Internet of Things server due to heartbeat packets is large, and the power consumption of the device due to heartbeats is also large.
[0004] To achieve the above-mentioned purpose, the first aspect of the present application provides a device heartbeat interval control method, which is applied to an Internet of Things device, and the method comprises:
[0005] The IoT device obtains at least one reference heartbeat value from the server, and determines a first heartbeat interval according to the at least one reference heartbeat value, wherein the at least one reference heartbeat value includes at least a reference heartbeat minimum value, and the reference heartbeat minimum value is a minimum heartbeat interval value of the device preset by the server;
[0006] The IoT device determines a current target working state, where the target working state is one of a plurality of working states, and the plurality of working states at least include a working state with user operation and a working state without user operation;
[0007] The Internet of Things device determines a second heartbeat interval in the target working state based on the first heartbeat interval and the reference heartbeat minimum value, and sends a heartbeat packet to the server at the second heartbeat interval, wherein the second heartbeat interval in the working state under user operation is smaller than the second heartbeat interval in the working state without user operation.
[0008] Optionally, taking the reference heartbeat minimum value as the detection starting point, calculating the detection heartbeat interval according to a preset first increase value of the arithmetic progression, and using the detection heartbeat interval to detect the server;
[0009] Until the detection of the detection heartbeat interval is successful and the next detection heartbeat interval is greater than the reference heartbeat maximum value, the detection heartbeat interval is determined to be the first heartbeat interval, wherein the reference heartbeat maximum value is included in the at least one reference heartbeat value, and the reference heartbeat maximum value is the maximum value of the heartbeat intervals of other devices connected to the server and within the same area as the Internet of Things device; or, until the detection of the detection heartbeat interval fails, the detection heartbeat interval before the detection failure is determined as the first heartbeat interval.
[0010] Optionally, the at least one reference heartbeat value further includes a reference heartbeat maximum value and an average heartbeat value, the reference heartbeat maximum value is the maximum value of the heartbeat intervals of other devices connected to the server and within the same area as the IoT device, and the average heartbeat value is an average value calculated by the server based on the heartbeat values of other devices within the same area as the IoT device and using the same operator network;
[0011] The determining a first heartbeat interval according to the at least one reference heartbeat value comprises:
[0012] The average heartbeat value is used as a detection starting point, based on the reference heartbeat maximum value and the reference heartbeat minimum value, a binary search method is used to perform the heartbeat interval detection operation on the server to determine the first heartbeat interval.
[0013] Optionally, the at least one reference heartbeat value further includes a reference heartbeat maximum value, where the reference heartbeat maximum value is a maximum value among heartbeat intervals of other devices connected to the server and within the same area as the IoT device;
[0014] The determining a first heartbeat interval according to the at least one reference heartbeat value comprises:
[0015] Determine the increase value corresponding to the current number of detections according to a preset first mapping relationship between the number of detections and the increase value; take the reference heartbeat minimum value as the detection starting point, calculate the detection heartbeat interval according to the increase value corresponding to the current number of detections, and use the detection heartbeat interval to detect the server, wherein the number of detections in the first mapping relationship is positively correlated with the increase value;
[0016] When the current detection heartbeat interval is detected successfully, and the next detection heartbeat interval of the current detection heartbeat interval is greater than the difference between the reference heartbeat maximum value and the reference heartbeat minimum value, determine the increase value corresponding to the current detection number of times according to a preset second mapping relationship between the number of detections and the increase value, take the current detection heartbeat interval as the detection starting point, calculate the detection heartbeat interval according to the increase value corresponding to the current detection number of times, use the detection heartbeat interval to detect the server, and the detection number of times in the second mapping relationship is negatively correlated with the increase value;
[0017] Until the detection of the detection heartbeat interval is successful, and the detection heartbeat interval is not greater than the reference heartbeat maximum value, and the next detection heartbeat interval of the detection heartbeat interval is greater than the reference heartbeat maximum value, the detection heartbeat interval is determined to be the first heartbeat interval; or, until the detection of the detection heartbeat interval fails, the detection heartbeat interval before the detection failure is determined to be the first heartbeat interval.
[0018] Optionally, until the detection of the detection heartbeat interval is successful, and the detection heartbeat interval is not greater than the reference heartbeat maximum value, and the next detection heartbeat interval of the detection heartbeat interval is greater than the reference heartbeat maximum value, then determining the detection heartbeat interval as the first heartbeat interval includes:
[0019] When the detection of the detection heartbeat interval is successful and the next detection heartbeat interval of the detection heartbeat interval is greater than the reference heartbeat maximum value, the detection heartbeat interval is calculated according to the current detection heartbeat interval and the preset second increase value of the arithmetic progression;
[0020] The server is detected using the detection heartbeat interval until the detection of the detection heartbeat interval succeeds and the detection of the next detection heartbeat interval of the detection heartbeat interval fails, then the detection heartbeat interval is determined to be the first heartbeat interval.
[0021] Optionally, until the detection of the detection heartbeat interval fails, determining the detection heartbeat interval before the detection failure as the first heartbeat interval includes:
[0022] In the case of detection failure, the detection heartbeat interval is calculated according to the previous detection heartbeat interval of the current detection heartbeat interval and the preset third increase value of the arithmetic progression, and the detection heartbeat interval is greater than the current detection heartbeat interval;
[0023] The server is detected using the detection heartbeat interval until the detection of the detection heartbeat interval is successful and the next detection heartbeat interval of the detection heartbeat interval is greater than the reference heartbeat maximum value, and the detection heartbeat interval of successful detection is determined as the first heartbeat interval; or until the detection of the detection heartbeat interval fails, the detection heartbeat interval before the detection failure is determined as the first heartbeat interval.
[0024] Optionally, the IoT device determines a current target working state, including:
[0025] When the Internet of Things device detects a user operation, determining that the target working state is a first-level heartbeat state;
[0026] The IoT device determines that the target working state is a second-level heartbeat state when detecting that the duration of no user operation reaches a first preset duration;
[0027] The IoT device determines that the target working state is a third-level heartbeat state when it is detected that the duration of no user operation reaches a second preset duration, wherein the second preset duration is greater than the first preset duration, the heartbeat interval corresponding to the first-level heartbeat state is less than the heartbeat interval corresponding to the second-level heartbeat state, and the heartbeat interval corresponding to the second-level heartbeat state is less than the heartbeat interval corresponding to the third-level heartbeat state;
[0028] The IoT device determines, according to the first heartbeat interval and the reference heartbeat minimum value, a second heartbeat interval in the target working state, including:
[0029] The Internet of Things device obtains a heartbeat calculation rule corresponding to the target working state;
[0030] A second heartbeat interval under the target working state is obtained by calculation according to the first heartbeat interval, the reference heartbeat minimum value and a heartbeat calculation rule corresponding to the target working state.
[0031] To achieve the above-mentioned purpose, the second aspect of the present application provides a device heartbeat interval control device, comprising:
[0032] A first determination module is configured to obtain at least one reference heartbeat value from a server, and determine a first heartbeat interval according to the at least one reference heartbeat value, wherein the at least one reference heartbeat value at least includes a reference heartbeat minimum value, and the reference heartbeat minimum value is a minimum heartbeat interval value of the device preset by the server;
[0033] A second determination module is used to determine a current target working state, where the target working state is one of a plurality of working states, where the plurality of working states at least include a working state with user operation and a working state without user operation;
[0034] A detection module is used to determine a second heartbeat interval in the target working state based on the first heartbeat interval and the reference heartbeat minimum value, and send a heartbeat packet to the server at the second heartbeat interval, wherein the second heartbeat interval in the working state with user operation is smaller than the second heartbeat interval in the working state without user operation.
[0035] Optionally, the at least one reference heartbeat value further includes a reference heartbeat maximum value, where the reference heartbeat maximum value is a maximum value of heartbeat intervals of other devices connected to the server and within the same area as the IoT device; the first determination module is specifically configured to:
[0036] Taking the reference heartbeat minimum value as the detection starting point, calculating the detection heartbeat interval according to the preset first increase value of the arithmetic progression, and using the detection heartbeat interval to detect the server;
[0037] Until the detection of the detection heartbeat interval is successful and the next detection heartbeat interval is greater than the reference heartbeat maximum value, the detection heartbeat interval is determined to be the first heartbeat interval, wherein the reference heartbeat maximum value is included in the at least one reference heartbeat value, and the reference heartbeat maximum value is the maximum value of the heartbeat intervals of other devices connected to the server and within the same area as the Internet of Things device; or, until the detection of the detection heartbeat interval fails, the detection heartbeat interval before the detection failure is determined as the first heartbeat interval.
[0038] Optionally, the at least one reference heartbeat value further includes a reference heartbeat maximum value and an average heartbeat value, the reference heartbeat maximum value is the maximum value of the heartbeat intervals of other devices connected to the server and within the same area as the IoT device, and the average heartbeat value is an average value calculated by the server based on the heartbeat values of other devices within the same area as the IoT device and using the same operator network;
[0039] The first determining module is specifically used for:
[0040] The average heartbeat value is used as a detection starting point, based on the reference heartbeat maximum value and the reference heartbeat minimum value, a binary search method is used to perform the heartbeat interval detection operation on the server to determine the first heartbeat interval.
[0041] Optionally, the at least one reference heartbeat value further includes a reference heartbeat maximum value, where the reference heartbeat maximum value is a maximum value among heartbeat intervals of other devices connected to the server and within the same area as the IoT device;
[0042] The first determining module is specifically used for:
[0043] Determine the increase value corresponding to the current number of detections according to a preset first mapping relationship between the number of detections and the increase value; take the reference heartbeat minimum value as the detection starting point, calculate the detection heartbeat interval according to the increase value corresponding to the current number of detections, and use the detection heartbeat interval to detect the server, wherein the number of detections in the first mapping relationship is positively correlated with the increase value;
[0044] When the current detection heartbeat interval is detected successfully, and the next detection heartbeat interval of the current detection heartbeat interval is greater than the difference between the reference heartbeat maximum value and the reference heartbeat minimum value, determine the increase value corresponding to the current detection number of times according to a preset second mapping relationship between the number of detections and the increase value, take the current detection heartbeat interval as the detection starting point, calculate the detection heartbeat interval according to the increase value corresponding to the current detection number of times, use the detection heartbeat interval to detect the server, and the detection number of times in the second mapping relationship is negatively correlated with the increase value;
[0045] Until the detection of the detection heartbeat interval is successful, and the detection heartbeat interval is not greater than the reference heartbeat maximum value, and the next detection heartbeat interval of the detection heartbeat interval is greater than the reference heartbeat maximum value, the detection heartbeat interval is determined to be the first heartbeat interval; or, until the detection of the detection heartbeat interval fails, the detection heartbeat interval before the detection failure is determined to be the first heartbeat interval.
[0046] Optionally, the first determining module is further configured to:
[0047] When the detection of the detection heartbeat interval is successful and the next detection heartbeat interval of the detection heartbeat interval is greater than the reference heartbeat maximum value, the detection heartbeat interval is calculated according to the current detection heartbeat interval and the preset second increase value of the arithmetic progression;
[0048] The server is detected using the detection heartbeat interval until the detection of the detection heartbeat interval succeeds and the detection of the next detection heartbeat interval of the detection heartbeat interval fails, then the detection heartbeat interval is determined to be the first heartbeat interval.
[0049] Optionally, the first determining module is further used for:
[0050] In the case of detection failure, the detection heartbeat interval is calculated according to the previous detection heartbeat interval of the current detection heartbeat interval and the preset third increase value of the arithmetic progression, and the detection heartbeat interval is greater than the current detection heartbeat interval;
[0051] The server is detected using the detection heartbeat interval until the detection of the detection heartbeat interval is successful and the next detection heartbeat interval of the detection heartbeat interval is greater than the reference heartbeat maximum value, and the detection heartbeat interval of successful detection is determined as the first heartbeat interval; or until the detection of the detection heartbeat interval fails, the detection heartbeat interval before the detection failure is determined as the first heartbeat interval.
[0052] Optionally, the second determining module is specifically configured to:
[0053] When a user operation is detected, determining that the target working state is a first-level heartbeat state;
[0054] When it is detected that the duration of no user operation reaches a first preset duration, determining that the target working state is a second-level heartbeat state;
[0055] In the case where it is detected that the duration without user operation reaches a second preset duration, determining that the target working state is a third-level heartbeat state, wherein the second preset duration is greater than the first preset duration, the heartbeat interval corresponding to the first-level heartbeat state is less than the heartbeat interval corresponding to the second-level heartbeat state, and the heartbeat interval corresponding to the second-level heartbeat state is less than the heartbeat interval corresponding to the third-level heartbeat state;
[0056] The detection module is also used for:
[0057] The Internet of Things device obtains a heartbeat calculation rule corresponding to the target working state;
[0058] A second heartbeat interval under the target working state is obtained by calculation according to the first heartbeat interval, the reference heartbeat minimum value and a heartbeat calculation rule corresponding to the target working state.
[0059] A third aspect of the present application provides an Internet of Things device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the steps of the first aspect and any possible implementation thereof.
[0060] To achieve the above-mentioned purpose, the fourth aspect of the present application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the processor executes the various steps in the method described in the first aspect.
[0061] The present application provides a device heartbeat interval control method, which is applied to an Internet of Things device, wherein the Internet of Things device obtains at least one reference heartbeat value from a server, and determines a first heartbeat interval according to the at least one reference heartbeat value, wherein the at least one reference heartbeat value at least includes a reference heartbeat minimum value, and the reference heartbeat minimum value is a device heartbeat interval minimum value preset by the server; the Internet of Things device determines a current target working state, wherein the target working state is one of a plurality of working states, and the plurality of working states at least include a working state with user operation and a working state without user operation; the Internet of Things device determines a second heartbeat interval under the target working state according to the first heartbeat interval and the reference heartbeat minimum value, and sends a heartbeat packet to the server at the second heartbeat interval, and can dynamically adjust the long connection heartbeat of the Internet of Things device according to the working state of the Internet of Things device, thereby ensuring the communication efficiency between the Internet of Things device and the server, reducing the processing pressure of the Internet of Things server caused by the heartbeat packet, and reducing the power consumption of the device caused by the heartbeat. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0063] in:
[0064] Figure 1 A schematic diagram of a flow chart of a device heartbeat interval control method provided in an embodiment of the present application;
[0065] Figure 2 A schematic diagram of a network system structure provided in an embodiment of the present application;
[0066] Figure 3 A flowchart of another device heartbeat interval control method provided in an embodiment of the present application;
[0067] Figure 4 A schematic diagram of an increase value curve of an enhanced arithmetic progression provided in an embodiment of the present application;
[0068] Figure 5 A schematic diagram of the structure of a device heartbeat interval control device provided in an embodiment of the present application;
[0069] Figure 6 A schematic diagram of the structure of an Internet of Things device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0070] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0071] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
[0072] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0073] The heartbeat mentioned in the embodiments of the present application refers to the periodic sending of information between the main server and each device in the monitoring of industrial equipment to determine the health status, connection status, etc. of the equipment and whether the other party is "alive".
[0074] A short connection means that when the two communicating parties have data exchange, a connection is established. After the data is sent, the connection is disconnected, that is, each connection only completes the sending of one business.
[0075] The long connection mentioned in the embodiments of the present application refers to the continuous sending of multiple data packets on a connection. During the connection maintenance period, if no data packet is sent, both parties need to send a link detection packet. It is mostly used for frequent operations and point-to-point communication. Transmission Control Protocol (TCP) is a connection-oriented, reliable, byte stream-based transport layer communication protocol.
[0076] The embodiments of the present application are described below in conjunction with the drawings in the embodiments of the present application.
[0077] See also Figure 1, is a flow chart of a device heartbeat interval control method in an embodiment of the present application, such as Figure 1 As shown, the method includes:
[0078] 101. The IoT device obtains at least one reference heartbeat value from a server, and determines a first heartbeat interval according to the at least one reference heartbeat value, wherein the at least one reference heartbeat value includes at least a reference heartbeat minimum value, and the reference heartbeat minimum value is a minimum heartbeat interval value of the device preset by the server.
[0079] The execution subject in the embodiment of the present application may be an electronic device, which may be connected to a server for data communication. Specifically, the electronic device may be an Internet of Things device. Figure 2 A schematic diagram of a network system structure provided for this application, such as Figure 2 As shown, the terminal device (mobile phone) can interact with the cloud server through the client application (APP), and a long connection is established between the IoT device and the cloud server through the network protocol. The IoT device can determine and adjust the heartbeat interval based on at least one reference heartbeat value provided by the server.
[0080] In the embodiment of the present application, the server can record the device identification (number) connected to it, the area range of the device, and the network type (such as the operator network). For example, Table 1 is a server connected device information table provided in the embodiment of the present application. As shown in Table 1, the server currently connects to five devices, namely D1-D5, and records the district and county where the device is located and the operator used.
[0081] Equipment No. District and county where the equipment is located Operators D1 Yubei District move D2 Yubei District move D3 Yubei District telecommunications D4 Yuzhong District move D5 Jiangbei District China Unicom
[0082] Table 1
[0083] Specifically, the device can perform a heartbeat interval detection on the server, and can send a heartbeat packet to the server to determine the detection result based on whether a corresponding reply is received. The device can report the detection result to the server, and the server can also record the heartbeat interval of each of the above devices accordingly.
[0084] In the embodiment of the present application, the above-mentioned reference heartbeat minimum value is the minimum heartbeat interval of the device preset by the server, and optionally, the reference heartbeat minimum value is the minimum heartbeat value that the server can bear. The determined first heartbeat interval is not less than the above-mentioned reference heartbeat minimum value.
[0085] With respect to step 101, a heartbeat interval detection operation is performed on the server with the reference heartbeat minimum value as the detection starting point to determine the first heartbeat interval.
[0086] For example, the minimum reference heartbeat value is 5 seconds (s), step = 2s, and the device detection value each time is:
[0087] x=5+2=7s,
[0088] x=5+2+2=9s,
[0089] x=5+2+2+2=11s,
[0090] ...and so on.
[0091] Until the first detection fails, the x corresponding to the last successful detection before the detection failure is the first heartbeat interval.
[0092] In order to simplify the processing of decimal points in the algorithm of this application, the decimals can be discarded and integers can be obtained.
[0093] A. In another possible embodiment, at least one reference heartbeat value also includes a reference heartbeat maximum value. The reference heartbeat maximum value involved in the embodiment of the present application is the maximum value of the heartbeat interval of other devices connected to the server and in the same area as the device to be subjected to the heartbeat interval detection operation. The detected maximum heartbeat can be reported to the server by each device, and then calculated by the server. For example, based on Table 1, at this time, device D6 (Yubei District Mobile) is connected to the server, and the obtained reference heartbeat maximum value maxHeartInS = max(D1, D2, D3).
[0094] (1) In one embodiment, determining the first heartbeat interval according to at least one reference heartbeat value may include:
[0095] 011. Taking the minimum reference heartbeat value as the detection starting point, calculating the detection heartbeat interval according to the preset first increase value of the arithmetic progression, and using the detection heartbeat interval to detect the server;
[0096] 012. Until the above-mentioned detection heartbeat interval is detected successfully and the next detection heartbeat interval is greater than the above-mentioned reference heartbeat maximum value, the above-mentioned detection heartbeat interval is determined to be the above-mentioned first heartbeat interval; or, until the above-mentioned detection heartbeat interval fails to be detected, the detection heartbeat interval before the detection failure is determined to be the above-mentioned first heartbeat interval.
[0097] An arithmetic sequence is a sequence in which the difference between each term and its previous term from the second term onwards is equal to the same constant. This constant is called the tolerance of the arithmetic sequence. The preset first increase value of the above arithmetic sequence is the tolerance, through which multiple detection values form an arithmetic sequence. Specifically, let the preset first increase value be step, and the minimum reference heartbeat value be minHeartInS. Then the device can perform detection each time with a fixed length or an arithmetic sequence currHeartInS=minHeartInS+n*step, where n represents the nth detection.
[0098] For example, the minimum reference heartbeat value is 5s, the maximum reference heartbeat value is 60s, step = 2s, and the device detection value each time is:
[0099] x=5+2=7s,
[0100] x=5+2+2=9s,
[0101] x=5+2+2+2=11s,
[0102] One situation is: until the detection of the heartbeat interval is successful, and the next detection heartbeat interval is greater than the above-mentioned reference heartbeat maximum value, due to the limitation of the reference heartbeat maximum value, the detection heartbeat interval that meets the above conditions is determined as the first heartbeat interval; another situation is: until the detection of the heartbeat interval fails, the detection heartbeat interval before the detection failure is determined as the first heartbeat interval.
[0103] ...and so on.
[0104] In order to simplify the processing of decimal points in the algorithm of this application, the decimals can be discarded and integers can be obtained.
[0105] B. In an optional implementation, the at least one reference heartbeat value further includes the reference heartbeat maximum value and the average heartbeat value, and the average heartbeat value is the average value calculated by the server based on the heartbeat values of other devices in the same area as the IoT device and using the same operator network. Optionally, the heartbeat value of other devices can be the heartbeat value of the other devices currently detected successfully, or can be the maximum heartbeat value of other devices, etc., which is not limited in this embodiment of the present application.
[0106] (1) In one implementation, step 101 includes:
[0107] 021. Taking the above average heartbeat value as the detection starting point, based on the above reference heartbeat maximum value and the above reference heartbeat minimum value, adopt the binary search method to perform the above heartbeat interval detection operation on the above server to determine the above first heartbeat interval.
[0108] Based on the example in Table 1, at this time, device D6 (Yubei District Mobile) is connected to the server, and the average heartbeat value avgHeartInS obtained is = (D1+D2) / 2.
[0109] Specifically, the device can start detection from the average heartbeat value, and perform binary detection based on the reference heartbeat maximum value and the reference heartbeat minimum value. It can be understood that each time the new detection heartbeat interval is determined, each change interval [min, max] can be determined based on the previous detection situation or the obtained average heartbeat value, the reference heartbeat minimum value and the reference heartbeat maximum value, that is, based on [min, max], each time processing:
[0110] For upward direction, x=min+(max-min) / 2 is used, and max is kept unchanged while min increases dynamically.
[0111] Use x=max-(max-min) / 2 downward, keep min unchanged downward, and increase max dynamically;
[0112] Among them, the detection starting point is the average heartbeat value. When the new detection heartbeat interval x is determined for the first time, the average heartbeat value is used as the minimum value min in the dichotomy, and the reference heartbeat maximum value is used as the maximum value max in the dichotomy, gradually approaching the detection result, that is, the first heartbeat interval MaxStableHeartInS.
[0113] Or it can be understood as:
[0114] Upward, x = minimum x of current successful detection + (maximum x of current successful detection - minimum x of current successful detection) / 2 is adopted; among which, for the first determination of a new detection heartbeat interval x: "minimum x of current successful detection" is the average heartbeat value, and "maximum x of current successful detection" is the reference heartbeat maximum value.
[0115] Downward, use x = maximum x of current successful detection - (maximum x of current successful detection - minimum x of current successful detection) / 2; among which, for the first determination of a new detection heartbeat interval x: "maximum x of current successful detection" is the average heartbeat value, and "minimum x of current successful detection" is the reference heartbeat minimum value.
[0116] For example, the current device obtains maxHeartInS=1000s, minHeartInS=100s, and avgHeartInS=400s from the server;
[0117] The detection started at 400s and was successful;
[0118] The detection was successful with x=400+(1000-400) / 2=700s;
[0119] The detection was carried out with x=700+(1000-700) / 2=850s, which was successful;
[0120] The detection was performed with x=850+(1000-850) / 2=925s, which was successful;
[0121] …
[0122] Until the new x<=maxHeartInS.
[0123] For another example, taking maxHeartInS = 1000s, minHeartInS = 100s, avgHeartInS = 400s as an example, the calculation is:
[0124] The detection started at 400s and was successful;
[0125] The detection was successful with x=400+(1000-400) / 2=700s;
[0126] The detection was performed with x=700+(1000-700) / 2=850s, which failed.
[0127] At this time, we only need to continue the detection from 700s after the last success to the current failure, that is, use maxHeartInS=850 to continue the calculation.
[0128] Success with x=700+(850-700) / 2=775s;
[0129] Success with x=775+(850-775) / 2=812s;
[0130] …and so on.
[0131] For another example, taking maxHeartInS = 1000s, minHeartInS = 100s, avgHeartInS = 400s as an example, the calculation is:
[0132] The detection started at 400s and failed;
[0133] Detection with x=400-(400-100) / 2=250s failed;
[0134] Detection with x=250-(250-100) / 2=175s failed;
[0135] The detection was successful with x=175-(175-100) / 2=137s;
[0136] At this time, use [137,175] to continue to increase the execution detection.
[0137] The first heartbeat interval can be determined through the above steps, and step 102 can be executed. In the embodiment of the present application, the IoT device can also determine the first heartbeat interval based on other reference heartbeat values and other set calculation rules, which is not limited here.
[0138] (2) In one embodiment, step 101 includes:
[0139] The device may start detection from a reference heartbeat minimum value, and perform binary detection based on a reference heartbeat maximum value, an average heartbeat value, and a reference heartbeat minimum value.
[0140] Specifically, the interval may be divided into a first interval - [reference minimum heartbeat value, average heartbeat value], and a second interval - [average heartbeat value, reference maximum heartbeat value]. In one case, binary detection may be performed on the first interval first, and when the first interval satisfies a preset number of detection successes (or consecutive preset number of detection successes), binary detection may be performed on the second interval; or in another case, binary detection may be performed on the second interval first, and when the second interval satisfies a preset number of detection failures (or consecutive preset number of detection failures), binary detection may be performed on the first interval.
[0141] Optionally, if detection fails, or a preset number of detection failures occur, or a preset number of detection failures occur continuously within an interval with a smaller value, detection will not be performed on the interval with a larger value; similarly, if detection succeeds, or a preset number of detection successes occur, or a preset number of detection successes occur continuously within an interval with a larger value, detection will not be performed on the interval with a smaller value.
[0142] Similarly, for example, the current device obtains maxHeartInS=1000s, minHeartInS=100s, and avgHeartInS=400s from the server;
[0143] Start detection with 100s, success;
[0144] Detection with x=100+(400-100) / 2=250s failed;
[0145] Detection with x=250-(250-100) / 2=175s failed;
[0146] The detection was successful with x=175-(175-100) / 2=137s;
[0147] At this time, [137,175] is used to continue to increase the detection. The detection can be stopped until the maximum value of successful detection is determined within 400s, and the maximum value of successful detection is the first heartbeat interval. In this example, the detection does not need to be performed for the interval [400,1000].
[0148] For example, the current device obtains maxHeartInS=1000s, minHeartInS=100s, and avgHeartInS=400s from the server;
[0149] Start detection with 100s, success;
[0150] Detection was successful with x=100+(400-100) / 2=250s;
[0151] Detection with x=250+(400-250) / 2=325s failed;
[0152] The detection was successful with x=325-(400-325) / 2=287s;
[0153] The detection was successful with x=287+(400-287) / 2=230s;
[0154] At this time, [230,287] is used to continue to increase the detection. The detection can be stopped when the maximum value of successful detection appears within 400s, and the maximum value of successful detection is the first heartbeat interval.
[0155] For example, the current device obtains maxHeartInS=1000s, minHeartInS=100s, and avgHeartInS=400s from the server;
[0156] Start detection with 100s, success;
[0157] Detection was successful with x=100+(400-100) / 2=250s;
[0158] Detection was successful with x=250+(400-250) / 2=325s;
[0159] Because there have been a preset number of successes within the interval of [reference heartbeat minimum value, average heartbeat value], detection can continue in a larger interval, that is, continue to detect within the interval of [average heartbeat value, reference heartbeat maximum value]; this application does not limit the above preset number of times.
[0160] Start the detection at 400s; if successful, continue the detection according to the minimum bisection method in the interval [400,1000], which will not be described here; if failed, continue the detection according to the minimum bisection method in the interval [325,400], which will not be described here. Then, use [230,287] to continue to increase the detection until the first heartbeat interval is determined.
[0161] 102. The IoT device determines a current target working state, where the target working state is one of a plurality of working states, and the plurality of working states at least include a working state with user operation and a working state without user operation.
[0162] Specifically, the heartbeat can be graded according to the working state of the IoT device, and different heartbeat intervals can be used in different working states. Generally, the more frequently the device works, the smaller the heartbeat interval is, which can better maintain data communication. The more idle the device is, the larger the heartbeat interval is, which can reduce overhead. Specifically, it can be detected whether the IoT device is in a working state with user operation or a working state without user operation. After determining the working state of the IoT device, step 103 can be executed to select the corresponding heartbeat interval.
[0163] 103. The IoT device determines a second heartbeat interval in the target working state based on the first heartbeat interval and the minimum reference heartbeat value, and sends a heartbeat packet to the server at the second heartbeat interval, wherein the second heartbeat interval in the working state with user operation is smaller than the second heartbeat interval in the working state without user operation.
[0164] After determining the working state of the IoT device, the IoT device may determine a second heartbeat interval under the target working state according to the first heartbeat interval and the reference heartbeat minimum value, and send a heartbeat packet to the server at the second heartbeat interval.
[0165] Through the above steps, a reasonable second heartbeat interval MaxStableHeartInS can be detected, and the TCP connection between the control device and the server can use the second heartbeat interval. Each time the device detects the second heartbeat interval, it reports it to the server, and the server can calculate based on the new data to update the corresponding reference heartbeat value.
[0166] Optionally, the above heartbeat interval detection operation adopts the first TCP connection;
[0167] The sending of the heartbeat packet to the server at the second heartbeat interval specifically includes:
[0168] A heartbeat packet is sent to the server via a second TCP connection at a second heartbeat interval.
[0169] In the embodiment of the present application, the above-mentioned heartbeat interval detection operation can use a separate TCP connection, and does not interfere with the TCP connection controlled by the normal device. That is, at least two TCP connections are used between the Internet of Things device and the server. The first TCP connection is used for the above-mentioned heartbeat interval detection operation, and a default heartbeat packet can be sent for detection, such as sending a default ping packet; the second TCP connection is used for normal communication, and a second heartbeat packet is sent for normal communication, such as a ping packet triggered by a different application layer; after the first TCP connection determines the optimal heartbeat interval (i.e., the above-mentioned second heartbeat interval), the second TCP connection can use the optimal heartbeat interval for communication. Using two TCP connections, the Internet of Things device can always maintain a connection with the server without disconnection and reconnection.
[0170] Specifically, when the IoT device uses the first TCP connection to detect the heartbeat interval, it communicates with the server through the first TCP connection at a heartbeat interval a1; if the first TCP connection between the IoT device and the server is not disconnected, the above scheme is used to continue to detect the optimal heartbeat interval (equivalent to determining the first heartbeat interval).
[0171] Specifically, if the first TCP between the device and the server is not disconnected, the heartbeat interval is increased by a predetermined value based on the current heartbeat interval, and the heartbeat interval is increased to reduce the processing pressure of the IoT server due to the heartbeat packet, and at the same time, the power consumption of the device due to the heartbeat can be reduced. If the first TCP is disconnected, it means that under the current network state, the IoT device and the server cannot communicate at a value higher than the recommended value of the heartbeat interval, otherwise the communication will be unsmooth, and because a too low heartbeat interval will cause a heavier load on the server, it is possible to continue to communicate with the server at the recommended value of the heartbeat interval.
[0172] It should be noted that after the first TCP connection is disconnected, the first TCP connection is re-established according to a standard process to start a new heartbeat interval detection operation.
[0173] In an optional implementation, if device resources are limited and a new TCP connection cannot be opened for detection, a long connection (only one TCP connection is established) for data communication with the server can be used for detection, and the detection algorithm starts with minHeartInS.
[0174] Optionally, in one implementation, the above heartbeat interval detection operation may include:
[0175] Send at least two heartbeat packets to the above server;
[0176] When a reply of at least one of the at least two heartbeat packets is received, the detection is successful; when a reply of the at least two heartbeat packets is not received, the detection fails.
[0177] One or more heartbeat packets can be sent during each detection. For example, the IoT device sends two heartbeat packets. As long as any one of the heartbeat packets receives a reply from the server, the detection is considered successful, which can prevent jitter to a certain extent.
[0178] Further optionally, the above step 102 includes:
[0179] When the IoT device detects a user operation, it determines that the target working state is a first-level heartbeat state;
[0180] The IoT device determines that the target working state is the second-level heartbeat state when detecting that the duration of no user operation reaches a first preset duration;
[0181] When the IoT device detects that the duration without user operation reaches a second preset duration, it determines that the target working state is a third-level heartbeat state, wherein the second preset duration is greater than the first preset duration, the heartbeat interval corresponding to the first-level heartbeat state is less than the heartbeat interval corresponding to the second-level heartbeat state, and the heartbeat interval corresponding to the second-level heartbeat state is less than the heartbeat interval corresponding to the third-level heartbeat state;
[0182] The above step 103 includes:
[0183] The IoT device obtains the heartbeat calculation rule corresponding to the target working state;
[0184] According to the first heartbeat interval, the reference heartbeat minimum value and the heartbeat calculation rule corresponding to the target working state, a second heartbeat interval under the target working state is calculated and obtained.
[0185] Specifically, the current working state of the device can be determined according to the user's operation on the IoT device, and then a reasonable device heartbeat can be determined, that is, the level of heartbeat interval used by the device can be determined according to the user's operation. Generally, the more frequent the user operation, the smaller the heartbeat interval. The above-mentioned preset durations and heartbeat calculation rules under different levels of working states can be set as needed, and the embodiments of the present application do not limit this, nor do they limit the number of division levels.
[0186] For example, you can set the heartbeat calculation rules for different levels of working status as follows:
[0187] Excellent level: minHeartInS+((MaxStableHeartInS-minHeartInS) / 3)
[0188] Good level: minHeartInS+2*((MaxStableHeartInS-minHeartInS) / 3)
[0189] Medium level: first heartbeat interval MaxStableHeartInS
[0190] When the user operates, enter: Excellent level heartbeat value;
[0191] When the user has no operation for 30 minutes: Good level heartbeat value;
[0192] When the user has no operation for 60 minutes, the heartbeat value of the Medium level is entered.
[0193] Through the above steps, you can select the heartbeat level according to the current working status of the device and use a reasonable heartbeat interval. During user operation, the device uses a smaller heartbeat interval to better maintain data communication. The longer the user does not operate, the larger the heartbeat interval the device can use, which can reduce device power consumption and server pressure.
[0194] At present, the heartbeat time of IoT devices connected to the server is fixed. Device heartbeats cause high server pressure and network transmission overhead, and the device consumes a lot of power. The device heartbeat interval control method in this application can dynamically adjust the long connection heartbeat between the IoT device and the server according to user usage and settings, as well as the adaptive heartbeat algorithm, to reduce the processing pressure of the IoT server caused by the heartbeat packet, while reducing the power consumption of the device caused by the heartbeat.
[0195] The present application provides a device heartbeat interval control method, which is applied to an Internet of Things device, wherein the Internet of Things device obtains at least one reference heartbeat value from a server, and determines a first heartbeat interval according to the at least one reference heartbeat value, wherein the at least one reference heartbeat value at least includes a reference heartbeat minimum value, and the reference heartbeat minimum value is a device heartbeat interval minimum value preset by the server; the Internet of Things device determines a current target working state, wherein the target working state is one of a plurality of working states, and the plurality of working states at least include a working state with user operation and a working state without user operation; the Internet of Things device determines a second heartbeat interval in the target working state according to the first heartbeat interval and the reference heartbeat minimum value, and sends a heartbeat packet to the server at the second heartbeat interval, wherein the second heartbeat interval in the working state with user operation is smaller than the second heartbeat interval in the working state without user operation, and the long connection heartbeat can be dynamically adjusted according to the working state of the Internet of Things device, so as to ensure the communication efficiency between the Internet of Things device and the server, reduce the processing pressure of the Internet of Things server caused by the heartbeat packet, and reduce the power consumption of the device caused by the heartbeat.
[0196] See also Figure 3 , Figure 3 A flow chart of another device heartbeat interval control method provided in an embodiment of the present application. Figure 3 As shown, the method can be applied to an IoT device, and the method may include:
[0197] 301. The IoT device obtains at least one reference heartbeat value from a server, where the at least one reference heartbeat value includes at least a minimum reference heartbeat value and a maximum reference heartbeat value.
[0198] The above step 301 can refer to Figure 1 The specific description of step 101 in the illustrated embodiment will not be repeated here.
[0199] 302. According to a first mapping relationship between a preset number of detection times and an increase value, determine the increase value corresponding to the current number of detection times, take the above-mentioned reference heartbeat minimum value as the detection starting point, calculate the detection heartbeat interval according to the increase value corresponding to the above-mentioned current number of detection times, use the above-mentioned detection heartbeat interval to detect the above-mentioned server, and in the above-mentioned first mapping relationship, the above-mentioned detection times and the above-mentioned increase value are positively correlated.
[0200] In the embodiment of the present application, a first mapping relationship between the number of detections and the increase value can be preset, that is, each detection increases a value based on the last detection value, and then detection is performed. In the first mapping relationship, the number of detections and the increase value are positively correlated, that is, as the number of detections increases, the increase value each time based on the last detection value is also greater, so as to reduce the number of detections and quickly approach the target.
[0201] 303. When the current detection heartbeat interval is detected successfully and the next detection heartbeat interval of the above-mentioned current detection heartbeat interval is greater than the difference between the above-mentioned reference heartbeat maximum value and the above-mentioned reference heartbeat minimum value, determine the increase value corresponding to the current detection number of times according to the second mapping relationship between the preset detection number of times and the increase value, take the above-mentioned current detection heartbeat interval as the detection starting point, calculate the above-mentioned detection heartbeat interval according to the increase value corresponding to the above-mentioned current detection number, use the above-mentioned detection heartbeat interval to detect the above-mentioned server, and the above-mentioned detection number and the above-mentioned increase value in the above-mentioned second mapping relationship are negatively correlated.
[0202] Specifically, in the initial stage, detection can be performed according to step 302; when the current detection heartbeat interval is successfully detected, and the next detection heartbeat interval of the current detection heartbeat interval is greater than the difference between the reference heartbeat maximum value and the reference heartbeat minimum value, the second stage can be entered, and another detection value increase method can be adopted. A second mapping relationship between the number of detections and the increase value can be pre-set, and the number of detections and the increase value in the second mapping relationship are negatively correlated, that is, as the number of detections increases, the increase value is reduced each time based on the previous detection value, so as to reduce the increase in the detection value and better approach the target.
[0203] 304. Until the detection of the above-mentioned detection heartbeat interval is successful, and the above-mentioned detection heartbeat interval is not greater than the above-mentioned reference heartbeat maximum value, and the next detection heartbeat interval of the above-mentioned detection heartbeat interval is greater than the above-mentioned reference heartbeat maximum value, then the above-mentioned detection heartbeat interval is determined to be the above-mentioned first heartbeat interval; or, until the detection of the above-mentioned detection heartbeat interval fails, then the detection heartbeat interval before the detection failure is determined to be the above-mentioned first heartbeat interval.
[0204] In the above two-stage detection process, if any of the following situations occurs, the detection ends: the first situation is until the heartbeat interval detection is successful, and the current detection heartbeat interval is not greater than the reference heartbeat maximum value, and the next detection value is greater than the reference heartbeat maximum value; the second situation is until the detection of the detection heartbeat interval fails, then the detection heartbeat interval before the detection failure is determined as the first heartbeat interval. The first heartbeat interval can be determined.
[0205] The above method is a method for increasing the detection value of an enhanced arithmetic progression. Figure 4 A schematic diagram of an increased value curve of an enhanced arithmetic progression provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, the horizontal axis represents the number of detections, and the vertical axis represents the increase in the detection heartbeat interval corresponding to each detection. It can be seen that the increase in the detection heartbeat interval first increases and then decreases, which further improves the detection efficiency compared to the traditional arithmetic sequence. In addition, the increment of the boundary value is reduced to remove the boundary effect.
[0206] In an optional implementation, after the above step 303, the first case can also be replaced by the following solution:
[0207] When the detection of the detection heartbeat interval is successful and the next detection heartbeat interval of the above detection heartbeat interval is greater than the above reference heartbeat maximum value, the above detection heartbeat interval is calculated according to the above current detection heartbeat interval and the preset second increase value of the arithmetic progression;
[0208] The server is detected using the detection heartbeat interval until the detection of the detection heartbeat interval succeeds and the detection of the next detection heartbeat interval of the detection heartbeat interval fails, then the detection heartbeat interval is determined to be the first heartbeat interval.
[0209] Specifically, in the initial stage, detection can be performed according to step 302, and in the second stage, detection can be performed according to step 303; and when the detection of the detection heartbeat interval is successful, and the next detection heartbeat interval of the above detection heartbeat interval is greater than the above reference heartbeat maximum value, the third stage can be entered, and the detection value is increased by an arithmetic progression to continue the detection. At this time, the tolerance of the arithmetic progression, that is, the preset second increase value, is smaller and not greater than the minimum detection value increase value of the second stage. Among them, the above steps can refer to Figure 1 The specific description of step 022 in the illustrated embodiment will not be repeated here.
[0210] As the number of detections increases, the detection value may be increased by a smaller fixed value each time, which may further approach the maximum heartbeat interval that the device may adopt.
[0211] The method for calculating the detection value in the embodiment of the present application is a method of enhancing arithmetic progression. On the basis of the above-mentioned embodiment, the minimum reference heartbeat value obtained by the current device is 5s, the maximum reference heartbeat value is 60s, step=2s, (maxHeartInS-minHeartInS) / 2=27s, then the detection value of the device each time is:
[0212] x = 5 + 2 = 7s;
[0213] x = 5 + 2 + 3 = 10s;
[0214] x=5+2+3+4=14s;
[0215] x=5+2+3+4+5=19s;
[0216] x=5+2+3+4+5+6=25s;
[0217] x=5+2+3+4+5+6+7=32s, at this time 32>27, so the increase value begins to decrease;
[0218] x=5+2+3+4+5+6+7+7=39s (the increase is 7);
[0219] x=5+2+3+4+5+6+7+7+6=45s (the increase is 6);
[0220] x=5+2+3+4+5+6+7+7+6+5=50s (the increase is 5);
[0221] x=5+2+3+4+5+6+7+7+6+5+4=54s (the increase is 4);
[0222] x=5+2+3+4+5+6+7+7+6+5+4+3=57s (the increase is 3);
[0223] x=5+2+3+4+5+6+7+7+6+5+4+2=59s (the increase is 2);
[0224] x=5+2+3+4+5+6+7+7+6+5+4+2+2=61s, at this time 60> the maximum value 60, and the increments are all set to the preset value 2;
[0225] x=5+2+3+4+5+6+7+7+6+5+4+2+2+2=63s;
[0226] x=5+2+3+4+5+6+7+7+6+5+4+2+2+2+2=65s.
[0227] In an optional implementation, after step 303, the second situation can also be replaced by the following scheme: in the case of detection failure, the detection heartbeat interval is calculated according to the previous detection heartbeat interval of the current detection heartbeat interval and the preset third increase value of the arithmetic progression, and the detection heartbeat interval is greater than the current detection heartbeat interval;
[0228] The above-mentioned detection heartbeat interval is used to detect the above-mentioned server until the above-mentioned detection heartbeat interval is successfully detected, and the next detection heartbeat interval of the above-mentioned detection heartbeat interval is greater than the above-mentioned reference heartbeat maximum value, and the above-mentioned detection heartbeat interval with successful detection is determined to be the above-mentioned first heartbeat interval; or until the above-mentioned detection heartbeat interval fails to detect, the detection heartbeat interval before the detection failure is determined to be the above-mentioned first heartbeat interval.
[0229] Based on the above embodiment, for example, if a detection failure occurs, the following is performed:
[0230] x = 5 + 2 = 7s;
[0231] x = 5 + 2 + 3 = 10s;
[0232] x=5+2+3+4=14s;
[0233] x=5+2+3+4+5=19s;
[0234] x=5+2+3+4+5+6=25s;
[0235] x=5+2+3+4+5+6+7=32s, at this time 32>27, so the increase value begins to decrease;
[0236] x=5+2+3+4+5+6+7+7=39s;
[0237] x=5+2+3+4+5+6+7+7+6=45s, if the detection fails, the last successful detection value plus the preset value 2 is used;
[0238] x=5+2+3+4+5+6+7+7+2=41s;
[0239] x=5+2+3+4+5+6+7+7+2+2=43s;
[0240] x=5+2+3+4+5+6+7+7+2+2+2=45s. At this time, 45 is the value of detection failure, so the first heartbeat interval is 43.
[0241] In one embodiment, the device can actively send the heartbeat detection start time, and the detection interval can be pre-set as needed, such as 15 minutes for each detection interval. The device can perform adaptive heartbeat adjustment, that is, the operation of any device can be perceived by the device, and switching can be performed when the new heartbeat interval is determined by detection. The device can trigger re-detection in the case of network disconnection, reconnection, power-on, etc., and each detection can re-acquire the latest reference heartbeat maximum value, reference heartbeat minimum value, and average heartbeat value from the server.
[0242] Based on the description of the device heartbeat interval control method embodiment, the present application embodiment also discloses a device heartbeat interval control device, see Figure 5 , the device heartbeat interval control device 500 comprises:
[0243] A first determination module 510 is configured to obtain at least one reference heartbeat value from a server, and determine a first heartbeat interval according to the at least one reference heartbeat value, wherein the at least one reference heartbeat value at least includes a reference heartbeat minimum value, and the reference heartbeat minimum value is a minimum heartbeat interval value of a device preset by the server;
[0244] A second determination module 520 is used to determine a current target working state, where the target working state is one of a plurality of working states, where the plurality of working states at least include a working state with user operation and a working state without user operation;
[0245] The detection module 530 is used to determine the second heartbeat interval in the target working state based on the first heartbeat interval and the reference heartbeat minimum value, and send a heartbeat packet to the server at the second heartbeat interval, wherein the second heartbeat interval in the working state with user operation is smaller than the second heartbeat interval in the working state without user operation.
[0246] Understandably, this involves Figure 5 The relevant contents of each module in the above method embodiment have been described in detail. For details, please refer to the contents in the method embodiment, which will not be repeated here.
[0247] The device heartbeat interval control device 500 in the embodiment of the present application can obtain at least one reference heartbeat value from the server, determine a first heartbeat interval according to the at least one reference heartbeat value, the at least one reference heartbeat value at least includes a reference heartbeat minimum value, and the reference heartbeat minimum value is a device heartbeat interval minimum value preset by the server; determine a current target working state, the target working state is one of a plurality of working states, and the plurality of working states at least include a working state with user operation and a working state without user operation; determine a second heartbeat interval under the target working state according to the first heartbeat interval and the reference heartbeat minimum value, and send a heartbeat packet to the server at the second heartbeat interval, so as to dynamically adjust the long connection heartbeat of the IoT device according to the working state of the IoT device, reduce the processing pressure of the IoT server due to the heartbeat packet, and reduce the power consumption of the device due to the heartbeat.
[0248] In one embodiment of the present application, an Internet of Things device is also proposed. Figure 6 , Figure 6 This is a schematic diagram of the structure of an Internet of Things device provided in an embodiment of the present application. Figure 6 As shown, the IoT device 600 includes a processor 601 and a memory 602. The memory 602 stores a computer program. When the computer program is executed by the processor 601, the following operations are performed: Figure 1 or Figure 3 Any step in the method embodiment shown.
[0249] In one embodiment, a computer-readable storage medium is further provided. The computer-readable storage medium stores a computer program. When the computer program is executed by the processor 601, the processor 601 executes any step in the above method embodiment.
[0250] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0251] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0252] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A device heartbeat interval control method, characterized in that: Applied to an IoT device, the method comprises: The IoT device obtains at least one reference heartbeat value from the server, and determines a first heartbeat interval according to the at least one reference heartbeat value, wherein the at least one reference heartbeat value includes at least a reference heartbeat minimum value, and the reference heartbeat minimum value is a minimum heartbeat interval value of the device preset by the server; The IoT device determines a current target working state, where the target working state is one of a plurality of working states, and the plurality of working states at least include a working state with user operation and a working state without user operation; The IoT device determines, according to the first heartbeat interval and the reference heartbeat minimum value, a second heartbeat interval in the target working state, and sends a heartbeat packet to the server at the second heartbeat interval, wherein the second heartbeat interval in the working state under the user operation is smaller than the second heartbeat interval in the working state without the user operation; The IoT device determines the current target working state, including: When the Internet of Things device detects a user operation, it determines that the target working state is a first-level heartbeat state; when the Internet of Things device detects that the duration without user operation reaches a first preset duration, it determines that the target working state is a second-level heartbeat state; when the Internet of Things device detects that the duration without user operation reaches a second preset duration, it determines that the target working state is a third-level heartbeat state, wherein the second preset duration is greater than the first preset duration, the heartbeat interval corresponding to the first-level heartbeat state is smaller than the heartbeat interval corresponding to the second-level heartbeat state, and the heartbeat interval corresponding to the second-level heartbeat state is smaller than the heartbeat interval corresponding to the third-level heartbeat state.
2. The method according to claim 1, characterized in that: The determining a first heartbeat interval according to the at least one reference heartbeat value comprises: Taking the reference heartbeat minimum value as the detection starting point, calculating the detection heartbeat interval according to the preset first increase value of the arithmetic progression, and using the detection heartbeat interval to detect the server; Until the detection of the detection heartbeat interval is successful and the next detection heartbeat interval is greater than the reference heartbeat maximum value, the detection heartbeat interval is determined to be the first heartbeat interval, wherein the reference heartbeat maximum value is included in the at least one reference heartbeat value, and the reference heartbeat maximum value is the maximum value of the heartbeat intervals of other devices connected to the server and within the same area as the Internet of Things device; or, until the detection of the detection heartbeat interval fails, the detection heartbeat interval before the detection failure is determined as the first heartbeat interval.
3. The method according to claim 1, characterized in that: The at least one reference heartbeat value also includes a reference heartbeat maximum value and an average heartbeat value, wherein the reference heartbeat maximum value is the maximum value of the heartbeat intervals of other devices connected to the server and in the same area as the IoT device, and the average heartbeat value is the average value calculated by the server based on the heartbeat values of other devices in the same area as the IoT device and using the same operator network; The determining a first heartbeat interval according to the at least one reference heartbeat value comprises: The average heartbeat value is used as a detection starting point, based on the reference heartbeat maximum value and the reference heartbeat minimum value, a binary search method is used to perform the heartbeat interval detection operation on the server to determine the first heartbeat interval.
4. The method according to claim 1, characterized in that: The at least one reference heartbeat value also includes a reference heartbeat maximum value, where the reference heartbeat maximum value is a maximum value among heartbeat intervals of other devices connected to the server and within the same area as the IoT device; The determining a first heartbeat interval according to the at least one reference heartbeat value comprises: Determine the increase value corresponding to the current number of detections according to a preset first mapping relationship between the number of detections and the increase value; take the reference heartbeat minimum value as the detection starting point, calculate the detection heartbeat interval according to the increase value corresponding to the current number of detections, and use the detection heartbeat interval to detect the server, wherein the number of detections in the first mapping relationship is positively correlated with the increase value; When the current detection heartbeat interval is detected successfully, and the next detection heartbeat interval of the current detection heartbeat interval is greater than the difference between the reference heartbeat maximum value and the reference heartbeat minimum value, determine the increase value corresponding to the current detection number of times according to a preset second mapping relationship between the number of detections and the increase value, take the current detection heartbeat interval as the detection starting point, calculate the detection heartbeat interval according to the increase value corresponding to the current detection number of times, use the detection heartbeat interval to detect the server, and the detection number of times in the second mapping relationship is negatively correlated with the increase value; Until the detection of the detection heartbeat interval is successful, and the detection heartbeat interval is not greater than the reference heartbeat maximum value, and the next detection heartbeat interval of the detection heartbeat interval is greater than the reference heartbeat maximum value, the detection heartbeat interval is determined to be the first heartbeat interval; or, until the detection of the detection heartbeat interval fails, the detection heartbeat interval before the detection failure is determined to be the first heartbeat interval.
5. The method according to claim 4, characterized in that: The step of determining that the detection heartbeat interval is the first heartbeat interval until the detection of the detection heartbeat interval is successful, and the detection heartbeat interval is not greater than the reference heartbeat maximum value, and the next detection heartbeat interval of the detection heartbeat interval is greater than the reference heartbeat maximum value, comprises: When the detection of the detection heartbeat interval is successful and the next detection heartbeat interval of the detection heartbeat interval is greater than the reference heartbeat maximum value, the detection heartbeat interval is calculated according to the current detection heartbeat interval and the preset second increase value of the arithmetic progression; The server is detected using the detection heartbeat interval until the detection of the detection heartbeat interval succeeds and the detection of the next detection heartbeat interval of the detection heartbeat interval fails, then the detection heartbeat interval is determined to be the first heartbeat interval.
6. The method according to claim 4, characterized in that: The step of detecting the detection heartbeat interval until the detection fails, then determining the detection heartbeat interval before the detection failure as the first heartbeat interval, comprises: In the case of detection failure, the detection heartbeat interval is calculated according to the previous detection heartbeat interval of the current detection heartbeat interval and the preset third increase value of the arithmetic progression, and the detection heartbeat interval is greater than the current detection heartbeat interval; The server is detected using the detection heartbeat interval until the detection of the detection heartbeat interval is successful and the next detection heartbeat interval of the detection heartbeat interval is greater than the reference heartbeat maximum value, and the detection heartbeat interval of successful detection is determined as the first heartbeat interval; or until the detection of the detection heartbeat interval fails, the detection heartbeat interval before the detection failure is determined as the first heartbeat interval.
7. The method according to claim 1, characterized in that: The IoT device determines, according to the first heartbeat interval and the reference heartbeat minimum value, a second heartbeat interval in the target working state, including: The Internet of Things device obtains a heartbeat calculation rule corresponding to the target working state; A second heartbeat interval under the target working state is obtained by calculation according to the first heartbeat interval, the reference heartbeat minimum value and a heartbeat calculation rule corresponding to the target working state.
8. A device for controlling heartbeat intervals, characterized in that: include: A first determination module is configured to obtain at least one reference heartbeat value from a server, and determine a first heartbeat interval according to the at least one reference heartbeat value, wherein the at least one reference heartbeat value at least includes a reference heartbeat minimum value, and the reference heartbeat minimum value is a minimum heartbeat interval value of the device preset by the server; A second determination module is used to determine a current target working state, where the target working state is one of a plurality of working states, where the plurality of working states at least include a working state with user operation and a working state without user operation; A detection module, used for determining a second heartbeat interval in the target working state according to the first heartbeat interval and the reference heartbeat minimum value, and sending a heartbeat packet to the server at the second heartbeat interval, wherein the second heartbeat interval in the working state under the user operation is smaller than the second heartbeat interval in the working state without the user operation; The second determining module is specifically used to: When user operation is detected, the target working state is determined to be a first-level heartbeat state; when it is detected that the time without user operation reaches a first preset time, the target working state is determined to be a second-level heartbeat state; when it is detected that the time without user operation reaches a second preset time, the target working state is determined to be a third-level heartbeat state, wherein the second preset time is greater than the first preset time, the heartbeat interval corresponding to the first-level heartbeat state is smaller than the heartbeat interval corresponding to the second-level heartbeat state, and the heartbeat interval corresponding to the second-level heartbeat state is smaller than the heartbeat interval corresponding to the third-level heartbeat state.
9. An Internet of Things device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 7.
