Method and device for processing center hop in communication process, electronic equipment and storage medium
By dynamically adjusting the heartbeat interval using a network state prediction model in IoT communication, the problems of slow convergence and local optima in the heartbeat mechanism are solved, and more stable network communication is achieved.
Patent Information
- Application Number
- CN202511283394.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-09
- Publication Date
- 2025-12-30
AI Technical Summary
In IoT communication, existing heartbeat mechanisms suffer from slow convergence, are prone to getting trapped in local optima, and cannot adapt to real-time network changes, resulting in unstable communication connections.
By acquiring real-time network characteristics of IoT devices, the heartbeat interval is dynamically adjusted using a network state prediction model. Communication is achieved by combining adaptive heartbeat flags and target heartbeat intervals. This enables dynamic optimization of the heartbeat interval.
It improves the accuracy of heart rate interval adjustment, adapts to real-time network changes, and enhances the stability of network communication.
Smart Images

Figure CN121239730A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of Internet of Things (IoT) communication technology, and in particular to a method for processing heartbeats during communication, a device for processing heartbeats during communication, an electronic device, and a computer-readable storage medium. Background Technology
[0002] In the field of IoT communication, to ensure real-time message communication between IoT devices and between IoT devices and cloud servers, both parties need to maintain a persistent TCP (Transmission Control Protocol) connection. However, in practice, issues such as NAT (Network Address Translation) timeouts and IoT device crashes can cause TCP link interruptions. The method used to maintain a persistent connection is a heartbeat mechanism. Specifically, the IoT device or cloud server periodically sends a heartbeat packet to the other party, and the other party replies with a heartbeat packet to indicate that it is online. If no reply packet is received from the other party for an extended period, the link is considered broken, and the IoT device needs to reconnect to the cloud server. However, the process of confirming the online status of the link through heartbeat packets suffers from slow convergence, susceptibility to local optima, inability to adapt to real-time network changes, and a lack of deep integration with the MQTT (Message Queuing Telemetry Transport) heartbeat mechanism. Summary of the Invention
[0003] This invention provides a method, apparatus, electronic device, and computer-readable storage medium for processing heartbeats during communication, in order to solve or partially solve the problem of unstable communication connections caused by slow convergence and easy getting trapped in local optima when confirming whether the link between two parties is online through heartbeat packets.
[0004] This invention discloses a method for processing heartbeats during communication, comprising:
[0005] Obtain the connection message corresponding to the IoT device, and send the connection message to the server. The connection message includes at least an adaptive heartbeat flag and an initial heartbeat interval.
[0006] In response to receiving a dynamic adjustment instruction for the adaptive heartbeat flag returned by the server, the real-time network characteristics corresponding to the IoT device are collected.
[0007] The real-time network features are input into the network state prediction model for prediction to obtain network state information;
[0008] The initial heartbeat interval is adjusted to the target heartbeat interval based on the network status information, and communication with the server is performed according to the target heartbeat interval.
[0009] Among some feasible implementation methods are:
[0010] A synchronization message corresponding to the target heartbeat interval is sent to the server. The synchronization message is used to instruct the server to synchronize the target heartbeat interval and communicate with the IoT device using the target heartbeat interval.
[0011] Among some feasible implementation methods are:
[0012] Obtain the session timeout threshold corresponding to the IoT device;
[0013] Obtain the adjustment coefficient corresponding to the session timeout threshold;
[0014] The session timeout threshold and the adjustment coefficient are used to calculate and obtain the limit range for the heartbeat interval, and the target heartbeat interval is controlled to be within the limit range.
[0015] In some feasible implementations, the network status information includes real-time bandwidth utilization, and adjusting the initial heartbeat interval to the target heartbeat interval based on the network status information includes:
[0016] If the real-time bandwidth utilization rate is greater than the first preset threshold, the initial heartbeat interval is halved to obtain the first heartbeat interval.
[0017] If the real-time bandwidth utilization rate is less than the first preset threshold and greater than the second preset threshold, then there is no need to adjust the initial heartbeat interval.
[0018] If the real-time bandwidth utilization rate is less than the second preset threshold, the initial heartbeat interval is increased to obtain a second heartbeat interval.
[0019] In some feasible implementations, the network state prediction model includes at least an input layer, a hidden layer, and an output layer. The network state information includes real-time bandwidth utilization. The step of inputting the real-time network features into the network state prediction model for prediction to obtain network state information includes:
[0020] The real-time network features are normalized to obtain the target network features;
[0021] The target network features are input into the hidden layer through the input layer to perform nonlinear feature extraction, thereby obtaining the corresponding nonlinear features.
[0022] The nonlinear features are input into the output layer for prediction to obtain the real-time bandwidth utilization rate corresponding to the IoT device.
[0023] In some feasible implementations, the real-time network characteristics include at least one of network throughput, network latency, and packet loss rate. The normalization of the real-time network characteristics to obtain the target network characteristics includes:
[0024] Obtain normalized information corresponding to the real-time network characteristics. The normalized information includes at least the historical mean and standard deviation of the network throughput, the historical mean and standard deviation of the network latency, and the historical mean and standard deviation of the packet loss rate.
[0025] The network throughput is normalized by using the historical throughput mean and the historical throughput standard deviation to obtain the throughput normalization value corresponding to the network throughput.
[0026] The network latency is normalized using the historical latency mean and the historical latency standard deviation to obtain the latency normalization value corresponding to the network latency;
[0027] The network packet loss is normalized using the historical packet loss mean and the historical packet loss standard deviation to obtain the packet loss normalization value corresponding to the packet loss rate.
[0028] Among some feasible implementation methods are:
[0029] Obtain the algorithm hyperparameters and network structure parameters corresponding to the genetic algorithm. The algorithm hyperparameters include at least the population size, crossover rate, mutation rate, and maximum number of generations.
[0030] The initial weights and bias information corresponding to several groups of individuals are randomly generated using the population size, and the initial weights and bias information corresponding to each group of individuals are encoded into a chromosome to construct the initial population corresponding to the chromosome;
[0031] Obtain historical network feature datasets and model training hyperparameters;
[0032] Chromosome evaluation is performed using the historical network feature dataset, the model training hyperparameters, and each chromosome to obtain the fitness value corresponding to each chromosome.
[0033] Based on the fitness value, each chromosome in the initial population is screened to obtain a first target chromosome, and crossover operation is performed on each of the first target chromosomes according to the crossover rate to obtain the corresponding second target chromosome;
[0034] Mutation operations are performed on each of the second target chromosomes according to the stated mutation rate to obtain the target population;
[0035] If the target population satisfies the maximum number of generations, the third target chromosome with the highest fitness value is selected from the target population as the optimal chromosome, and the network state prediction model is constructed based on the target chromosome and the network structure parameters.
[0036] This invention also discloses a heartbeat processing device during communication, comprising:
[0037] The message processing module is used to obtain the connection message corresponding to the IoT device and send the connection message to the server. The connection message includes at least an adaptive heartbeat flag and an initial heartbeat interval.
[0038] The feature acquisition module is used to acquire real-time network features corresponding to the IoT device in response to receiving a dynamic adjustment instruction for the adaptive heartbeat flag returned by the server.
[0039] The prediction module is used to input the real-time network features into the network state prediction model for prediction to obtain network state information;
[0040] The adjustment module is used to adjust the initial heartbeat interval to a target heartbeat interval based on the network status information, and communicate with the server according to the target heartbeat interval.
[0041] Among some feasible implementation methods are:
[0042] The synchronization module is used to send a synchronization message corresponding to the target heartbeat interval to the server. The synchronization message is used to instruct the server to synchronize the target heartbeat interval and communicate with the IoT device at the target heartbeat interval.
[0043] Among some feasible implementation methods are:
[0044] The threshold acquisition module is used to acquire the session timeout threshold corresponding to the IoT device;
[0045] The coefficient acquisition module is used to acquire the adjustment coefficient corresponding to the session timeout threshold.
[0046] The limiting module is used to calculate, using the session timeout threshold and the adjustment coefficient, a limiting range for the heartbeat interval, and to control the target heartbeat interval to be within the limiting range.
[0047] In some feasible implementations, the network status information includes real-time bandwidth utilization, and the adjustment module is specifically used for:
[0048] If the real-time bandwidth utilization rate is greater than the first preset threshold, the initial heartbeat interval is halved to obtain the first heartbeat interval.
[0049] If the real-time bandwidth utilization rate is less than the first preset threshold and greater than the second preset threshold, then there is no need to adjust the initial heartbeat interval.
[0050] If the real-time bandwidth utilization rate is less than the second preset threshold, the initial heartbeat interval is increased to obtain a second heartbeat interval.
[0051] In some feasible implementations, the network state prediction model includes at least an input layer, a hidden layer, and an output layer; the network state information includes real-time bandwidth utilization; and the prediction module is specifically used for:
[0052] The real-time network features are normalized to obtain the target network features;
[0053] The target network features are input into the hidden layer through the input layer to perform nonlinear feature extraction, thereby obtaining the corresponding nonlinear features.
[0054] The nonlinear features are input into the output layer for prediction to obtain the real-time bandwidth utilization rate corresponding to the IoT device.
[0055] In some feasible implementations, the real-time network characteristics include at least one of network throughput, network latency, and packet loss rate, and the prediction module is specifically used for:
[0056] Obtain normalized information corresponding to the real-time network characteristics. The normalized information includes at least the historical mean and standard deviation of the network throughput, the historical mean and standard deviation of the network latency, and the historical mean and standard deviation of the packet loss rate.
[0057] The network throughput is normalized by using the historical throughput mean and the historical throughput standard deviation to obtain the throughput normalization value corresponding to the network throughput.
[0058] The network latency is normalized using the historical latency mean and the historical latency standard deviation to obtain the latency normalization value corresponding to the network latency;
[0059] The network packet loss is normalized using the historical packet loss mean and the historical packet loss standard deviation to obtain the packet loss normalization value corresponding to the packet loss rate.
[0060] Among some feasible implementation methods are:
[0061] The parameter acquisition module is used to acquire the algorithm hyperparameters and network structure parameters corresponding to the genetic algorithm. The algorithm hyperparameters include at least the population size, crossover rate, mutation rate, and maximum number of generations.
[0062] The population construction module is used to randomly generate initial weights and bias information corresponding to several groups of individuals using the population size, and encode the initial weights and bias information corresponding to each group of individuals into a chromosome to construct the initial population corresponding to the chromosome;
[0063] The dataset acquisition module is used to acquire historical network feature datasets and model training hyperparameters;
[0064] The chromosome evaluation module is used to evaluate chromosomes using the historical network feature dataset, the model training hyperparameters, and each chromosome to obtain the fitness value corresponding to each chromosome.
[0065] The crossover module is used to screen each chromosome in the initial population according to the fitness value to obtain a first target chromosome, and to perform a crossover operation on each of the first target chromosomes according to the crossover rate to obtain a corresponding second target chromosome.
[0066] The mutation module is used to perform mutation operations on each of the second target chromosomes according to the mutation rate to obtain the target population.
[0067] The filtering module is used to select the third target chromosome with the highest fitness value from the target population as the optimal chromosome if the target population satisfies the maximum number of generations, and to construct the network state prediction model based on the target chromosome and the network structure parameters.
[0068] This invention also discloses an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0069] The memory is used to store computer programs;
[0070] When the processor executes a program stored in the memory, it implements the method described in the embodiments of the present invention.
[0071] This invention also discloses a computer-readable storage medium storing instructions that, when executed by one or more processors, cause the processors to perform the methods described in this invention.
[0072] The embodiments of the present invention have the following advantages:
[0073] In this embodiment of the invention, a connection message corresponding to an IoT device is obtained and sent to a server. This connection message may include an adaptive heartbeat flag and an initial heartbeat interval. When dynamic adjustment of the heartbeat interval is supported, the IoT device can respond to the server's dynamic adjustment instruction for the adaptive heartbeat flag, collect real-time network characteristics corresponding to the IoT device, input the real-time network characteristics into a network state prediction model for prediction, obtain network state information, and then adjust the initial heartbeat interval to a target heartbeat interval based on the network state information. The device then communicates with the server according to the target heartbeat interval. By adding an adaptive heartbeat flag to the message, the server can initiate intelligent heartbeat negotiation based on the adaptive heartbeat flag. Thus, the IoT device can dynamically adjust the heartbeat interval according to its own network state, which not only improves the accuracy of heartbeat interval adjustment but also adapts to the needs of real-time network changes, thereby improving the stability of network communication. Attached Figure Description
[0074] Figure 1 This is a flowchart of the steps of a heartbeat processing method during communication provided in an embodiment of the present invention;
[0075] Figure 2 This is a structural block diagram of a heartbeat processing device provided in an embodiment of the present invention. Detailed Implementation
[0076] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0077] As an example, during communication between IoT devices and servers, both parties can periodically send a heartbeat packet to each other, and the other party will reply with a heartbeat packet to indicate that it is online. Based on this, IoT devices and servers need to maintain an appropriate heartbeat interval. The heartbeat interval setting directly affects system performance and resource consumption. Shorter heartbeat intervals can detect faults more quickly, while longer heartbeat intervals can save bandwidth, power, and computing resources. However, in the process of adjusting the heartbeat interval, there are problems such as slow convergence and easy getting trapped in local optima. This makes the heartbeat interval adjustment unable to adapt to changes in the real-time network, and it is not deeply integrated with the MQTT heartbeat mechanism, resulting in unstable communication connections.
[0078] In this invention, a connection message corresponding to the IoT device is obtained and sent to the server. This connection message may include an adaptive heartbeat flag and an initial heartbeat interval. When dynamic adjustment of the heartbeat interval is supported, the IoT device can respond to the server's dynamic adjustment instruction for the adaptive heartbeat flag, collect real-time network characteristics corresponding to the IoT device, input the real-time network characteristics into a network state prediction model for prediction, obtain network state information, and then adjust the initial heartbeat interval to a target heartbeat interval based on the network state information. The device then communicates with the server according to the target heartbeat interval. By adding an adaptive heartbeat flag to the message, the server can initiate intelligent heartbeat negotiation based on the adaptive heartbeat flag. Thus, the IoT device can dynamically adjust the heartbeat interval according to its own network state, which not only improves the accuracy of heartbeat interval adjustment but also adapts to the needs of real-time network changes, thereby improving the stability of network communication.
[0079] Reference Figure 1 The diagram illustrates a flowchart of a heartbeat processing method during communication provided in an embodiment of the present invention, which may specifically include the following steps:
[0080] Step 101: Obtain the connection message corresponding to the IoT device and send the connection message to the server. The connection message includes at least an adaptive heartbeat flag and an initial heartbeat interval.
[0081] Once an IoT device is online, it can send a connection message to the server. In this application, the connection message may include at least an adaptive heartbeat flag and an initial heartbeat interval. The adaptive heartbeat flag can be a newly added flag in the message, allowing the server to be requested to dynamically adjust the heartbeat interval during communication. The initial heartbeat interval can be a suggested initial heartbeat interval (in seconds) to the server. Upon receiving the connection message, the server can first establish a communication connection with the IoT device and transmit heartbeat packets according to the initial heartbeat interval. Simultaneously, it can determine whether to enable dynamic adjustment of the heartbeat interval to dynamically adjust the heartbeat interval between the IoT device and the server, ensuring efficient resource utilization while improving the stability of the communication connection.
[0082] Optionally, the connection message can be a Connect message, which may include: Byte1: 0x10 (CONNECT fixed header); Byte2: 0x40 (adaptive heartbeat flag); Bytes 3-4: suggested initial heartbeat interval (unit: seconds), etc. The present invention does not limit this.
[0083] Step 102: In response to receiving the dynamic adjustment instruction for the adaptive heartbeat flag returned by the server, collect the real-time network characteristics corresponding to the IoT device;
[0084] When the server receives a connection message, it can parse the adaptive heartbeat flag in the message and then determine whether adaptive heartbeat is supported (including whether the server supports the adaptive heartbeat mechanism and whether the communication connection supports it). If adaptive heartbeat is supported, the server can return a corresponding adjustment message to the IoT device. This message can include a dynamic adjustment command, which the IoT device can respond to to trigger a dynamic adjustment of the heartbeat interval between the heartbeat packets transmitted with the server. If adaptive heartbeat is not supported, the server can revert to the standard MQTT heartbeat mechanism.
[0085] With the support of an adaptive heartbeat mechanism, IoT devices can collect corresponding real-time network characteristics. These real-time network characteristics can characterize the network status of the communication connection between the IoT device and the server, such as network throughput, network latency, and packet loss rate. Network throughput can be used to characterize real-time data traffic, network latency can be used to determine the round-trip time of a packet, and packet loss rate can be used to determine the ACK loss status of a packet.
[0086] In some examples, IoT devices can collect network characteristics in real time at a corresponding collection frequency, such as once every 5 minutes, to avoid the extra power consumption caused by high-frequency sampling. During the collection process, data traffic can be monitored in real time through device APIs (such as Linux ifconfig, Android TrafficStats) to obtain the corresponding network throughput. The corresponding network latency can be calculated by using the round-trip time of ICMP (Internet Control Message Protocol) Ping or MQTT QoS1 / 2 message ACK (ACK knowledge) and the ACK loss of MQTT PUBLISH messages can be counted (e.g., if no ACK is received for 3 consecutive times, it is considered a packet loss), etc., to obtain the corresponding real-time network characteristics, so as to further determine whether to dynamically adjust the heartbeat interval based on the real-time network characteristics.
[0087] Step 103: Input the real-time network features into the network state prediction model for prediction to obtain network state information;
[0088] After IoT devices collect relevant real-time network features, they can further obtain a network state prediction model for predicting network status. Then, the real-time network features are input into the network state prediction model to obtain their own corresponding network state information. This network state information can accurately and effectively describe the network status of the communication connection between IoT devices and servers. Thus, the high-precision prediction capability of the network state prediction model enables rapid convergence, which can further achieve dynamic optimization of the heartbeat interval.
[0089] In some feasible implementations, the network state prediction model can include at least an input layer, a hidden layer, and an output layer. The input layer can be used to input the prediction data into the network state prediction model, the hidden layer can be used to extract nonlinear features, and the output layer can predict the network state based on the extracted nonlinear features and output the corresponding prediction results.
[0090] In practical implementation, network status information includes real-time bandwidth utilization. IoT devices can first normalize the real-time network features to obtain target network features, making the input data meet the prediction requirements of the neural network. Then, the target network features are input into the hidden layer of the network status prediction model through the input layer to extract nonlinear features and obtain the corresponding nonlinear features. The nonlinear features are then input into the output layer for prediction to obtain the real-time bandwidth utilization of the IoT device. Thus, the high-precision prediction capability of the network status prediction model enables rapid convergence, so as to further realize the dynamic optimization of the heartbeat interval.
[0091] In some examples, the normalization of network features can be achieved using Z-score standardization, transforming real-time network features into those that meet the prediction requirements of the network state prediction model. Optionally, assuming that real-time network features include at least one of network throughput, network latency, and packet loss rate, the normalized information corresponding to the real-time network features can be obtained first. This normalized information includes at least the historical mean and standard deviation of network throughput, the historical mean and standard deviation of network latency, and the historical mean and standard deviation of packet loss rate. Then, the historical mean throughput and historical standard deviation are used to normalize the network characteristics. Through throughput standard deviation, network throughput is normalized to obtain the normalized throughput value. Similarly, historical latency mean and historical latency standard deviation are used to normalize network latency to obtain the normalized latency value. Likewise, historical packet loss mean and historical packet loss standard deviation are used to normalize network packet loss to obtain the normalized packet loss value. This data preprocessing transforms all network features into dimensionless pure numerical forms, eliminating the influence of dimensions. Furthermore, by converting network features into values distributed within a preset range, the convergence speed of the neural network can be effectively increased, avoiding neuron saturation.
[0092] For example, suppose that before the IoT devices are put into operation, the corresponding historical network features have been collected, and the historical mean and historical standard deviation of each network feature have been calculated, as shown in Table 1 below:
[0093]
[0094] Table 1
[0095] The real-time network characteristics collected by IoT devices may include:
[0096] Throughput (x_1): 2.7Mbps, latency (x_2): 85ms, and packet loss rate (x_3): 2%.
[0097] Next, the Z-Score formula can be applied for normalization:
[0098] Throughput normalization: x_{1\text{-norm}}=\frac{2.7-1.8}{0.6}=\frac{0.9}{0.6}=1.5; Latency normalization: x_{2\text{-norm}}=\frac{85-120}{40}=\frac{-35}{40}=-0.875; Packet loss rate normalization: x_{3\text{-norm}}=\frac{2-5}{3}=\frac{-3}{3}=-1.0. Finally, the normalized result vector is: [1.5,-0.875,-1.0]
[0099] After Z-score standardization, most of the data will be concentrated in the interval [-3, +3], with a mean of 0 and a standard deviation of 1. Wherein:
[0100] 1.5 indicates that the throughput is 1.5 standard deviations above the historical average (good network).
[0101] -0.875 indicates that the latency is 0.875 standard deviations below the historical average (good network).
[0102] -1.0 indicates that the packet loss rate is one standard deviation below the historical average (the network is relatively good).
[0103] By normalizing the network features, all features are transformed into dimensionless pure numerical values. Units such as Mbps, ms, and % are completely eliminated, allowing the three features to be processed fairly by the neural network on the same scale. Furthermore, the neural network activation functions (such as Sigmoid and Tanh) have the largest gradients near 0. The normalized input data distribution near 0 can greatly accelerate the convergence speed of gradient descent and avoid neuron saturation.
[0104] After the corresponding data normalization process is completed, the normalized data can be input into the network state prediction model for network state prediction and forward propagation. During the forward propagation process, the target network features are transmitted from the input layer to the output layer. The current real-time bandwidth utilization of IoT devices can be calculated, and corresponding fine-tuning can be performed. Since the network environment of IoT devices may have subtle changes, the network state prediction model can perform a few backpropagation adjustments to fine-tune the weights to adapt to the real-time environment and finally output high-precision prediction values to guide IoT devices in adjusting their heartbeat intervals.
[0105] In some feasible implementations, for network state prediction models (such as BP (Back Propagation) neural networks), it can be a neural network model used to predict network states. Before formally performing network state prediction, a set of initial weights close to the global optimum can be determined for the network state prediction model through a genetic algorithm, so that the prediction process of network states does not start blindly, but can start from a good starting point.
[0106] Optionally, before formal prediction, the hyperparameters and network structure parameters corresponding to the genetic algorithm can be obtained first. The hyperparameters include at least population size, crossover rate, mutation rate, and maximum number of generations. Then, initial weights and biases are randomly generated for several groups of individuals based on the population size, and the initial weights and biases for each group are encoded into a chromosome, constructing the initial population corresponding to the chromosome. Next, historical network feature datasets and model training hyperparameters are obtained, and chromosome evaluation is performed using these datasets to obtain the fitness value for each chromosome. Finally, the prediction is based on the fitness values... The initial population is selected by screening each chromosome to obtain the first target chromosome. Then, crossover operations are performed on each of the first target chromosomes according to the crossover rate to obtain the corresponding second target chromosomes. Next, mutation operations are performed on each of the second target chromosomes according to the mutation rate to obtain the target population. If the target population meets the maximum number of generations, the third target chromosome with the highest fitness value is selected from the target population as the optimal chromosome. A network state prediction model is then constructed based on the target chromosomes and network structure parameters. The network state prediction model is then optimized by a genetic algorithm, which can prevent the model from getting trapped in local optima, thereby improving the convergence speed and prediction accuracy.
[0107] For example, in the process of outputting the initial weights and biases of an optimal network state prediction model using a genetic algorithm, the corresponding initialization parameters can be obtained first. These include GA (Genetic Algorithm) hyperparameters, the BP neural network structure, and the parameter range. GA hyperparameters can include parameters involved in model optimization, such as population size, crossover rate, mutation rate, and maximum number of generations. The BP neural network structure can include the number of neurons corresponding to each layer of the network state prediction model, such as 3 neurons for the input layer, 6 neurons for the hidden layer, and 1 neuron for the output layer. The parameter range includes the initialization range of weights / biases (e.g., [-1, 1]). After obtaining the corresponding initialization parameters, multiple sets (individuals) of initial weights and biases can be randomly generated based on the population size. Each set of parameters can be encoded as a chromosome, and the initial population P0 is formed based on all chromosomes, containing N individuals (chromosomes). Each individual is a real number array representing a complete set of network initial parameters.
[0108] Next, the corresponding fitness calculation formula can be obtained, and the fitness of each chromosome can be calculated based on the fitness calculation formula. Specifically, the chromosome can be decoded first, and restored to a specific weight matrix and bias vector. Then, a BP neural network can be initialized with the decoded parameters [W,B], and the initialized network can be trained briefly with the training set (e.g., 100 epochs). Then, the network trained briefly can be used to predict the validation set to obtain the prediction result Y_pred. The mean squared error (MSE) between the predicted value Y_pred and the true value Y_true can be calculated. Finally, the error can be converted into fitness, for example, Fitness = 1 / (MSE + 1e-5), thereby obtaining the fitness value (Fitness) of each chromosome.
[0109] After obtaining the fitness values for each chromosome, a selection-crossover-mutation cycle can be performed on the chromosomes. Based on the overall quality of the initial population (i.e., the full predictive accuracy of the neural network), a "biological evolution" can occur, continuously improving generation after generation until the optimal solution is obtained. Optionally, individuals with high fitness can be selected as parents with a certain probability. Individuals with higher fitness have a greater probability of being selected (e.g., using selection algorithms such as "roulette wheel" or "tournament"), ultimately outputting a parent pool composed of selected high-fitness individuals. Then, individuals in the parent pool can be randomly paired, and their chromosomes can be exchanged using a crossover rate to generate new offspring individuals, resulting in a new offspring population after the crossover operation. Finally, using a mutation rate, one or more gene values on the chromosomes of some individuals in the offspring population can be randomly changed (e.g., by adding a random perturbation), resulting in a new generation population P_{t+1} after the mutation operation. For the new generation population P_{t+1}, corresponding termination conditions can be preset, such as the maximum number of generations. It is then determined whether the termination condition is met. If not, t = t+1, P_{t+1} is taken as the new current population, and the process of calculating the fitness value is returned to continue the iteration. If the condition is met, the loop is terminated, and the chromosome with the highest fitness value is selected from the final generation population as the optimal chromosome, i.e., a set of optimized initial weights and biases [W_optimal, B_optimal] for the BP neural network. This initial weights and biases are used to predict the network state, thereby optimizing the network state prediction model through the genetic algorithm. This allows the model to avoid getting trapped in local optima, thus improving the convergence speed and prediction accuracy.
[0110] Step 104: Adjust the initial heartbeat interval to the target heartbeat interval according to the network status information, and communicate with the server according to the target heartbeat interval.
[0111] After obtaining the current network status information of the IoT device, the IoT device can adjust the initial heartbeat interval to the target heartbeat interval based on the network status information, and communicate with the server according to the target heartbeat interval. In this way, the IoT device can dynamically adjust the heartbeat interval according to its own network status, which not only improves the accuracy of heartbeat interval adjustment, but also adapts to the needs of real-time network changes and improves the stability of network communication.
[0112] In some feasible implementations, network status information can be real-time bandwidth utilization. IoT devices can then determine whether to adjust the heartbeat interval based on this utilization. If the real-time bandwidth utilization is greater than a first preset threshold, the initial heartbeat interval is halved to obtain a first heartbeat interval. If the real-time bandwidth utilization is less than the first preset threshold but greater than a second preset threshold, no adjustment to the initial heartbeat interval is needed. If the real-time bandwidth utilization is less than the second preset threshold, the initial heartbeat interval is increased to obtain a second heartbeat interval. After adjusting the heartbeat interval, the device communicates with the server according to the adjusted interval. Thus, IoT devices can dynamically adjust the heartbeat interval based on their own network status, improving the accuracy of heartbeat interval adjustment and adapting to real-time network changes, thereby enhancing the stability of network communication.
[0113] Furthermore, during the adaptive heartbeat adjustment process, corresponding binary search parameters can be introduced to limit the adjustment of the heartbeat interval, so as to balance connection stability and resource consumption, as shown in Table 2 below:
[0114] Network status Bandwidth utilization Adjusting the action Bisection parameters congestion >70% Heart rate interval halved Upper limit = current interval, lower limit = 0 generally 30%~70% Maintain current heart rate interval No adjustment Smooth <30% The heart rate interval increased to 1.5 times. Upper limit = NAT timeout, lower limit = current
[0115] Table 2
[0116] Specifically, when the real-time bandwidth utilization rate output by the network state prediction model is greater than 70%, the IoT device can halve the current heartbeat interval (such as the initial heartbeat interval) and use a binary search parameter to limit it, so that the adjusted target heartbeat interval is between the initial heartbeat interval and 0. When the real-time bandwidth utilization rate output by the network state prediction model is between 30% and 70%, the current heartbeat interval is maintained without adjustment. When the real-time bandwidth utilization rate output by the network state prediction model is less than 30%, the IoT device can increase the current heartbeat interval (such as the initial heartbeat interval) by 1.5 times and use a binary search parameter to limit it, so that the adjusted target heartbeat interval is between the NAT timeout and the current heartbeat interval. Thus, based on the cooperation between the network state prediction model and the binary search method, the fast convergence characteristic can be achieved, realizing the dynamic optimization of the heartbeat interval. This can effectively cope with network mutations, adapt to different network environments, and improve the accuracy of heartbeat adjustment.
[0117] Optionally, for NAT timeout, IoT devices can periodically send ICMP probe packets to measure the NAT session timeout threshold and limit the adjusted target heartbeat interval within the corresponding range. In some feasible implementations, after obtaining the session timeout threshold corresponding to the IoT device, the IoT device can also obtain the adjustment coefficient corresponding to the session timeout threshold. Then, the session timeout threshold and the adjustment coefficient are used to calculate and obtain the limit range for the heartbeat interval, and control the target heartbeat interval to be within the limit range. This reduces the probability of being affected by firewall errors and improves communication stability by ensuring that the adjusted heartbeat interval is within a reasonable range.
[0118] Furthermore, after an IoT device adjusts its heartbeat interval, it can send a synchronization message corresponding to the target heartbeat interval to the server. This synchronization message instructs the server to synchronize with the target heartbeat interval and communicate with the IoT device using that interval, thus ensuring policy consistency between the IoT device and the server. For example, each time an IoT device adjusts its heartbeat interval, it notifies the server via the Heartbeat-Update field (a custom MQTT attribute) to ensure policy consistency between the two parties.
[0119] It should be noted that the embodiments of the present invention include, but are not limited to, the examples described above. It is understood that those skilled in the art can make further settings according to actual needs under the guidance of the ideas in the embodiments of the present invention, and the present invention does not limit such settings.
[0120] In this embodiment of the invention, a connection message corresponding to an IoT device is obtained and sent to a server. This connection message may include an adaptive heartbeat flag and an initial heartbeat interval. When dynamic adjustment of the heartbeat interval is supported, the IoT device can respond to the server's dynamic adjustment instruction for the adaptive heartbeat flag, collect real-time network characteristics corresponding to the IoT device, input the real-time network characteristics into a network state prediction model for prediction, obtain network state information, and then adjust the initial heartbeat interval to a target heartbeat interval based on the network state information. The device then communicates with the server according to the target heartbeat interval. By adding an adaptive heartbeat flag to the message, the server can initiate intelligent heartbeat negotiation based on the adaptive heartbeat flag. Thus, the IoT device can dynamically adjust the heartbeat interval according to its own network state, which not only improves the accuracy of heartbeat interval adjustment but also adapts to the needs of real-time network changes, thereby improving the stability of network communication.
[0121] To enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the following examples are provided for illustrative purposes:
[0122] 1. Data Acquisition and Preprocessing
[0123] Real-time acquisition of network state features provides input data for neural network prediction.
[0124] 1.1 Network Feature Acquisition
[0125] IoT devices can collect at least the following network characteristics:
[0126] Network throughput (Mbps): Real-time monitoring of data traffic via device APIs (such as Linux ifconfig, Android TrafficStats).
[0127] Network latency (ms): Calculated using the round-trip time of ACK for ICMP Ping or MQTT QoS1 / 2 packets.
[0128] Packet loss rate (%): Statistics on the ACK loss of MQTT PUBLISH messages (packet loss is determined if no ACK is received for 3 consecutive times).
[0129] Data acquisition frequency: Once every 5 minutes (configurable) to avoid extra energy consumption caused by high-frequency sampling.
[0130] 1.2 Data Preprocessing
[0131] For the collected network features, IoT devices can perform normalization processing: Z-score standardization is used to make the input data conform to the requirements of neural network training: xnorm = x - μσxnorm = σx - μ. Here, μ can be the historical mean; σ can be the standard deviation. In addition, interference can be eliminated through sliding window smoothing, for example, using a 5-times moving average to eliminate instantaneous fluctuation interference.
[0132] For example, suppose 100 sets of network status data have been collected during the initial operation of the device, and the μ (historical mean) and sigma (historical standard deviation) of each network feature have been calculated. At the current moment, the IoT device collects a new set of real-time data: throughput (x_1): 2.7Mbps; latency (x_2): 85ms; packet loss rate (x_3): 2%, etc. Then, the Z-Score formula can be applied for normalization:
[0133] Throughput normalization:
[0134] x_{1\text{-norm}}=\frac{2.7-1.8}{0.6}=\frac{0.9}{0.6}=1.5
[0135] Delay normalization:
[0136] x_{2\text{-norm}}=\frac{85-120}{40}=\frac{-35}{40}=-0.875
[0137] Packet loss rate normalization:
[0138] x_{3\text{-norm}}=\frac{2-5}{3}=\frac{-3}{3}=-1.0
[0139] The normalized result vector is: [1.5, -0.875, -1.0]
[0140] 1.3 Normalization Results
[0141] Numerical distribution: After Z-score standardization, most of the data will be concentrated in the range of [-3, +3].
[0142] The mean is 0, and the standard deviation is 1. Wherein:
[0143] 1.5 indicates that the throughput is 1.5 standard deviations above the historical average (good network).
[0144] -0.875 indicates that the latency is 0.875 standard deviations below the historical average (good network).
[0145] -1.0 indicates that the packet loss rate is one standard deviation below the historical average (the network is relatively good).
[0146] Dimensionless elimination: All features are transformed into dimensionless pure numerical values. Units such as Mbps, ms, and % are completely eliminated, allowing the three features to be processed fairly by the neural network on the same scale.
[0147] Accelerated training: Neural network activation functions (such as Sigmoid and Tanh) have the largest gradient near 0. The distribution of input data near 0 can greatly accelerate the convergence speed of gradient descent and avoid neuron saturation.
[0148] 2. Network congestion prediction (GA-BP neural network)
[0149] Bandwidth utilization is predicted based on real-time network characteristics, which serves as the basis for adjusting the heartbeat interval.
[0150] 2.1 The structure of the GA-BP neural network can be shown in Table 3 below:
[0151] hierarchy Number of nodes Activation function Input / Output Input layer 3 - Throughput, latency, packet loss rate Hidden layer 6 Sigmoid Nonlinear feature extraction Output layer 1 Linear Bandwidth utilization (0-100%)
[0152] Table 3
[0153] 2.2 Genetic Algorithm (GA) Optimization of Backpropagation Neural Network
[0154] For genetic algorithms, a set of initial weights close to the global optimum can be found for the BP neural network before its formal training (prediction). This allows the BP neural network to start learning from a suitable starting point, rather than blindly starting randomly. Optionally, by directly loading the optimal weights obtained from GA optimization into the lightweight BP neural network in the IoT device, the network state of the IoT device can be predicted in real time. On the one hand, this can avoid the BP neural network getting stuck in local optima during the prediction process, improving the convergence speed. On the other hand, it can quickly and accurately predict the network state to guide the IoT device in adjusting its heartbeat interval.
[0155] In a specific implementation, the process of optimizing a backpropagation (BP) neural network using a GA (Generative Attraction) approach can include:
[0156] Population initialization: Randomly generate 50 sets of initial weights (chromosome encoding) for the BP neural network.
[0157] Fitness assessment: Calculate prediction error (MSE), fitness function:
[0158] F=11+1n∑i=1n(yi-y^i)2F=1+n1∑i=1n(yi-y^i)21
[0159] The meanings of the parameters for this fitness function are shown in Table 4 below:
[0160]
[0161]
[0162] Table 4
[0163] Chromosome decoding: Take a chromosome (a long string) from the population and decode it into a specific weight matrix (W_1, W_2) and bias vector (B_1, B_2) of a BP neural network according to preset rules.
[0164] Construct a temporary network: Use this set of decoded weight parameters to temporarily build a BP neural network.
[0165] Prediction is performed by traversing the dataset: The features (throughput, latency, packet loss rate) of each sample in the historical dataset are input into this temporary network, and forward propagation is performed to obtain the corresponding predicted value \hat{y}_i.
[0166] Error calculation: For each sample, calculate the square of the difference between its predicted value \hat{y}_i and the true value y_i, which is (y_i-\hat{y}_i)^2.
[0167] Aggregate error: Sum the squared errors of all n samples, then divide by n to get the mean square error (MSE), and then take the square root to get the root mean square error (RMSE).
[0168] Calculate fitness: Substitute the calculated RMSE value into the fitness function F=\frac{1}{1+\text{RMSE}} to obtain the comprehensive score representing the quality of this chromosome.
[0169] The process involves repeating the steps of "chromosome decoding - building a temporary network - traversing the dataset for prediction - calculating error - aggregating error - calculating fitness" for each chromosome in the population, thus calculating a fitness score for each chromosome. This score list can then directly guide subsequent selection, crossover, and mutation operations. Chromosomes with higher scores have a greater chance of producing offspring, while those with lower scores are eliminated.
[0170] Through this process, the genetic algorithm can objectively and automatically evaluate thousands of different network parameters and gradually select the individuals with the strongest predictive ability, ultimately finding the "golden initial weights".
[0171] The selection-crossover-mutation process can be described as follows:
[0172] Step 1: Selection – “Survival of the Fittest”
[0173] The selection process involves choosing individuals with high fitness from the current population, increasing their probability of passing on superior genes to the next generation. Specifically, taking the "roulette wheel selection" method as an example, the input is a population (a set of N chromosomes, e.g., 50) and a fitness list (N fitness values (F) corresponding one-to-one with the population). Then, based on the input data, the selection probability of each individual is calculated: P_i = \frac{F_i}{\sum_{j=1}^{N}F_j}, where F_i is the fitness of the i-th individual, and \sum_{j=1}^{N}F_j is the sum of the fitness values of all individuals in the population. In this process, individuals with higher fitness occupy a larger area on the "roulette wheel" with their probability block. Next, a corresponding roulette wheel can be constructed. By calculating the cumulative probability C_i = \sum_{j=1}^{i}P_j, an interval from 0 to 1 is created, with each individual occupying a sub-interval. Next, a rotational selection process is performed. A random number r between [0,1) is generated, and the first individual i that satisfies r <= C_i is selected and copied to a new "Mating Pool". This rotation is repeated N times until N individuals are selected. Individuals with high fitness may be selected multiple times, while individuals with low fitness may not be selected at all. Finally, a new set (Mating Pool) with the same size as the original population (N) is obtained, but dominated by superior individuals.
[0174] Step Two: Crossover – “Genetic Recombination”
[0175] The purpose of crossover is to simulate sexual reproduction in organisms by exchanging some genes between parent individuals to produce offspring with characteristics of both, thus exploring new solution spaces. In a specific implementation, "single-point crossover" can be used as an example. This involves randomly pairing individuals from a "mating pool" (e.g., chromosomes 1 and 2 as one pair, chromosomes 3 and 4 as another pair, etc.), and then deciding whether to crossover. A crossover probability (Pc, usually high, such as 0.8) is assigned to each parent pair, and a random number in the range [0, 1) is generated. If the probability is less than Pc, crossover occurs; otherwise, the offspring directly replicate the parents. Suppose we have two parent chromosomes: Parent1 = [A1,A2,A3,A4,A5] and Parent2 = [B1,B2,B3,B4,B5]. We randomly select a crossover point (e.g., after the second gene) and swap the chromosomes after that point, generating two offspring: Child1 = [A1,A2,|B3,B4,B5] and Child2 = [B1,B2,|A3,A4,A5], etc. Optionally, the "genes" involved can be the weights and thresholds of a neural network. Through crossover, we can create new network parameter configurations and ultimately obtain a new offspring population of size N. Crossover is the primary driving force behind the generation of new individuals.
[0176] Step 3: Mutation – “Introducing Diversity”
[0177] By randomly changing gene values with a very small probability to simulate gene mutation, new genes can be injected into the population, helping the algorithm escape local optima and explore unknown regions.
[0178] In a practical implementation, taking "basic bit mutation" as an example, for each chromosome in the offspring population, each gene position is traversed, and a mutation probability (Pm, usually very low, such as 0.01 or 0.05) is assigned to each gene position. A random number in the range [0,1) is generated; if it is less than Pm, mutation is performed on that gene. During the mutation process, if it is binary encoding: the bit is directly flipped on the gene position (0 becomes 1, 1 becomes 0); if it is real number encoding (which is more likely to be used in this patent): random perturbation is performed within the value range of the gene. For example: new_gene = old_gene + random.uniform(-0.1, 0.1).
[0179] Through the tiny perturbations described above, the weights of a neural network can be fine-tuned, resulting in random changes to a very small number of genes. This maintains population diversity and prevents all individuals from prematurely converging (getting trapped in local optima). The data flow for one iteration of the selection-crossover-mutation process described above can be shown in Table 5 below:
[0180]
[0181] Table 5
[0182] Through repeated cycles of "evaluation → selection → crossover → mutation", the overall quality of the population (i.e., the predictive accuracy of the neural network weights) will improve generation after generation, just like biological evolution, and eventually obtain the optimal solution that meets the preset conditions.
[0183] 2.3 Online Prediction
[0184] After optimizing the BP neural network using a genetic algorithm, the optimized BP neural network can be used to predict the network status of IoT devices. The specific process may include:
[0185] Input: Real-time collected and preprocessed network data (such as throughput, latency, packet loss rate, etc.).
[0186] Forward propagation: Data travels from the input layer to the output layer, and the predicted bandwidth utilization is calculated.
[0187] Fine-tuning: Although the starting point is high, the network environment on the device side may still have subtle changes. The BP neural network will perform a few backpropagations to fine-tune the weights to adapt to the real-time environment.
[0188] Output: Outputs the final high-precision predicted value to guide the adjustment of heart rate interval.
[0189] For example, given the input: preprocessed network features (throughput, latency, packet loss rate), the BP neural network can output: bandwidth utilization (0-100%), and classify it according to the threshold: smooth (<30%): the heartbeat interval can be increased; normal (30%-70%): maintain the current interval; congested (>70%): the heartbeat interval needs to be reduced.
[0190] 3. Dynamic adjustment of heart rate interval (dichotomy strategy)
[0191] Objective: To dynamically optimize the heartbeat interval based on prediction results, balancing connection stability and resource consumption.
[0192] 3.1 The adjustment strategy can be shown in Table 6 below:
[0193]
[0194] Table 6
[0195] 3.2 Dynamic NAT Timeout Detection
[0196] ICMP probe method: The client periodically sends ICMP probe packets to measure the NAT session timeout threshold (e.g., the probe result can be 30 seconds, etc.).
[0197] Security interval constraint: The final heartbeat interval is forcibly limited to between 0.3TNAT and 0.8TNAT to avoid being mistakenly blocked by the firewall.
[0198] 4. MQTT Protocol Integration
[0199] This ensures that the client and server work together to adjust the heartbeat interval, avoiding inconsistencies in state.
[0200] 4.1 Protocol Extension
[0201] A new flag (0x40) has been added to the CONNECT message:
[0202] Byte 1: 0x10 (CONNECT header)
[0203] Byte 2: 0x40 (Adaptive Heartbeat Flag)
[0204] Byte 3-4: Suggested initial heartbeat interval (unit: seconds)
[0205] Server response:
[0206] If adaptive heartbeat is supported, return CONNACK and adopt dynamic detection mode.
[0207] If not supported, fall back to the standard MQTT heartbeat mechanism.
[0208] 4.2 Synchronization of heartbeat intervals
[0209] Each time the client adjusts the heartbeat interval, it notifies the server via the Heartbeat-Update field (a custom MQTT property) to ensure that the strategies of both parties are consistent.
[0210] 5. System Overall Workflow
[0211] Device online: Sends a CONNECT message with the 0x40 flag to negotiate the initial heartbeat interval.
[0212] Periodic monitoring: Collect network status every 5 minutes and input it into the GA-BP model to predict the degree of congestion.
[0213] Dynamic adjustment:
[0214] If congestion is predicted (>70%), reduce the heartbeat interval to 50% of the current value.
[0215] If the predicted smooth flow (<30%), increase the interval to 1.5 times (not exceeding the NAT timeout).
[0216] Protocol synchronization: The latest interval is notified to the server via MQTT extended fields to maintain a long-lived connection.
[0217] In the above process, by adding an adaptive heartbeat flag to the message, the server can initiate intelligent heartbeat negotiation based on the adaptive heartbeat flag. As a result, IoT devices can dynamically adjust the heartbeat interval according to their own network status, which not only improves the accuracy of heartbeat interval adjustment, but also adapts to the needs of real-time network changes and improves the stability of network communication.
[0218] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of the present invention are not limited to the described order of actions, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present invention.
[0219] Reference Figure 2 The diagram illustrates a structural block diagram of a heartbeat processing device during communication provided in an embodiment of the present invention, which may specifically include the following modules:
[0220] Message processing module 201 is used to obtain a connection message corresponding to an IoT device and send the connection message to a server. The connection message includes at least an adaptive heartbeat flag and an initial heartbeat interval.
[0221] The feature acquisition module 202 is used to acquire real-time network features corresponding to the Internet of Things device in response to receiving a dynamic adjustment instruction for the adaptive heartbeat flag returned by the server.
[0222] Prediction module 203 is used to input the real-time network features into the network state prediction model for prediction to obtain network state information;
[0223] The adjustment module 204 is used to adjust the initial heartbeat interval to a target heartbeat interval according to the network status information, and communicate with the server according to the target heartbeat interval.
[0224] Among some feasible implementation methods are:
[0225] The synchronization module is used to send a synchronization message corresponding to the target heartbeat interval to the server. The synchronization message is used to instruct the server to synchronize the target heartbeat interval and communicate with the IoT device at the target heartbeat interval.
[0226] Among some feasible implementation methods are:
[0227] The threshold acquisition module is used to acquire the session timeout threshold corresponding to the IoT device;
[0228] The coefficient acquisition module is used to acquire the adjustment coefficient corresponding to the session timeout threshold.
[0229] The limiting module is used to calculate, using the session timeout threshold and the adjustment coefficient, a limiting range for the heartbeat interval, and to control the target heartbeat interval to be within the limiting range.
[0230] In some feasible implementations, the network status information includes real-time bandwidth utilization, and the adjustment module 204 is specifically used for:
[0231] If the real-time bandwidth utilization rate is greater than the first preset threshold, the initial heartbeat interval is halved to obtain the first heartbeat interval.
[0232] If the real-time bandwidth utilization rate is less than the first preset threshold and greater than the second preset threshold, then there is no need to adjust the initial heartbeat interval.
[0233] If the real-time bandwidth utilization rate is less than the second preset threshold, the initial heartbeat interval is increased to obtain a second heartbeat interval.
[0234] In some feasible implementations, the network state prediction model includes at least an input layer, a hidden layer, and an output layer; the network state information includes real-time bandwidth utilization; and the prediction module 203 is specifically used for:
[0235] The real-time network features are normalized to obtain the target network features;
[0236] The target network features are input into the hidden layer through the input layer to perform nonlinear feature extraction, thereby obtaining the corresponding nonlinear features.
[0237] The nonlinear features are input into the output layer for prediction to obtain the real-time bandwidth utilization rate corresponding to the IoT device.
[0238] In some feasible implementations, the real-time network characteristics include at least one of network throughput, network latency, and packet loss rate, and the prediction module 203 is specifically used for:
[0239] Obtain normalized information corresponding to the real-time network characteristics. The normalized information includes at least the historical mean and standard deviation of the network throughput, the historical mean and standard deviation of the network latency, and the historical mean and standard deviation of the packet loss rate.
[0240] The network throughput is normalized by using the historical throughput mean and the historical throughput standard deviation to obtain the throughput normalization value corresponding to the network throughput.
[0241] The network latency is normalized using the historical latency mean and the historical latency standard deviation to obtain the latency normalization value corresponding to the network latency;
[0242] The network packet loss is normalized using the historical packet loss mean and the historical packet loss standard deviation to obtain the packet loss normalization value corresponding to the packet loss rate.
[0243] Among some feasible implementation methods are:
[0244] The parameter acquisition module is used to acquire the algorithm hyperparameters and network structure parameters corresponding to the genetic algorithm. The algorithm hyperparameters include at least the population size, crossover rate, mutation rate, and maximum number of generations.
[0245] The population construction module is used to randomly generate initial weights and bias information corresponding to several groups of individuals using the population size, and encode the initial weights and bias information corresponding to each group of individuals into a chromosome to construct the initial population corresponding to the chromosome;
[0246] The dataset acquisition module is used to acquire historical network feature datasets and model training hyperparameters;
[0247] The chromosome evaluation module is used to evaluate chromosomes using the historical network feature dataset, the model training hyperparameters, and each chromosome to obtain the fitness value corresponding to each chromosome.
[0248] The crossover module is used to screen each chromosome in the initial population according to the fitness value to obtain a first target chromosome, and to perform a crossover operation on each of the first target chromosomes according to the crossover rate to obtain a corresponding second target chromosome.
[0249] The mutation module is used to perform mutation operations on each of the second target chromosomes according to the mutation rate to obtain the target population.
[0250] The filtering module is used to select the third target chromosome with the highest fitness value from the target population as the optimal chromosome if the target population satisfies the maximum number of generations, and to construct the network state prediction model based on the target chromosome and the network structure parameters.
[0251] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0252] In addition, this invention also provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, it implements the various processes of the above-described heartbeat processing method embodiment and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0253] This invention also provides a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the various processes of the heartbeat processing method embodiments described above, achieving the same technical effects. To avoid repetition, these will not be elaborated upon here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.
[0254] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0255] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, EEPROM, Flash, and eMMC, etc.) containing computer-usable program code.
[0256] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0257] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0258] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0259] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present invention.
[0260] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0261] The present invention has provided a detailed description of a method and apparatus for processing heartbeats during communication. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, those skilled in the art will recognize that there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for processing a communication procedure hop-by-hop, characterized by, The method comprises the following steps: acquiring a connection message corresponding to an Internet of Things device, and sending the connection message to a server, wherein the connection message at least comprises an adaptive heartbeat flag and an initial heartbeat interval; in response to receiving a dynamic adjustment instruction returned by the server for the adaptive heartbeat flag, collecting real-time network features corresponding to the Internet of Things device; inputting the real-time network features into a network state prediction model for prediction to obtain network state information; adjusting the initial heartbeat interval to a target heartbeat interval according to the network state information, and communicating with the server according to the target heartbeat interval.
2. The method of claim 1, wherein, Further comprising: sending a synchronization message corresponding to the target heartbeat interval to the server, wherein the synchronization message is used to instruct the server to synchronize the target heartbeat interval and communicate with the Internet of Things device at the target heartbeat interval.
3. The method according to claim 1 or 2, characterized in that, Further comprising: acquiring a session timeout threshold corresponding to the Internet of Things device; acquiring an adjustment coefficient corresponding to the session timeout threshold; calculating the session timeout threshold and the adjustment coefficient to obtain a limit range for the heartbeat interval, and controlling the target heartbeat interval to be located in the limit range.
4. The method of claim 1, wherein, The network state information comprises a real-time bandwidth occupancy rate, and the adjusting of the initial heartbeat interval to a target heartbeat interval according to the network state information comprises: if the real-time bandwidth occupancy rate is greater than a first preset threshold, halving the initial heartbeat interval to obtain a first heartbeat interval; if the real-time bandwidth occupancy rate is less than the first preset threshold and greater than a second preset threshold, no adjustment is needed for the initial heartbeat interval; if the real-time bandwidth occupancy rate is less than the second preset threshold, expanding the initial heartbeat interval to obtain a second heartbeat interval.
5. The method of claim 1, wherein, The network state prediction model at least comprises an input layer, a hidden layer and an output layer, the network state information comprises a real-time bandwidth occupancy rate, and the inputting of the real-time network features into the network state prediction model for prediction to obtain network state information comprises: normalizing the real-time network features to obtain target network features; inputting the target network features into the hidden layer through the input layer for nonlinear feature extraction to obtain corresponding nonlinear features; inputting the nonlinear features into the output layer for prediction to obtain the real-time bandwidth occupancy rate corresponding to the Internet of Things device.
6. The method of claim 5, wherein, The real-time network features at least comprise one of a network throughput, a network delay and a packet loss rate, and the normalizing of the real-time network features to obtain target network features comprises: acquiring normalization information corresponding to the real-time network features, wherein the normalization information at least comprises a historical throughput mean and a historical throughput standard deviation corresponding to the network throughput, a historical delay mean and a historical delay standard deviation corresponding to the network delay, and a historical packet loss mean and a historical packet loss standard deviation corresponding to the packet loss rate; normalizing the network throughput by using the historical throughput mean and the historical throughput standard deviation to obtain a throughput normalization value corresponding to the network throughput; The network delay is normalized by using the historical delay mean and the historical delay standard deviation, to obtain a delay normalized value corresponding to the network delay; The network packet loss is normalized by using the historical packet loss mean and the historical packet loss standard deviation, to obtain a packet loss normalized value corresponding to the packet loss rate.
7. The method according to claim 5 or 6, characterized in that, Further comprising: obtaining algorithm hyperparameters corresponding to the genetic algorithm, and network structure parameters, the algorithm hyperparameters at least including population size, crossover rate, mutation rate, and maximum evolution generation number; randomly generating initial weights and bias information corresponding to a plurality of groups of individuals using the population size, and encoding the initial weights and the bias information corresponding to each group of individuals into a chromosome to construct an initial population corresponding to the chromosome; obtaining a historical network feature dataset and model training hyperparameters; performing chromosome evaluation using the historical network feature dataset, the model training hyperparameters, and each chromosome to obtain a fitness value corresponding to each chromosome; filtering each chromosome in the initial population according to the fitness value to obtain a first target chromosome, and performing a crossover operation on each first target chromosome according to the crossover rate to obtain a corresponding second target chromosome; performing a mutation operation on each second target chromosome according to the mutation rate to obtain a target population; if the target population satisfies the maximum evolution generation number, filtering a third target chromosome with the highest fitness value from the target population as an optimal chromosome, and constructing the network state prediction model based on the target chromosome and the network structure parameters.
8. A processing device for a communication process of a center hop, characterized in that, comprising: a packet processing module configured to obtain a connection packet corresponding to an Internet of Things device, and send the connection packet to a server, the connection packet at least including an adaptive heartbeat flag and an initial heartbeat interval; a feature collection module configured to collect real-time network features corresponding to the Internet of Things device in response to receiving a dynamic adjustment instruction for the adaptive heartbeat flag returned by the server; a prediction module configured to input the real-time network features into a network state prediction model for prediction to obtain network state information; an adjustment module configured to adjust the initial heartbeat interval to a target heartbeat interval according to the network state information, and communicate with the server according to the target heartbeat interval.
9. An electronic device, comprising: comprising a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory complete communication with each other through the communication bus; the memory is used to store computer programs; the processor is used to execute the programs stored on the memory to implement the method of any one of claims 1-7.
10. A computer-readable storage medium having instructions stored thereon, which, when executed by one or more processors, cause the processors to perform the method of any one of claims 1-7.