Method and apparatus for switching communication protocol, electronic device, storage medium and product

By dynamically switching communication protocols and optimizing link parameters in new energy IoT devices, the stability problem of communication links in complex electromagnetic interference and weak network signal environments is solved, achieving efficient and reliable communication.

CN122137905APending Publication Date: 2026-06-02HAIER ENERGY TECHNOLOGY CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HAIER ENERGY TECHNOLOGY CO LTD
Filing Date
2026-05-07
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Existing technologies suffer from poor communication link stability in complex electromagnetic interference and weak network signal environments for new energy IoT devices, and are unable to adaptively cope with problems such as network jitter, bandwidth fluctuations, and signal attenuation.

Method used

By responding to the target service message received from the terminal device, the service level is determined, the network quality is evaluated using a preset network scoring algorithm and prediction model, the communication protocol is dynamically switched, including Transmission Control Protocol, Message Queuing Telemetry Transmission Protocol and Restricted Application Protocol, and the communication link parameters and retransmission strategy are optimized.

Benefits of technology

It improves the stability of communication links, solves the problems of poor adaptability to single protocols and slow response to network changes, and ensures high efficiency and reliability of communication.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122137905A_ABST
    Figure CN122137905A_ABST
Patent Text Reader

Abstract

This application provides a method, apparatus, electronic device, storage medium, and product for switching communication protocols, comprising: responding to receiving a target service message sent by a terminal device, determining a target service level based on the target service message; the target service message includes service data; the target service level is used to indicate the urgency level of the service data; determining a network quality score for the communication link using a preset network scoring algorithm and based on real-time network parameter data of the communication link; the communication link is established based on the terminal device; determining a predicted network quality score using a preset network prediction model and based on real-time network parameter data; determining a target communication protocol based on the predicted network quality score, the network quality score of the communication link, and the target service level; if the target communication protocol is different from the current communication protocol, switching the current communication protocol of the terminal device to the target communication protocol. The method of this application improves the stability of the communication link.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communication technology, and in particular to a method, apparatus, electronic device, storage medium and product for switching communication protocols. Background Technology

[0002] New energy IoT devices are widely used in industries, energy, and smart cities, such as photovoltaic power plants, wind turbines, energy storage systems, and smart grid monitoring equipment. These devices are typically deployed in remote areas, environments with complex electromagnetic interference, or areas with weak network signals (such as underground pipelines and tunnels). In actual operation, they need to interact with other devices at high frequency, such as uploading power generation data in real time, receiving remote control commands, and synchronizing operating status. However, such scenarios often face problems such as network jitter, bandwidth fluctuations, and signal attenuation. Furthermore, the number of devices in industrial IoT scenarios is enormous. Therefore, ensuring communication stability is crucial to supporting the efficient operation of new energy systems.

[0003] Currently, most existing technologies use fixed communication protocols, which cannot adaptively cope with problems such as network jitter, bandwidth fluctuations, and signal attenuation, resulting in poor stability of communication links. Summary of the Invention

[0004] This application provides a method, apparatus, electronic device, storage medium, and product for switching communication protocols to improve the stability of communication links.

[0005] In a first aspect, embodiments of this application provide a method for switching communication protocols, including:

[0006] In response to receiving a target service message sent by a terminal device, a target service level is determined based on the target service message; the target service message includes service data; the target service level is used to indicate the urgency level of the service data;

[0007] A preset network scoring algorithm is used to determine the network quality score of the communication link based on real-time network parameter data of the communication link; the communication link is established based on the terminal device.

[0008] A preset network prediction model is used, and a predicted network quality score is determined based on the real-time network parameter data.

[0009] The target communication protocol is determined based on the predicted network quality score, the network quality score of the communication link, and the target service level.

[0010] If the target communication protocol is different from the current communication protocol, then the current communication protocol of the terminal device will be switched to the target communication protocol.

[0011] In one possible implementation, the real-time network parameter data includes transmission delay data, bandwidth data, and packet loss rate;

[0012] The target business level is the first business level, the second business level, or the third business level;

[0013] The process of determining the network quality score of the communication link using a preset network scoring algorithm and based on real-time network parameter data of the communication link includes:

[0014] A first score, a second score, and a third score are determined using a preset scoring formula based on the transmission delay data, the bandwidth data, and the packet loss rate; the first score is the score corresponding to the transmission delay data; the second score is the score corresponding to the bandwidth data; and the third score is the score corresponding to the packet loss rate.

[0015] Based on the target service level, the target weights corresponding to the transmission delay data, the bandwidth data, and the packet loss rate are determined respectively.

[0016] The first score, the second score, and the third score are weighted and summed based on the target weights to determine the network quality score of the communication link.

[0017] In one possible implementation, the step of employing a preset network prediction model and determining the predicted network quality score based on the real-time network parameter data includes:

[0018] Obtain historical prediction network quality scores for a preset period;

[0019] The historical prediction network quality score of the preset period, the first score, the second score, and the third score are input into the preset network prediction model, and the prediction network quality score is output. The preset network prediction model is pre-trained to convergence.

[0020] In one possible implementation, determining the target communication protocol based on the predicted network quality score, the network quality score of the communication link, and the target service level includes:

[0021] In response to the predicted network quality score being less than or equal to a preset predicted score threshold, the transmission control protocol is determined as the target communication protocol;

[0022] In response to the predicted network quality score being greater than a preset predicted score threshold, the target communication protocol is determined based on the network quality score of the communication link and the target service level.

[0023] In one possible implementation, determining the target communication protocol based on the network quality score of the communication link and the target service level includes:

[0024] In response to the target service level being the second or third service level and the network quality score of the communication link being greater than or equal to the first preset threshold, the restricted application protocol is determined as the target communication protocol.

[0025] In response to the target service level being the first service level and the network quality score of the communication link being greater than or equal to the second preset threshold, the message queue telemetry transmission protocol is determined as the target communication protocol.

[0026] In response to the target service level being the second or third service level and the network quality score of the communication link being less than the first preset threshold and greater than or equal to the second preset threshold, the message queue telemetry transmission protocol is determined as the target communication protocol.

[0027] If the network quality score of the communication link is less than a second preset threshold, the transmission control protocol is determined as the target communication protocol.

[0028] In one possible implementation, the method further includes:

[0029] In response to the network quality score of the communication link being less than a third preset threshold, the communication parameters of the communication link are adjusted according to the target service level; the communication parameters of the communication link include write buffer size, heartbeat interval time and write timeout time, and the third preset threshold is less than the second preset threshold.

[0030] In one possible implementation, after switching the current communication protocol of the terminal device to the target communication protocol, the method further includes:

[0031] In response to the target service level being the first service level, the target service message is compressed according to the first preset compression ratio;

[0032] In response to the target service level being the second service level and the target communication protocol being a restricted application protocol, the target service message is compressed according to a second preset compression ratio;

[0033] In response to the target service level being the second service level and the target communication protocol being a message queue telemetry transmission protocol or a transmission control protocol, the target service message is compressed according to a third preset compression ratio; the third preset compression ratio is greater than the second preset compression ratio.

[0034] In response to the target service level being the third service level and the target communication protocol being a restricted application protocol, the target service message is compressed according to a fourth preset compression ratio;

[0035] In response to the target service level being the third service level and the target communication protocol being a message queue telemetry transmission protocol or a transmission control protocol, the target service message is compressed according to a fifth preset compression ratio; the fifth preset compression ratio is greater than the fourth preset compression ratio.

[0036] In one possible implementation, the method further includes:

[0037] In response to the satisfaction of preset retransmission conditions, a target retransmission strategy is determined based on the target service level and target communication protocol of the target service packet; the preset retransmission conditions are that the write timeout is greater than a preset time threshold or the received target service packet is lost.

[0038] The target retransmission strategy is used to transmit the target service message.

[0039] In one possible implementation, the step of transmitting the target service message using the target retransmission strategy includes:

[0040] In response to the target service level being a first service level, the target service message is transmitted according to a first preset interval time and a first preset number of retransmissions;

[0041] In response to the target service level being the second service level, the target service message is transmitted according to the second preset interval time and the second preset number of retransmissions;

[0042] In response to the target service level being the third service level, the target service message is transmitted according to a third preset interval time and a third preset retransmission number; the first preset retransmission number is greater than the second preset retransmission number, and the second preset retransmission number is greater than the third preset retransmission number.

[0043] In one possible implementation, the method further includes:

[0044] In response to a predicted network quality score being less than or equal to a preset predicted score threshold, the target service level of the target service packet is determined.

[0045] In response to the target service level of the target service message being the first service level, the target service message is cached.

[0046] In one possible implementation, the method further includes:

[0047] If the predicted network quality score is greater than a preset predicted score threshold and the network quality score of the communication link is less than a third preset threshold, then it is determined that there is an anomaly in the communication link.

[0048] In response to the target service level of the target service message being the first service level, the failed target service message is buffered, and it is determined whether the communication link has been restored to normal.

[0049] In response to the restoration of normal communication links, the cached target service messages will be retransmitted.

[0050] Secondly, embodiments of this application provide a communication protocol switching device, comprising:

[0051] A determination module is configured to, in response to receiving a target service message sent by a terminal device, determine a target service level based on the target service message; the target service message includes service data; the target service level is used to indicate the urgency level of the service data.

[0052] The determining module is further configured to determine the network quality score of the communication link using a preset network scoring algorithm and based on real-time network parameter data of the communication link; the communication link is established based on the terminal device;

[0053] The determination module is also used to determine the predicted network quality score based on the preset network prediction model and the real-time network parameter data;

[0054] The determining module is further configured to determine the target communication protocol based on the predicted network quality score, the network quality score of the communication link, and the target service level;

[0055] The switching module is used to switch the current communication protocol of the terminal device to the target communication protocol if the target communication protocol is different from the current communication protocol.

[0056] Thirdly, embodiments of this application provide an electronic device, including: a memory and a processor;

[0057] The memory stores instructions that the computer executes;

[0058] The processor executes computer execution instructions stored in memory, causing the processor to perform the first aspect above, or various possible implementations of the first aspect.

[0059] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the first aspect and / or various possible implementations of the first aspect.

[0060] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the first aspect above, or various possible implementations of the first aspect.

[0061] The communication protocol switching method, apparatus, electronic device, storage medium, and product provided in this application, in response to receiving a target service message sent by a terminal device, extracts service data and determines the target service level, clarifies the urgency of the service, and provides a priority basis for subsequent protocol decisions. It acquires real-time network parameter data of the communication link corresponding to the terminal device, obtains the current network quality score through a preset network scoring algorithm, and uses a preset network prediction model to derive and predict the network quality score based on the real-time network parameter data, achieving a dual assessment of the current state and future trends. Finally, it comprehensively considers the predicted network quality score, the real-time network quality score, and the target service level to determine the target communication protocol. When the target communication protocol differs from the current communication protocol, it completes the switching of the terminal device from the current communication protocol to the target communication protocol, solving the problems of poor adaptability of a single protocol and delayed response to network changes, and improving the stability of the communication link. Attached Figure Description

[0062] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0063] Figure 1 A system architecture diagram of the communication protocol switching method provided in the embodiments of this application;

[0064] Figure 2 A flowchart illustrating the communication protocol switching method provided in an embodiment of this application;

[0065] Figure 3 A schematic diagram of the communication protocol switching device provided in the embodiments of this application;

[0066] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.

[0067] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0068] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0069] First, some nouns or terms that appear in the description of the embodiments of this disclosure shall be interpreted as follows:

[0070] Netty is a high-performance, asynchronous, event-driven network communication framework based on Java NIO. It is widely used in scenarios requiring high-performance network communication, such as the Internet of Things, distributed services, big data, and games.

[0071] The Netty IoT Protocol Gateway is a network access gateway built on an asynchronous event-driven architecture, specifically designed to solve the core challenges of massive concurrent device connections and diverse protocol adaptation in IoT scenarios. This type of gateway uses a non-blocking input / output model, employing a small number of fixed threads and multiplexing mechanisms to manage tens of thousands of long-lived device connections. Processing resources are dynamically allocated only when data arrives, thus achieving high-throughput data exchange with extremely low memory and CPU overhead.

[0072] HTTPS is a secure application-layer communication protocol based on HTTP with SSL / TLS encryption. It ensures the security and integrity of data exchange through encrypted transmission.

[0073] The WebSocket protocol is a full-duplex, long-connection application layer communication protocol built on the TCP protocol, which enables bidirectional real-time data push between the client and the server.

[0074] In existing technologies, communication between new energy IoT devices and remote devices often uses fixed communication protocols. Fixed communication protocols have fixed protocol stacks, non-adjustable parameters, and lack adaptive mechanisms. However, the deployment environment for new energy IoT devices is typically in remote areas, complex electromagnetic interference environments, or areas with weak network signals.

[0075] In complex electromagnetic interference (EMI) environments, such as frequent switching of frequency converters, starting and stopping of large motors, and operation of large relays, the interference is non-stationary and sudden. If a fixed communication protocol is used, employing a fixed modulation scheme, fixed transmit power, and fixed retransmission mechanism, it cannot dynamically switch to a more robust modulation scheme or instantly increase the forward error correction rate when a sudden, strong interference occurs. At the moment the interference appears, the bit error rate spikes dramatically, but the protocol cannot avoid this, directly leading to packet loss or connection interruption.

[0076] In remote areas or areas with weak network signals, there are common problems such as narrow bandwidth, high latency, severe link jitter, and frequent instantaneous packet loss. Fixed communication protocols are also unable to meet these shortcomings.

[0077] Therefore, to solve the above-mentioned technical problems, this application proposes the following technical concept: In response to receiving a target service message sent by a terminal device, extract service data and determine the target service level to clarify the urgency of the service and provide a priority basis for subsequent protocol decisions. Obtain real-time network parameter data of the communication link corresponding to the terminal device, obtain the current network quality score through a preset scoring algorithm, and derive and predict the network quality score based on the real-time network parameter data using a preset network prediction model to achieve a dual assessment of the current state and future trends. Finally, by comprehensively considering the predicted network quality score, the real-time network quality score, and the target service level, determine the target communication protocol. When the target communication protocol differs from the current communication protocol, complete the switching of the terminal device from the current communication protocol to the target communication protocol, solving the problems of poor adaptability of a single protocol and delayed response to network changes, and improving the stability of the communication link.

[0078] Figure 1 A system architecture diagram of the communication protocol switching method provided in the embodiments of this application is shown below. Figure 1 As shown, it includes the device layer, the Netty IoT protocol gateway, and the cloud service layer.

[0079] In this embodiment, the device layer connects to various terminal devices in the new energy Internet of Things (IoT), such as control devices (photovoltaic inverters), smart meters, data acquisition devices (environmental sensors), and gateway devices. The terminal devices initiate access requests to the Netty IoT protocol gateway and use the communication protocol currently used by the terminal device for access. The communication protocol can include any of the following: Message Queuing Telemetry Transport (MQTT), Constrained Application Protocol (CoAP), Transmission Control Protocol (TCP), and User Datagram Protocol (UDP). In this embodiment, the Netty IoT protocol gateway acts as a bridge between the cloud service layer and the terminal devices. Built on the Netty framework, it is responsible for multi-protocol access, protocol adaptation, intelligent transmission, and link monitoring, serving as the core middleware between the terminal devices and the cloud server. The Netty IoT protocol gateway includes a protocol adaptation layer, a protocol selection engine, an intelligent retransmission module, and a link quality monitoring module. The protocol adaptation layer is responsible for multi-protocol encoding and decoding, protocol format conversion, and enabling interconnection between heterogeneous protocol terminals and the cloud server. The protocol selection engine determines and switches the target communication protocol based on multiple network quality parameters of the communication link established between the terminal device and the Netty IoT protocol gateway, as well as the service priority of the terminal device. The intelligent retransmission module enables intelligent retries and resume transmission of communication data, reducing data loss rates. The link quality monitoring module collects multiple network quality parameters of the communication link in real time, providing quantitative decision-making basis for the protocol selection engine.

[0080] In this embodiment, the Netty IoT protocol gateway also includes a Netty event loop group. The Netty event loop group is a thread model component of the Netty framework, used to manage network communication threads and handle I / O operations. It includes two sub-components: a main event loop group and worker event loop groups. The main event loop group is responsible for listening to the port, processing client connection requests, and distributing connections to the worker event loop groups. The worker event loop groups are responsible for handling I / O read / write operations and business logic processing for connected clients.

[0081] In this embodiment, the cloud service layer and the Netty IoT protocol gateway communicate using both HTTPS and WebSocket protocols. HTTPS is used for secure and reliable command issuance and data reporting, ensuring the confidentiality and integrity of management-related interactive information. WebSocket is used to establish a two-way real-time communication channel, supporting scenarios with high timeliness requirements such as communication protocol switching notifications and real-time monitoring data transmission, ensuring low latency and high responsiveness in message interaction between the cloud and the gateway.

[0082] In this embodiment, the cloud service layer includes a data storage module, a business logic processing module, a protocol analysis engine, and a device management module. The data storage module is responsible for the persistent storage of IoT data, supporting time-series databases, relational databases, etc. The business logic processing module is responsible for implementing IoT business logic, including device control, service scheduling, alarm management, and data analysis. The protocol analysis engine parses and verifies various protocol messages transmitted from the Netty IoT protocol gateway, then converts them into structured data that can be directly used in the cloud. The device management module is used to implement full lifecycle management of terminal devices.

[0083] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0084] Figure 2 A flowchart illustrating a communication protocol switching method provided in an embodiment of this application is shown below. Figure 2 As shown. The communication protocol switching method provided in this embodiment is applied to the Netty IoT protocol gateway. The specific steps of the communication protocol switching method provided in this embodiment are as follows:

[0085] S201: In response to receiving a target service message sent by a terminal device, determine the target service level based on the target service message.

[0086] The target service message includes service data. The target service level indicates the urgency level of the service data.

[0087] In this embodiment, Netty is the underlying core network framework of the method of this application. Netty is a high-performance, asynchronous, event-driven network communication framework developed based on Java NIO, and is widely used in scenarios requiring high-performance network communication, such as the Internet of Things, distributed services, big data, and games.

[0088] In this embodiment, in response to receiving the target service message sent by the terminal device, when the terminal device first accesses the network, a connection request sent by the terminal device is received. The main event loop group receives and processes the connection request sent by the terminal device, completes the TCP three-way handshake, and registers the connection request to the working event loop group. Netty establishes a dedicated communication link (Channel) for the terminal device, adopting a single-device single-channel mode to achieve independent management of concurrent access by multiple devices.

[0089] The system integrates the Netty standard bidirectional codec component, supporting inbound byte stream decoding and outbound object encoding. Based on the ByteBuf probe reading mechanism, the Netty standard bidirectional codec component extracts protocol features from the ByteBuf byte stream without modifying the byte buffer read pointer, automatically identifying the initial protocol type used in the terminal device's connection request. Based on the Netty ChannelPipeline mechanism, the decoder corresponding to the identified initial protocol type is dynamically added to the data processing pipeline via the standard API `ChannelPipeline.addAfter()`, achieving adaptive protocol loading (loading the corresponding codec logic as soon as the corresponding protocol is detected).

[0090] Once the decoder is mounted, Netty triggers channelActive(), marking the formal establishment of the communication link. All subsequent communication data will be transmitted through this dedicated communication link.

[0091] Among them, the ByteBuf is a data container in Netty used to store binary byte streams.

[0092] ChannelPipeline refers to the channel pipeline, a chain of responsibility in Netty used to organize and execute logic such as data encoding / decoding and business processing.

[0093] ChannelPipeline.addAfter() is used to dynamically add a new decoder after a specified processor in the pipeline.

[0094] The `channelActive` event is a channel activation event that indicates a communication link has been successfully established. The connection request includes the initial protocol type, which can be MQTT, CoAP, TCP, or UDP, etc.

[0095] Optionally, the terminal device can be a photovoltaic inverter, smart meter, environmental sensor or gateway device, or a new energy device. It can be set independently according to the needs, and this embodiment does not limit it.

[0096] In this embodiment, Netty is used to listen to device connection requests at the underlying level, and Netty's standard bidirectional codec component is used to detect and identify the initial communication protocol of the device.

[0097] In this embodiment, the working event loop group receives the target service message sent by the terminal device. The protocol adaptation layer decodes the original message, identifies the protocol, and completes basic protocol parsing. Then, by matching a preset service feature library, it parses the service parameters in the message header to complete service classification and determine the target service level. The service classification processor of the protocol adaptation layer binds a target service level tag to the message and writes the tag into the attachment of the corresponding channel on the terminal device for end-to-end transmission. The tagged message is forwarded to the link quality monitoring module for weighted calculation of the network quality score of the communication link or for predicting the network quality score according to the service level.

[0098] The service classification can include multiple levels. The higher the service level, the higher the priority of the service message. For example, the first service level indicates that the service level is the highest and has the highest priority.

[0099] The business parameters include, but are not limited to, business type, instruction code, and data type.

[0100] The business type field identifies the purpose of the message (control / acquisition / logging). The instruction code identifies the specific operation (emergency stop, power adjustment, data reporting, log upload, etc.). The data type identifies the data attributes (real-time data / historical data / status data / log data).

[0101] For example, the preset business feature library may include a business type field, business meaning, and corresponding business level.

[0102] Optionally, the default business feature library is pre-defined.

[0103] For example, the preset business feature library can be:

[0104] Business Level: First business level; Business Type Field: Control command codes such as energy storage power regulation, inverter protection tripping, and remote emergency stop; Business Meaning: Core control business used for equipment regulation and safety protection.

[0105] Business Level: Second Business Level; Business Type Field: Identifiers for power operation data collection such as voltage, current, and power; Business Meaning: Real-time monitoring business reflecting the operating status of equipment and power grid.

[0106] Business Level: Third Business Level; Business Type Field: Data tags such as equipment operation logs, historical data, and ambient temperature and humidity; Business Meaning: Non-real-time auxiliary business used for status tracing and environmental monitoring.

[0107] Among them, the first business level, the second business level, and the third business level are business levels. In actual application, the business type field corresponding to each level can be visualized as standardized instruction codes, data type exclusive identifiers, etc., to complete the hierarchical classification and differentiation of different businesses.

[0108] For example, if the service message is determined to be a control command by the command code, the service level is directly determined to be the first service level. Service type / data type is only checked, not forced to match simultaneously. If the command code for the first service level is not matched, matching either the service type or data type is sufficient for level determination. If the service type field is a data acquisition field or the data type is real-time data, the service level is determined to be the second service level. If neither the command code for the first service level nor the determination criteria for the second service level are matched, level determination can still be made by either the service type or data type. When the data type is device operation log, historical data, or the service type is maintenance log, the service level is determined to be the third service level.

[0109] Understandably, the system prioritizes identifying whether the target service message contains core control commands such as remote emergency stop and power adjustment through instruction codes. If it does, the target service level is determined to be the first service level. If the target service message does not contain instruction codes corresponding to the first service level, the service type field or data type field in the target service message is matched. If the service type field or data type field in the target service message meets the characteristics corresponding to the second service level, the target service level is determined to be the second service level. If the target service level of the target service message is not determined to be the second service level, it is determined whether the corresponding data type or service type in the target service message matches the characteristics of the device operation log and historical data. If they match, the target service level is determined to be the third service level.

[0110] S202: The network quality score of the communication link is determined by using a preset network scoring algorithm and based on real-time network parameter data of the communication link.

[0111] Real-time network parameter data may include transmission delay data, bandwidth data, and packet loss rate.

[0112] Transmission delay data refers to the time required from the start of data transmission from the first bit to the completion of transmission of the last bit.

[0113] Packet loss rate refers to the ratio of the difference between the total number of data packets sent from the sending end through the communication link and the total number of data packets successfully received by the receiving end within a certain period of time, to the total number of data packets sent.

[0114] Bandwidth data refers to the maximum network bandwidth that a communication link can actually use to transmit data within a certain time period.

[0115] The target business level is either the first business level, the second business level, or the third business level.

[0116] It is understandable that Level 1 business corresponds to the first business level, Level 2 business corresponds to the second business level, and Level 3 business corresponds to the third business level. The first business level is the highest priority business level.

[0117] Specifically, step S202 includes S2021 to S2023:

[0118] S2021: The first, second, and third scores are determined using a preset scoring formula based on transmission delay data, bandwidth data, and packet loss rate.

[0119] The first score is for the transmission delay data. The second score is for the bandwidth data. The third score is for the packet loss rate.

[0120] The following preset scoring formula is used to calculate the scores for transmission delay data and packet loss rate:

[0121] Indicator score = 1 - (current value - minimum value) / (maximum value - minimum value).

[0122] The current value is the corresponding value obtained in real time, while the maximum and minimum values ​​are preset data.

[0123] The score can be the score corresponding to the transmission delay data, or it can be the score corresponding to the packet loss rate.

[0124] Optionally, the maximum and minimum values ​​for each parameter are preset values, which are not limited in this embodiment.

[0125] For example, the minimum value of the transmission delay data can be 50ms, and the maximum value can be 1000ms.

[0126] The preset minimum packet loss rate can be 0%, and the preset maximum rate can be 20%.

[0127] The following preset scoring formula is used to calculate the score corresponding to bandwidth data:

[0128] Bandwidth data score = (current value - minimum value) / (maximum value - minimum value).

[0129] For example, the preset minimum value of bandwidth data can be 100Kbps, and the maximum value can be 10Mbps.

[0130] In this embodiment, the link quality monitoring module collects real-time network parameter data of the communication link, and calculates the first score, second score and third score respectively using the formulas corresponding to transmission delay data, bandwidth data and packet loss rate.

[0131] If the terminal device is establishing a communication link for the first time, it retrieves preset transmission delay data, bandwidth data, and packet loss rate from a preset database as the current values. For communication links that have already transmitted data, it collects real-time network parameter data of the communication link.

[0132] S2022: Determine the target weights for transmission delay data, bandwidth data, and packet loss rate based on the target service level.

[0133] Here, the target service level refers to the service level corresponding to the received service message. The target weight refers to the weight corresponding to the target service level.

[0134] For example, in this embodiment, the link quality monitoring module reads the target service level corresponding to the service packet and matches the corresponding target weight from the preset weights according to the target service level.

[0135] For example, if the target service level is the first service level, the weight corresponding to transmission delay data is 0.5, the weight corresponding to bandwidth data is 0.1, and the weight corresponding to packet loss rate is 0.4. If the target service level is the second service level, the weight corresponding to transmission delay data is 0.3, the weight corresponding to bandwidth data is 0.3, and the weight corresponding to packet loss rate is 0.4. If the target service level is the third service level, the weight corresponding to transmission delay data is 0.2, the weight corresponding to bandwidth data is 0.2, and the weight corresponding to packet loss rate is 0.6.

[0136] For example, the weight corresponding to each business level can be set independently according to needs, and this embodiment does not impose any limitations.

[0137] The sum of the weights is 1.

[0138] S2023: The first, second, and third scores are weighted and summed based on the target weights to determine the network quality score of the communication link.

[0139] In this embodiment, the first score, the second score, and the third score are weighted and summed using the following formula to obtain the network quality score of the communication link.

[0140] LQ = W1 × first score + W2 × second score + W3 × third score.

[0141] Here, LQ represents the network quality score of the communication link. W1 is the weight corresponding to the transmission delay data. W2 is the weight corresponding to the bandwidth data. W3 is the weight corresponding to the packet loss rate.

[0142] Specifically, by dynamically matching the target weights of each network parameter for different service levels, the focus of quality evaluation can be flexibly adjusted according to the differences in transmission requirements of the first, second, and third service levels, so that the network quality score is highly adapted to the service transmission requirements.

[0143] S203: The predicted network quality score is determined by using a preset network prediction model and based on real-time network parameter data.

[0144] Specifically, step S203 includes S2031~S2032:

[0145] S2031: Obtain historical prediction network quality scores for a preset period.

[0146] The preset network prediction model is pre-trained until convergence.

[0147] Specifically, in this embodiment, historical prediction network quality scores for a preset period are obtained from a preset database.

[0148] Optionally, the preset period can be 5 periods, which is the prediction network quality score of the 5 predictions made before this.

[0149] Understandably, the historical prediction network quality score is based on previously predicted historical data.

[0150] Specifically, when a communication link is first established and the predicted network quality score is first calculated, the historical predicted network quality scores for a preset period are retrieved from the preset database for subsequent calculations. When a new predicted network quality score is calculated, the corresponding data in the corresponding historical predicted quality score is replaced.

[0151] For example, assuming the preset period is 3 periods, if the historical predicted network quality score for the preset period is (0.5, 0.6, 0.7) when the communication link is first created and the predicted network quality score is calculated for the first time, and then the predicted network quality score for the current period is calculated to be 0.65 based on the historical predicted network quality score for the preset period, then the historical predicted network quality score for the preset period obtained in the next calculation will be (0.6, 0.7, 0.65), and so on.

[0152] Another implementation method addresses the cold start scenario where there is no historical predicted network quality score when establishing a new communication link for terminal devices. The preset network prediction model completes the inference initialization using preset filling rules. It repeatedly fills the temporal feature bits of the preset period using the preset initial network quality score. The network indicators use the transmission delay data, bandwidth data, and default packet loss rate of the initial probe, and adopt the target service level. In this way, the cold start feature is constructed and the predicted network quality score is output. After the gateway continuously collects the historical predicted network quality scores of the preset period, it automatically exits the cold start mode and switches to the regular inference process of full real features.

[0153] S2032: Input the historical predicted network quality scores and the first, second and third scores of the preset period into the preset network prediction model, and output the predicted network quality score.

[0154] Specifically, in this embodiment, the historical predicted network quality scores for a preset period, along with the first score, the second score, the third score, and the target service level, are input into the preset network prediction model to obtain the output predicted network quality score.

[0155] For example, the training process of the preset network prediction model specifically involves collecting real data from communication links to obtain training samples. Each sample includes the real network quality score for the previous 8 consecutive sampling periods, the normalized transmission delay score, packet loss rate score, bandwidth data score, and service level for the current period. Simultaneously, the real LQ score for the next period is used as the label value for training the preset network prediction model. The above sample data is organized into a fixed 13-dimensional feature vector, where the first 8 dimensions are historical time-series LQ features, the middle 3 dimensions are real-time network indicator features, and the remaining 2 dimensions are service-level coding features. Then, all feature data undergoes standardized preprocessing, and a small amount of missing network indicator data is supplemented through linear interpolation. All features are uniformly mapped to the 0-1 interval to eliminate dimensional differences. After preprocessing, the dataset is divided into a training set and a validation set in an 8:2 ratio. The training set is used for model weight fitting, and the validation set is used to verify the model's generalization ability. The model uses the standard least squares method for closed-form fitting, with the training objective being to minimize the mean square error between the predicted network quality score and the actual network quality score. The feature weights and bias terms of the model are directly calculated without iterative optimization or hyperparameter tuning. The model is considered to have converged when the mean square error on the validation set is no higher than 0.005.

[0156] Specifically, by introducing historical network quality scores with a preset period, the limitations of predicting network quality solely with real-time network quality scores are overcome, allowing the model to make inferences based on historical trends and avoiding prediction biases caused by instantaneous network fluctuations.

[0157] S204: Determine the target communication protocol based on the predicted network quality score, the network quality score of the communication link, and the target service level.

[0158] Specifically, step S204 includes S2041~S2042:

[0159] S2041: In response to a predicted network quality score being less than or equal to a preset predicted score threshold, the transmission control protocol is determined as the target communication protocol.

[0160] Transmission Control Protocol (TCP) is the fundamental network protocol for connection-oriented and reliable transmission at the transmission layer. It establishes connections through a three-way handshake, provides acknowledgment, retransmits lost packets, and sorts packets.

[0161] For example, in this embodiment, if the protocol selection engine determines that the predicted network quality score is less than or equal to the preset predicted score threshold, it means that the network quality in the next cycle may not meet the stable operation conditions of the lightweight protocol. Since the transmission control protocol is a connection-oriented, reliable transmission transport layer protocol with acknowledgment, retransmission, flow control and congestion control mechanisms, the transmission control protocol is determined as the target communication protocol.

[0162] Optionally, the preset prediction score threshold can be set independently according to needs, and this embodiment does not impose any limitations.

[0163] For example, the preset prediction score threshold can be 0.35.

[0164] S2042: In response to the predicted network quality score being greater than the preset predicted score threshold, the target communication protocol is determined based on the network quality score of the communication link and the target service level.

[0165] As an optional implementation, based on any of the above embodiments, in response to the target service level being the second or third service level and the network quality score of the communication link being greater than or equal to the first preset threshold, the restricted application protocol is determined as the target communication protocol.

[0166] In response to the target service level being the first service level and the network quality score of the communication link being greater than or equal to the second preset threshold, the message queue telemetry transmission protocol is determined as the target communication protocol.

[0167] In response to a target service level of the second or third service level and a network quality score of the communication link that is less than the first preset threshold and greater than or equal to the second preset threshold, the message queue telemetry transmission protocol is determined as the target communication protocol.

[0168] If the network quality score of the communication link is less than a second preset threshold, the transmission control protocol is determined as the target communication protocol.

[0169] Optionally, the first preset threshold and the second preset threshold can be set independently according to needs, and this embodiment does not impose any limitations.

[0170] Among them, the Restricted Application Protocol is a lightweight connectionless application layer protocol encapsulated based on the Transport Layer User Datagram Protocol.

[0171] For example, in this embodiment, it is assumed that the first preset threshold is set to 0.85 and the second preset threshold is set to 0.8. In response to a target service level of the second or third service level and a network quality score of the communication link greater than or equal to 0.85, indicating that the current network environment quality is excellent and the link stability is high, capable of supporting lightweight, low-overhead, and highly reliable communication requirements, the restricted application protocol is determined as the target communication protocol.

[0172] For example, in this embodiment, in response to the target service level being the second or third service level and the network quality score of the communication link being less than 0.85 and greater than or equal to 0.8, it indicates that the current network environment quality is good, the link has a certain stability but has slight fluctuations, and it is suitable to use a lightweight, efficient message-based transmission protocol that is adapted to medium network conditions. Therefore, the message queue telemetry transmission protocol is determined as the target communication protocol.

[0173] For example, in this embodiment, in response to the target service level being the first service level and the network quality score of the communication link being greater than or equal to 0.8, indicating that the current network quality meets the basic reliable transmission requirements, the message queue telemetry transmission protocol is determined as the target communication protocol.

[0174] For example, in this embodiment, if the network quality score of the communication link is less than 0.8, the target service level is the first service level, the second service level, or the third service level, indicating that the current network quality is poor and the link fluctuates greatly. It is necessary to use a connection-oriented reliable transmission protocol with retransmission and flow control capabilities to ensure communication integrity. Therefore, the transmission control protocol is determined as the target communication protocol.

[0175] Specifically, the decision-making logic is divided by setting a preset prediction score threshold. First, a protocol is initially selected based on the predicted network quality score. If the network prediction is poor, a high-reliability transmission control protocol is directly adopted to avoid transmission failures in weak networks in advance. If the prediction is good, the decision is further refined by combining real-time network quality and service level. This approach uses the predicted value to achieve proactive protection while taking into account the real-time link status, avoiding blind protocol switching and improving the accuracy of network adaptation and transmission stability.

[0176] S205: If the target communication protocol is different from the current communication protocol, then switch the current communication protocol of the terminal device to the target communication protocol.

[0177] Specifically, in this embodiment, without interrupting the communication link or losing service data, the protocol processor is dynamically replaced by operating Netty's ChannelPipeline, achieving a seamless switch from the current communication protocol to the target communication protocol. Simultaneously, the terminal device is notified to switch synchronously, ensuring end-to-end protocol consistency. It is compatible with multiple protocols, and the communication protocol switching cost is low.

[0178] In this embodiment, the current protocol processor is removed by calling `ChannelPipeline.remove(String name)`. Based on the name of the current communication protocol, the corresponding communication protocol processor is removed from the pipeline of the communication link. The target communication protocol processor is added by calling `ChannelPipeline.addAfter(String baseName, String handlerName, ChannelHandler handler)`. Using the protocol detector as the base node, the target processor name is passed in, and a standard protocol processor is directly instantiated. The new protocol processor is dynamically attached to the pipeline, ensuring that data is first detected by the protocol and then processed by the new protocol. A communication protocol switching notification message is sent to the terminal device through the communication link. Upon receiving the message, the terminal device locally switches to the target communication protocol, avoiding data transmission failures caused by end-to-end protocol incompatibility.

[0179] The `ChannelPipeline.remove(String name)` method is a native Netty standard method that removes the current communication protocol processor from the channel pipeline based on its name. `Name` is the unique identifier of the current communication protocol processor within the pipeline.

[0180] The ChannelPipeline.addAfter(String baseName, String handlerName, ChannelHandler handler) method is a native Netty standard method used to dynamically insert a new communication protocol handler after the specified protocol detector in the channel pipeline.

[0181] Here, ChannelHandler is the smallest processing unit in the pipeline. baseName refers to the protocol detector, and handlerName is the identifier information of the processor corresponding to the target communication protocol. Handler is the processor instance corresponding to the target communication protocol.

[0182] In this embodiment, the communication protocol, time, and remote address of the terminal device before and after the switch are recorded in the communication protocol switch log to meet the requirements of traceability.

[0183] In summary, upon receiving a target service message from a terminal device, the system extracts service data, determines the target service level, and clarifies the service urgency, providing a priority basis for subsequent protocol decisions. It acquires real-time network parameter data for the communication link corresponding to the terminal device, obtains the current network quality score using a preset scoring algorithm, and derives a predicted network quality score based on the real-time network parameter data using a preset network prediction model, achieving a dual assessment of the current state and future trends. Finally, by combining the predicted network quality score, the real-time network quality score, and the target service level, the target communication protocol is determined. If the target communication protocol differs from the current communication protocol, the system switches the terminal device from the current protocol to the target protocol, resolving issues of poor adaptability to single protocols and delayed response to network changes, thereby improving the stability of the communication link.

[0184] As an optional implementation, based on any of the above embodiments, in response to the network quality score of the communication link being less than a third preset threshold, the communication parameters of the communication link are adjusted according to the target service level.

[0185] The communication parameters of the communication link include write buffer size, heartbeat interval time and write timeout time, and the third preset threshold is less than the second preset threshold.

[0186] The write buffer size refers to the capacity of the buffer used to temporarily store data to be sent. The heartbeat interval is the time period during which the gateway and terminal device periodically send heartbeat probe messages to monitor the communication link in real time and promptly detect anomalies such as link disconnection or device offline. The write timeout is the maximum allowed time for the gateway to wait for a response message from the terminal after writing the service message into the sending channel. If no valid response is received within this time, the current service message is considered to have failed to be sent, triggering the intelligent retransmission mechanism.

[0187] Optionally, the third preset threshold can be set independently according to needs, and is not limited in this embodiment.

[0188] For example, the third preset threshold may be 0.3, and the second preset threshold may be 0.8.

[0189] Specifically, when determining the target service level corresponding to the target service message, the communication parameters of the communication link are adjusted accordingly based on the different target service levels.

[0190] For example, the heartbeat interval for the first service level is 5 seconds, the write timeout is 10 seconds, and the write buffer size is 128KB. The heartbeat interval for the second service level is 15 seconds, the write timeout is 20 seconds, and the write buffer size is 64KB. The heartbeat interval for the third service level is 30 seconds, the write timeout is 30 seconds, and the write buffer size is 32KB.

[0191] In this embodiment, in response to the network quality score of the communication link being less than the third preset threshold, indicating that the current network quality is poor and cannot meet the established communication efficiency and stability requirements, the communication parameters of the communication link are adjusted. The adjusted parameters are the Netty parameters bound to the communication link, i.e., the configurable operating attributes of the communication link.

[0192] It is understandable that when the network quality score of the communication link is less than the third preset threshold, the current network can be considered to be in a weak network state.

[0193] Adjusting communication parameters of the communication link can be done by calling the Netty framework's ChannelOption interface, which is used to set configurable runtime properties of the Netty communication link. This adjustment process does not require restarting the communication link, allowing parameters to take effect dynamically, ensuring uninterrupted data transmission, and adapting to poor network environments to improve communication stability.

[0194] Specifically, if the network quality score of the communication link is less than a third preset threshold, the communication parameters of the communication link will be adjusted as follows.

[0195] For example, the heartbeat interval for the first service level is adjusted to 3 seconds, the write timeout to 15 seconds, and the write buffer size to 256KB. The heartbeat interval for the second service level is adjusted to 10 seconds, the write timeout to 25 seconds, and the write buffer size to 128KB. The heartbeat interval for the third service level is adjusted to 20 seconds, the write timeout to 35 seconds, and the write buffer size to 64KB.

[0196] The write buffer is a memory storage area allocated by Netty for each communication link, used to temporarily store communication data. Because network transmission speeds are much lower than transmission speeds in weak network environments, communication data will queue in the buffer waiting to be sent. If the buffer has no capacity limit, it will lead to memory overflow; if the capacity is too small, data packets will be dropped due to lack of storage space.

[0197] Specifically, the write buffer size, heartbeat interval, and write timeout corresponding to different target service levels can be set independently according to requirements, and this embodiment does not impose any limitations.

[0198] Specifically, when the network quality score is lower than the third preset threshold, the write buffer size, heartbeat interval, and write timeout time are adaptively adjusted according to the service level, which can dynamically adapt to the characteristics of weak network transmission and improve the stability of communication links.

[0199] As an optional implementation, based on any of the above embodiments, after switching the current communication protocol of the terminal device to the target communication protocol, the method further includes:

[0200] In response to the target service level being the first service level, the target service message is compressed according to the first preset compression ratio;

[0201] In response to the target service level being the second service level and the target communication protocol being a restricted application protocol, the target service message is compressed according to the second preset compression ratio;

[0202] In response to the target service level being the second service level and the target communication protocol being the message queue telemetry transmission protocol or the transmission control protocol, the target service message is compressed according to the third preset compression ratio;

[0203] In response to the target service level being the third service level and the target communication protocol being a restricted application protocol, the target service message is compressed according to the fourth preset compression ratio;

[0204] In response to the target service level being the third service level and the target communication protocol being the message queue telemetry transmission protocol or the transmission control protocol, the target service message is compressed according to the fifth preset compression ratio.

[0205] The third preset compression ratio is greater than the second preset compression ratio. The fifth preset compression ratio is greater than the fourth preset compression ratio.

[0206] For example, the first preset compression ratio can be in the range of 10% to 20%. The second preset compression ratio is less than or equal to 10%. The third preset compression ratio can be in the range of 30% to 40%. The fourth preset compression ratio can be in the range of 10% to 20%. The fifth preset compression ratio can be in the range of 50% to 70%.

[0207] Optionally, the first preset compression, the second preset compression ratio, the third preset compression ratio, the fourth preset compression ratio, and the fifth preset compression ratio can be set independently according to needs after the preset size setting is met; this embodiment does not impose any limitations.

[0208] In this embodiment, Netty's native Deflate algorithm compression encoder is used to perform real-time lightweight compression on the outbound data sent to the terminal device, which is the outbound implementation of the data compression mechanism.

[0209] In this embodiment, the inbound compressed data sent by the terminal device is decompressed and restored in real time using Netty's native Deflate algorithm decompression decoder, which is an inbound supporting implementation of the data compression mechanism.

[0210] For example, in this embodiment, after the current communication protocol of the terminal device is switched to the target communication protocol, the target service message is obtained and the target service level corresponding to the target service message is read. In response to the target service level being the first service level, it indicates that the service message is a high-priority core service with extremely high real-time transmission requirements and a small data volume. Therefore, there is no need for an excessively high compression ratio to avoid affecting the message parsing efficiency. The target service message is compressed at a compression ratio of 15%.

[0211] For example, in this embodiment, in response to the target service level being the second service level and the target communication protocol being a restricted application protocol, it indicates that the service message is regular service data. Restricted application protocols themselves have limited transmission bandwidth and weak message carrying capacity, requiring a lower compression ratio to balance transmission efficiency and data integrity. Therefore, the target service message is compressed at a compression ratio of 8%. In response to the target service level being the second service level and the target communication protocol being a message queue telemetry transport protocol or a transmission control protocol, it indicates that the service message is regular service data. Message queue telemetry transport protocols and transmission control protocols have stable transmission channels and large bandwidth carrying capacity, allowing for a moderate increase in the compression ratio to reduce transmission resource consumption. Therefore, the target service message is compressed at a compression ratio of 30%.

[0212] For example, in this embodiment, in response to the target service level being the third service level and the target communication protocol being a restricted application protocol, it indicates that the service message is a low-priority non-real-time service. The restricted application protocol has limited transmission capacity, requiring a moderate compression ratio to reduce transmission load while ensuring normal message parsing. Therefore, the target service message is compressed at a compression ratio of 10%. In response to the target service level being the third service level and the target communication protocol being a message queue telemetry transport protocol or a transmission control protocol, it indicates that the service message is a low-priority non-real-time service, insensitive to transmission latency and typically has a large data volume. Therefore, a high compression ratio can be used to maximize message volume compression and save transmission bandwidth. Therefore, the target service message is compressed at a compression ratio of 50%.

[0213] Specifically, by configuring compression ratios differently according to target service levels and target communication protocols, different service priorities and protocol characteristics can be adapted to reduce message transmission volume, reduce transmission pressure and packet loss probability in weak network environments, and improve message transmission efficiency.

[0214] As an optional implementation, based on any of the above embodiments, it further includes:

[0215] In response to the satisfaction of preset retransmission conditions, the target retransmission strategy is determined based on the target service level and target communication protocol of the target service message;

[0216] A target retransmission strategy is adopted to transmit target service messages.

[0217] The preset retransmission conditions are that the write timeout exceeds the preset time threshold or the received target service message is lost.

[0218] Optionally, the preset time threshold corresponds to the write timeout in the communication parameters of the communication link, depending on the target service level of the target service message. Different target service levels correspond to different preset time thresholds.

[0219] Specifically, a native Netty write timeout handler is attached to the Netty pipeline, setting a corresponding preset time threshold. Specifically, the Netty native timeout monitoring handler, WriteTimeoutHandler, monitors data writing operations to the communication link. If data is written but not successfully transmitted within the preset time threshold (i.e., the terminal device does not respond or the data is not sent), a write timeout exception is triggered. A retransmission handler is attached to the pipeline, determining the target retransmission strategy based on the target service level and target communication protocol of the target service message. After a timeout exception is captured, the unsuccessfully transmitted data is automatically retransmitted. If a retransmission is successful, the retry is immediately terminated; if it still fails after reaching the preset number of retransmissions, it will be handled by an upper-layer fault tolerance mechanism (such as resume interrupted transmission, session persistence, etc.).

[0220] Specifically, the link quality monitoring module detects the loss of target service packets by verifying packet sequence numbers and determining missing responses, and directly triggers the retransmission process. Based on the target service level and target communication protocol of the target service packets, a target retransmission strategy is determined, and the target service packets are transmitted using the target retransmission strategy.

[0221] Specifically, by dynamically determining the retransmission strategy based on the service level and communication protocol of the target service message, it is possible to adapt to the transmission reliability requirements and protocol characteristics of different services, and avoid the loss of critical data or waste of network resources caused by a unified retransmission mechanism.

[0222] As an optional implementation, based on any of the above embodiments, a target retransmission strategy is used to transmit the target service message, including:

[0223] In response to the target service level being the first service level, data is transmitted to the target service message according to the first preset interval time and the first preset number of retransmissions.

[0224] In response to the target service level being the second service level, data is transmitted to the target service message according to the second preset interval time and the second preset number of retransmissions.

[0225] In response to the target service level being the third service level, data is transmitted to the target service message according to the third preset interval time and the third preset number of retransmissions.

[0226] Among them, the first preset retransmission number is greater than the second preset retransmission number, and the second preset retransmission number is greater than the third preset retransmission number.

[0227] Optionally, the first preset interval time, the second preset interval time, and the third preset interval time can be set independently according to requirements, and are not limited in this embodiment.

[0228] It is understandable that the number of retransmissions directly determines the upper limit of retries after a message is lost, and is a core parameter for ensuring transmission reliability.

[0229] Understandably, the first service level is the highest priority service, which has extremely high requirements for message delivery rate. Therefore, the maximum number of retransmissions is configured to minimize packet loss rate through multiple retries, ensuring uninterrupted service and no data loss.

[0230] Understandably, the priority of the second and third service tiers decreases sequentially, and the requirements for transmission reliability gradually relax, thus reducing the number of retransmissions at each tier. Even if a small number of packets are lost in low-priority services, the impact on the service is minimal, and reducing the number of retransmissions avoids wasting network bandwidth and equipment computing power on ineffective retries.

[0231] The retransmission interval determines the timing of message retries, which directly affects transmission delay and network congestion.

[0232] Understandably, the first service level employs an exponential backoff interval. By initially shortening the retransmission interval, it ensures that high-priority packets are quickly retried and delivered in a timely manner. If a retry fails, the interval is gradually lengthened to avoid network congestion caused by frequent retransmissions in a short period of time, thus balancing high-reliability transmission with network congestion avoidance.

[0233] Understandably, the second and third service levels use fixed intervals, with the interval duration increasing progressively; the lower the priority, the longer the retransmission interval. On one hand, low-priority services are not sensitive to transmission latency, so a longer interval will not affect the service experience. On the other hand, extending the retransmission interval reduces the impact of low-priority packets on the network, freeing up network resources for high-priority services, while also preventing a large number of low-priority packets from being retransmitted simultaneously, thus avoiding exacerbating network congestion.

[0234] Optionally, the first preset number of retransmissions, the second preset number of retransmissions, and the third preset number of retransmissions can also be set independently based on satisfying the preset size relationship; this embodiment does not impose any limitations on these settings.

[0235] For example, the first preset retransmission count can be 5 times, the second preset retransmission count can be 3 times, and the third preset retransmission count can be 1 time.

[0236] For example, the first preset interval time may not be a fixed value, but an exponential backoff interval. The second preset interval time may be 1 second, and the third preset interval time may be 2 seconds.

[0237] For example, in response to the target service level being the first service level, the system may send a first retransmission, wait 1 second, send a second retransmission, wait 2 seconds, send a third retransmission, wait 4 seconds, send a fourth retransmission, wait 8 seconds, and send a fifth retransmission, wait 16 seconds before sending.

[0238] Specifically, refined hierarchical transmission control is achieved by configuring corresponding retransmission intervals and retransmission counts according to the first, second, and third service levels. High-level services receive more retransmission guarantees to ensure reliable instruction transmission, while medium and low-level services adopt a moderate retransmission strategy to reduce invalid retransmissions and network congestion.

[0239] As an optional implementation, based on any of the above embodiments, it further includes:

[0240] In response to a predicted network quality score being less than or equal to a preset predicted score threshold, the target service level of the target service packet is determined.

[0241] In response to the target service message being classified as a first-level service message, the target service message is cached.

[0242] It is understandable that if the predicted network quality score is less than or equal to the preset predicted score threshold, it can be interpreted as a high probability that the network will deteriorate later.

[0243] Specifically, in this embodiment, if the weak network degradation module determines that the predicted network quality score is less than or equal to the preset predicted score threshold, it reads the service level tag in the target service packet to obtain the target service level. If the target service level is the first service level, the local caching module caches the target service packet locally.

[0244] Specifically, when poor network quality is predicted, identifying and caching primary service packets in advance can avoid packet loss and timeouts caused by sending instructions directly under weak network conditions, reduce bandwidth waste and link congestion caused by invalid retransmissions, ensure that critical control instructions are not lost, and improve the reliability of high-priority service transmission and system stability.

[0245] As an optional implementation, based on any of the above embodiments, it further includes:

[0246] If the predicted network quality score is greater than a preset predicted score threshold and the network quality score of the communication link is less than a third preset threshold, then it is determined that there is an anomaly in the communication link.

[0247] In response to the target service level of the target service message being the first service level, the failed target service message will be buffered, and it will be determined whether the communication link has been restored to normal.

[0248] In response to the restoration of normal communication links, the cached target service messages will be retransmitted.

[0249] Optionally, the third preset threshold can be set independently according to needs, and is not limited in this embodiment.

[0250] The predicted network quality score is a theoretically expected network quality score calculated based on information such as bandwidth data and historical operational data of the communication link. A preset predicted score threshold defines the lower limit of the link's expected normal performance. A predicted network quality score greater than the preset predicted score threshold indicates that the communication link's theoretical performance meets the standard.

[0251] The network quality score for the communication link is an actual operational quality score obtained by real-time monitoring of dynamic indicators such as latency, packet loss rate, and bandwidth. It is a direct reflection of the current true operational status of the communication link. The third preset threshold is the lower limit for the actual operational quality of the link. If the actual score is lower than this threshold, it means that the current actual transmission performance of the link has not met the qualified standard.

[0252] Therefore, when the predicted network quality score is greater than the preset predicted score threshold and the network quality score of the communication link is less than the third preset threshold, it indicates that there is a real operational anomaly in the current communication link and a weak network state. In this case, the first service level message is first buffered and sent after the current communication link returns to normal.

[0253] For example, the third preset threshold can be 0.3.

[0254] Specifically, in this embodiment, if the weak network degradation module determines that the predicted network quality score is greater than the preset predicted score threshold and the network quality score of the communication link is less than the third preset threshold, then it is determined that there is an anomaly in the communication link. If the target service level of the target service packet is the first service level, the local caching module will send the failed target service packet for caching and check the link status at preset intervals. When the network quality score of the communication link is greater than or equal to the third preset threshold link, it is determined that the communication link has recovered and is normal, and the caching instruction is immediately resent.

[0255] For example, in this embodiment, for service messages of the second service level, if there is an anomaly in the communication link and the buffer retransmission is not initiated, and the service message fails to be sent, a retransmission is performed. After three failed retransmissions, the current message is discarded directly, and new messages are received normally after the communication link is restored.

[0256] For example, in this embodiment, for service messages of the third service level, if there is an anomaly in the communication link and the buffer retransmission is not initiated, and the service message fails to be sent, a retransmission is performed. After one retransmission failure, the current message is discarded directly, and new messages are received normally after the communication link is restored.

[0257] The number of retransmissions for the second and third service levels can be set independently according to requirements, and is not limited in this embodiment.

[0258] The weak network degradation module and the local caching module are independently configured service enhancement modules for the Netty IoT protocol gateway, operating at the same service level as the protocol adaptation layer, link quality monitoring module, and intelligent retransmission module. The weak network degradation module executes weak network status determination and tiered degradation logic, while the local caching module stores breakpoint resumed transmissions of primary service commands. Both modules are independent of the Netty native communication core layer, achieving data interaction and logical linkage through the gateway's internal interface.

[0259] Specifically, by combining predicted quality with real-time link status to identify anomalies, failed first-level service packets are cached and retransmitted after the link is restored. This avoids frequent retransmissions that exacerbate network degradation while ensuring the reliable delivery of critical control commands, thus achieving orderly transmission in abnormal scenarios and improving communication robustness and service continuity.

[0260] Figure 3 This is a schematic diagram of the communication protocol switching device provided in the embodiments of this application, as shown below. Figure 3 As shown, the communication protocol switching device 30 provided in this embodiment includes: a determining module 301 and a switching module 302.

[0261] Specifically, the determining module 301 is used to determine the target service level based on the target service message received from the terminal device; the target service message includes service data; the target service level is used to indicate the urgency level of the service data; the determining module 301 is also used to determine the network quality score of the communication link by using a preset network scoring algorithm and based on real-time network parameter data of the communication link; the communication link is established based on the terminal device; the determining module 301 is also used to determine the predicted network quality score by using a preset network prediction model and based on real-time network parameter data; the determining module 301 is also used to determine the target communication protocol based on the predicted network quality score, the network quality score of the communication link, and the target service level; the switching module 302 is used to switch the current communication protocol of the terminal device to the target communication protocol if the target communication protocol is different from the current communication protocol.

[0262] Optionally, real-time network parameter data includes transmission delay data, bandwidth data, and packet loss rate. The target service level is either the first service level, the second service level, or the third service level.

[0263] Accordingly, the determining module 301, when determining the network quality score of the communication link using a preset network scoring algorithm and based on real-time network parameter data of the communication link, specifically performs the following: determining a first score, a second score, and a third score using a preset scoring formula and based on transmission delay data, bandwidth data, and packet loss rate; the first score is the score corresponding to the transmission delay data; the second score is the score corresponding to the bandwidth data; the third score is the score corresponding to the packet loss rate; determining the target weights corresponding to the transmission delay data, bandwidth data, and packet loss rate based on the target service level; and performing a weighted summation of the first score, the second score, and the third score based on the target weights to determine the network quality score of the communication link.

[0264] Optionally, the determining module 301, when using a preset network prediction model and determining the predicted network quality score based on real-time network parameter data, is specifically used to: obtain historical predicted network quality scores for a preset period; input the historical predicted network quality scores for the preset period and the first score, second score, and third score into the preset network prediction model, and output the predicted network quality score; the preset network prediction model is pre-trained to convergence.

[0265] Optionally, when determining the target communication protocol based on the predicted network quality score, the network quality score of the communication link, and the target service level, the determining module 301 is specifically used to: determine the transmission control protocol as the target communication protocol in response to the predicted network quality score being less than or equal to a preset predicted score threshold; and determine the target communication protocol based on the network quality score of the communication link and the target service level in response to the predicted network quality score being greater than the preset predicted score threshold.

[0266] Optionally, when determining the target communication protocol based on the network quality score of the communication link and the target service level, the determining module 301 is specifically configured to: determine the restricted application protocol as the target communication protocol in response to the target service level being the second or third service level and the network quality score of the communication link being greater than or equal to a first preset threshold; determine the message queue telemetry transmission protocol as the target communication protocol in response to the target service level being the first service level and the network quality score of the communication link being greater than or equal to a second preset threshold; determine the message queue telemetry transmission protocol as the target communication protocol in response to the target service level being the second or third service level and the network quality score of the communication link being less than the first preset threshold but greater than or equal to the second preset threshold; and determine the transmission control protocol as the target communication protocol in response to the network quality score of the communication link being less than the second preset threshold.

[0267] Optionally, the communication protocol switching device may also include an adjustment module.

[0268] Accordingly, the adjustment module is used to adjust the communication parameters of the communication link based on the target service level in response to the network quality score of the communication link being less than the third preset threshold; the communication parameters of the communication link include the write buffer size, heartbeat interval time and write timeout time, and the third preset threshold is less than the second preset threshold.

[0269] Optionally, the communication protocol switching device may also include a compression module.

[0270] Accordingly, the compression module is used to, after switching the current communication protocol of the terminal device to the target communication protocol, compress the target service message according to a first preset compression ratio in response to the target service level being a first service level; compress the target service message according to a second preset compression ratio in response to the target service level being a second service level and the target communication protocol being a restricted application protocol; compress the target service message according to a third preset compression ratio in response to the target service level being a second service level and the target communication protocol being a message queue telemetry transmission protocol or a transmission control protocol; the third preset compression ratio is greater than the second preset compression ratio; compress the target service message according to a fourth preset compression ratio in response to the target service level being a third service level and the target communication protocol being a restricted application protocol; and compress the target service message according to a fifth preset compression ratio in response to the target service level being a third service level and the target communication protocol being a message queue telemetry transmission protocol or a transmission control protocol; the fifth preset compression ratio is greater than the fourth preset compression ratio.

[0271] Optionally, the communication protocol switching device may also include a transmission module.

[0272] Accordingly, the determining module 301 is used to determine the target retransmission strategy based on the target service level and target communication protocol of the target service message in response to the satisfaction of the preset retransmission conditions; the preset retransmission conditions are that the write timeout is greater than a preset time threshold or the received target service message is lost. The transmission module is used to transmit the target service message using the target retransmission strategy.

[0273] Optionally, when the transmission module transmits data to the target service message using the target retransmission strategy, it is configured to transmit the target service message according to a first preset interval and a first preset number of retransmissions in response to the target service level being a first service level; transmit the target service message according to a second preset interval and a second preset number of retransmissions in response to the target service level being a second service level; and transmit the target service message according to a third preset interval and a third preset number of retransmissions in response to the target service level being a third service level; wherein the first preset number of retransmissions is greater than the second preset number of retransmissions, and the second preset number of retransmissions is greater than the third preset number of retransmissions.

[0274] Optionally, the communication protocol switching device may also include a buffer module.

[0275] Accordingly, the determining module 301 is used to determine the target service level of the target service packet in response to the predicted network quality score being less than or equal to a preset predicted score threshold. The caching module is used to cache the target service packet in response to the target service level being the first service level.

[0276] Optionally, the communication protocol switching device may also include a sending module.

[0277] Accordingly, the determining module 301 is used to determine that the communication link is currently abnormal if the predicted network quality score is greater than a preset predicted score threshold and the network quality score of the communication link is less than a third preset threshold; and if the target service level of the target service message is the first service level, the failed target service message is cached, and it is determined whether the communication link has returned to normal. The sending module is used to resend the cached target service message if the communication link has returned to normal.

[0278] The communication protocol switching device provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.

[0279] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 4As shown, the electronic device 40 provided in this embodiment includes at least one processor 401 and a memory 402. Optionally, the electronic device further includes a communication component 403. The processor 401, memory 402, and communication component 403 are connected via a bus.

[0280] In a specific implementation, at least one processor 401 executes computer execution instructions stored in memory 402, causing at least one processor 401 to perform the above-described method.

[0281] The specific implementation process of processor 401 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.

[0282] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.

[0283] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.

[0284] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.

[0285] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0286] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.

[0287] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.

[0288] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.

[0289] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0290] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0291] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0292] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0293] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.

[0294] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.

Claims

1. A method for switching communication protocols, characterized in that, include: In response to receiving a target service message sent by a terminal device, the target service level is determined based on the target service message; The target service message includes service data; the target service level is used to indicate the urgency level of the service data. A preset network scoring algorithm is used to determine the network quality score of the communication link based on real-time network parameter data of the communication link; The communication link is established based on the terminal device; A preset network prediction model is used, and a predicted network quality score is determined based on the real-time network parameter data. The target communication protocol is determined based on the predicted network quality score, the network quality score of the communication link, and the target service level. If the target communication protocol is different from the current communication protocol, then the current communication protocol of the terminal device will be switched to the target communication protocol.

2. The method according to claim 1, characterized in that, The real-time network parameter data includes transmission delay data, bandwidth data, and packet loss rate; The target business level is the first business level, the second business level, or the third business level; The process of determining the network quality score of the communication link using a preset network scoring algorithm and based on real-time network parameter data of the communication link includes: A first score, a second score, and a third score are determined using a preset scoring formula based on the transmission delay data, the bandwidth data, and the packet loss rate; the first score is the score corresponding to the transmission delay data; the second score is the score corresponding to the bandwidth data; and the third score is the score corresponding to the packet loss rate. Based on the target service level, the target weights corresponding to the transmission delay data, the bandwidth data, and the packet loss rate are determined respectively. The first score, the second score, and the third score are weighted and summed based on the target weights to determine the network quality score of the communication link.

3. The method according to claim 2, characterized in that, The step of using a preset network prediction model and determining the predicted network quality score based on the real-time network parameter data includes: Obtain historical prediction network quality scores for a preset period; The historical prediction network quality score of the preset period, the first score, the second score, and the third score are input into the preset network prediction model, and the prediction network quality score is output; the preset network prediction model is pre-trained to convergence.

4. The method according to claim 1, characterized in that, The step of determining the target communication protocol based on the predicted network quality score, the network quality score of the communication link, and the target service level includes: In response to the predicted network quality score being less than or equal to a preset predicted score threshold, the transmission control protocol is determined as the target communication protocol; In response to the predicted network quality score being greater than a preset predicted score threshold, the target communication protocol is determined based on the network quality score of the communication link and the target service level.

5. The method according to claim 4, characterized in that, The determination of the target communication protocol based on the network quality score of the communication link and the target service level includes: In response to the target service level being the second or third service level and the network quality score of the communication link being greater than or equal to the first preset threshold, the restricted application protocol is determined as the target communication protocol. In response to the target service level being the first service level and the network quality score of the communication link being greater than or equal to the second preset threshold, the message queue telemetry transmission protocol is determined as the target communication protocol. In response to the target service level being the second or third service level and the network quality score of the communication link being less than the first preset threshold and greater than or equal to the second preset threshold, the message queue telemetry transmission protocol is determined as the target communication protocol. If the network quality score of the communication link is less than a second preset threshold, the transmission control protocol is determined as the target communication protocol.

6. The method according to claim 5, characterized in that, The method further includes: In response to the network quality score of the communication link being less than a third preset threshold, the communication parameters of the communication link are adjusted according to the target service level; the communication parameters of the communication link include write buffer size, heartbeat interval time and write timeout time, and the third preset threshold is less than the second preset threshold.

7. The method according to any one of claims 1-6, characterized in that, After switching the current communication protocol of the terminal device to the target communication protocol, the method further includes: In response to the target service level being the first service level, the target service message is compressed according to the first preset compression ratio; In response to the target service level being the second service level and the target communication protocol being a restricted application protocol, the target service message is compressed according to the second preset compression ratio; In response to the target service level being the second service level and the target communication protocol being a message queue telemetry transmission protocol or a transmission control protocol, the target service message is compressed according to a third preset compression ratio; the third preset compression ratio is greater than the second preset compression ratio; In response to the target service level being the third service level and the target communication protocol being a restricted application protocol, the target service message is compressed according to a fourth preset compression ratio; In response to the target service level being the third service level and the target communication protocol being a message queue telemetry transmission protocol or a transmission control protocol, the target service message is compressed according to a fifth preset compression ratio; the fifth preset compression ratio is greater than the fourth preset compression ratio.

8. The method according to any one of claims 1-6, characterized in that, The method further includes: In response to the satisfaction of preset retransmission conditions, a target retransmission strategy is determined based on the target service level and target communication protocol of the target service packet; the preset retransmission conditions are that the write timeout is greater than a preset time threshold or the received target service packet is lost. The target retransmission strategy is used to transmit the target service message.

9. The method according to claim 8, characterized in that, The process of transmitting data to the target service packet using the target retransmission strategy includes: In response to the target service level being a first service level, the target service message is transmitted according to a first preset interval time and a first preset number of retransmissions; In response to the target service level being the second service level, the target service message is transmitted according to the second preset interval time and the second preset number of retransmissions; In response to the target service level being the third service level, the target service message is transmitted according to a third preset interval time and a third preset retransmission number; the first preset retransmission number is greater than the second preset retransmission number, and the second preset retransmission number is greater than the third preset retransmission number.

10. The method according to any one of claims 1-6, characterized in that, The method further includes: In response to a predicted network quality score being less than or equal to a preset predicted score threshold, the target service level of the target service packet is determined. In response to the target service level of the target service message being the first service level, the target service message is cached.

11. The method according to any one of claims 1-6, characterized in that, The method further includes: If the predicted network quality score is greater than a preset predicted score threshold and the network quality score of the communication link is less than a third preset threshold, then it is determined that there is an anomaly in the communication link. In response to the target service level of the target service message being the first service level, the failed target service message is buffered, and it is determined whether the communication link has been restored to normal. In response to the restoration of normal communication links, the cached target service messages will be retransmitted.

12. A communication protocol switching device, characterized in that, include: A determination module is configured to, in response to receiving a target service message sent by a terminal device, determine a target service level based on the target service message; the target service message includes service data; the target service level is used to indicate the urgency level of the service data. The determining module is further configured to determine the network quality score of the communication link using a preset network scoring algorithm and based on real-time network parameter data of the communication link; the communication link is established based on the terminal device; The determination module is also used to determine the predicted network quality score based on the preset network prediction model and the real-time network parameter data; The determining module is further configured to determine the target communication protocol based on the predicted network quality score, the network quality score of the communication link, and the target service level; The switching module is used to switch the current communication protocol of the terminal device to the target communication protocol if the target communication protocol is different from the current communication protocol.

13. An electronic device, characterized in that, include: Memory, processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the method as described in any one of claims 1-11.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-11.

15. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method described in any one of claims 1-11.