A method and system for plug-in independent operation of Internet of Things (IoT) protocols

By encapsulating independent protocol plugins in IoT gateways and establishing unified lifecycle interfaces and independent channels, the problems of high protocol coupling and insufficient fault isolation capabilities in multi-protocol gateways are solved. This enables independent operation and fault isolation of protocol plugins, reducing system resource consumption and maintenance difficulty.

CN123075112APending Publication Date: 2026-11-10SHENZHEN SHUYING TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611581604.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-13
Publication Date
2026-11-10

AI Technical Summary

Technical Problem

Existing multi-protocol bearer solutions in IoT gateways suffer from problems such as high protocol coupling, high resource consumption, lack of fault isolation capabilities, lack of independent protocol upgrade and scaling support, inconsistent initialization and scheduling interfaces, and reuse of communication channels between the control plane and data plane, which increases system stability and maintenance difficulty.

Method used

Each communication protocol is encapsulated as an independent protocol plugin, providing a unified lifecycle interface. Independent command and data channels are loaded and established through the protocol manager. Management commands and data are transmitted using request-response and publish-subscribe methods, and a fault detection and recovery mechanism is implemented to support the independent operation and maintenance of protocol plugins.

Benefits of technology

It enables independent operation and fault isolation of multiple communication protocols in resource-constrained environments, reduces the difficulty of protocol access and maintenance, improves system stability and maintainability, supports individual upgrades and extensions of protocol plugins, and reduces resource consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123075112A_ABST
    Figure CN123075112A_ABST
Patent Text Reader

Abstract

This invention discloses a method and system for independent operation of IoT protocol plug-ins. The method includes: encapsulating each communication protocol as a dynamic library, with independent plug-ins containing initialization / run / exit interfaces; a protocol manager loading the plug-ins to establish resources and connections, and establishing a request-response command channel and a publish-subscribe data channel for each plug-in; calling the run interface to keep the plug-in running continuously, sending and receiving management commands and results via the command channel, and receiving reported data via the data channel; periodically sending collection requests and determining the running status based on whether a valid result is returned after a timeout; exiting and restarting the plug-in in case of a fault, stopping recovery after reaching the maximum number of restarts. By implementing this method, multiple communication protocols can run independently, be isolated from each other, and be maintained independently in a resource-constrained embedded IoT gateway.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the Internet of Things (IoT), and more specifically to a method and system for the independent operation of IoT protocol plug-ins. Background Technology

[0002] With the development of IoT technology, embedded IoT gateways are widely used in smart kitchen appliances, smart weighing, industrial gateways, and agricultural IoT. These gateways typically need to support multiple north-south communication protocols simultaneously within a single device, such as Modbus, MQTT, ZMQ, and various proprietary protocols, as well as OTA upgrades and LED control, to enable the connection of various components or managed devices downstream and the integration with cloud platforms or upper-level business systems upstream.

[0003] Currently, there are three main types of solutions for implementing multi-protocol transport in gateways: First, the monolithic embedded software solution, which statically compiles multiple protocol stacks into the same executable file, allowing all protocols to share the same process space; second, the microservice solution represented by EdgeX Foundry, which isolates each device service through containers and relies on a container orchestration system for lifecycle management. However, this type of solution has high runtime resource consumption and is difficult to implement directly on resource-constrained embedded Linux gateways; third, the in-process dynamic module solution, such as ROS nodelet, OSGi, and Mosquitto plugin. Although these provide in-process dynamic loading mechanisms, they are all loaded within the same process, lack protocol-level fault isolation capabilities, and have non-universal interfaces that are not oriented towards C / C++ embedded protocol stacks.

[0004] However, the above solutions all have shortcomings: high protocol coupling, requiring recompiling the entire firmware when adding or upgrading protocols, resulting in a large workload for regression testing; a single protocol stack crash or deadlock can cause abnormal processes in the entire machine, lacking protocol-level fault isolation capabilities; the protocols do not support independent upgrades and independent scaling, making it impossible to upgrade a single protocol module or scale the same protocol horizontally based on the number of device instances; the initialization, scheduling, resource release, subscription, and data reporting interfaces of each protocol component are not unified, lacking standardized plug-in interfaces, making it difficult to achieve unified operation and maintenance and monitoring; there is a lack of health check and rate-limiting restart mechanisms adapted to embedded devices; in addition, the control plane and data plane reuse communication channels, and once the data plane is blocked or flooded, control plane operations such as start / stop, restart, and health checks will fail, making it impossible to intervene in faults in a timely manner.

[0005] Therefore, it is necessary to design a new method to enable multiple communication protocols to run independently, in isolation, and be maintained independently in resource-constrained embedded IoT gateways. Summary of the Invention

[0006] The purpose of this invention is to overcome the shortcomings of the prior art and provide a method and system for independent operation of IoT protocol plug-ins.

[0007] To achieve the above objectives, the present invention adopts the following technical solution: a method for plug-in independent operation of an Internet of Things (IoT) protocol, comprising: Each communication protocol is encapsulated as an independent protocol plugin, and the protocol plugin provides a unified lifecycle interface in the form of a dynamic library. The lifecycle interface includes an initialization interface, a running interface, and an exit interface. The protocol manager loads the protocol plugin and calls the initialization interface to establish the resources and communication connections required for operation. It establishes an instruction channel and a data channel for each protocol plugin. The instruction channel and the data channel are independent of each other. The instruction channel transmits management instructions and their processing results in a request-response manner. The data channel transmits the data reported by the protocol plugin in a publish-subscribe manner. The protocol plugin is continuously run by calling the running interface, management commands are issued through the command channel and corresponding command processing results are received, and data reported by the protocol plugin is received through the data channel. According to a predetermined cycle, a collection request is sent to the protocol plugin through the instruction channel. The running status of the protocol plugin is determined based on whether the protocol plugin returns a valid collection result within a preset time. When the running state is a fault state, fault recovery is performed on the protocol plugin, wherein the exit interface is called to stop the protocol plugin, and the protocol plugin is reloaded and started; when the number of restarts of the protocol plugin reaches a preset limit within a predetermined time, fault recovery of the protocol plugin is stopped.

[0008] The further technical solution is as follows: the initialization interface is used to establish the resources, parameters and communication connections required for the protocol plugin to run; The runtime interface is used to perform the continuous work of the protocol plugin; The exit interface is used to release the resources occupied by the protocol plugin and stop the protocol plugin; The initialization interface, the running interface, and the exit interface have a unified interface form in the protocol plugins corresponding to different types of communication protocols.

[0009] The further technical solution is as follows: the protocol manager assigns a communication address to each protocol plugin individually, and establishes the instruction channel and the data channel corresponding to the protocol plugin based on the assigned communication address; The management commands include start configuration commands, device acquisition commands, stop commands, restart commands, and running status query commands; if the protocol manager does not receive the corresponding command processing result within the specified waiting time after issuing the management command through the command channel, it determines that the command communication is abnormal. The data channel is also used to transmit device events actively generated by the protocol plugin, periodically collected data, and status change information. The data channel does not carry the management instructions, so that when the data channel is blocked, the protocol manager can still perform running status query, stop, and restart operations on the protocol plugin through the instruction channel.

[0010] The further technical solution is as follows: the operating state includes initialization state, normal operation state, stopped state and fault state; Within a specified startup time after the protocol plugin is started, the protocol plugin is checked multiple times to determine its running status. If no valid data is collected, the protocol plugin is determined to have failed to start and its running status is marked as faulty. When the protocol plugin is in normal operation, if the protocol plugin fails to return valid collection results within a preset time period multiple times in a row, the running status of the protocol plugin will be changed from normal operation to fault status to trigger fault recovery of the protocol plugin.

[0011] The further technical solution is as follows: determining the operating status of the protocol plugin based on whether it returns valid collection results within a preset time period includes: When the protocol plugin does not respond to the acquisition request, it is determined that the protocol plugin has stopped running; When the protocol plugin responds to the collection request, but the response does not contain valid collection data, it is determined that the protocol plugin is running but cannot return valid collection data. When the response contains valid collected data, but the data channel does not receive the data reported by the protocol plugin, the data channel is determined to be abnormal. The running status and fault type of the protocol plugin are determined based on the judgment result.

[0012] The further technical solution is as follows: the fault recovery also includes: clearing the communication resources occupied by the protocol plugin, and re-establishing the command channel and the data channel; After reloading and restarting the protocol plugin, the method further includes: checking the running status of the protocol plugin again; if the protocol plugin returns valid collection results within a preset time, the running status of the protocol plugin is restored to normal operation; otherwise, the running status of the protocol plugin is kept in fault state. After stopping the fault recovery of the protocol plugin, the protocol plugin is kept in a fault state and the fault information is reported to the upper layer system to await maintenance processing.

[0013] The further technical solution is as follows: the protocol manager creates protocol plugin instances according to the components or managed devices connected to the IoT gateway. Each protocol plugin instance is only responsible for one corresponding component or managed device and uses an independent communication address, acquisition cycle and fault recovery parameters. When the IoT gateway is connected to multiple devices using the same communication protocol, an independent protocol plugin instance is created for each device, and the operation of each protocol plugin instance does not affect the others.

[0014] The further technical solution is as follows: the method further includes: The protocol plugin instances are maintained independently; The independent maintenance includes at least one of the following: When upgrading the target protocol plugin, stop and replace the target protocol plugin and then restart the corresponding protocol plugin instance, without stopping the operation of the IoT gateway and other protocol plugin instances; When the number of connected devices increases, create a corresponding number of protocol plugin instances according to the number of additional devices. Set the collection period, communication parameters, and retry count for the protocol plugin instances corresponding to different devices.

[0015] The further technical solution is as follows: the messages transmitted between the protocol plugin and the protocol manager adopt a unified message format, and each message includes at least a message number, message type, generation time and message content; the protocol manager parses, classifies and forwards the received messages according to the unified message format, and provides event processing interface, data acquisition processing interface and instruction result processing interface to the upper layer business; The event handling interface is used to handle device online, offline, alarm, and status change events. The data processing interface is used to process the device data collected by the protocol plugin; The instruction result processing interface is used to process control instructions issued by upper-layer services and their execution results.

[0016] The present invention also provides an IoT protocol plug-in independent operating system, including a protocol manager and at least one protocol plug-in; Each communication protocol is encapsulated as an independent protocol plugin. The protocol plugin provides a unified lifecycle interface in the form of a dynamic library. The lifecycle interface includes an initialization interface, a running interface, and an exit interface. The protocol manager includes: The loading module is used to load the protocol plugin and call the initialization interface to establish the resources and communication connections required for operation. It establishes an instruction channel and a data channel for each protocol plugin. The instruction channel and the data channel are independent of each other. The instruction channel transmits management instructions and their processing results in a request-response manner. The data channel transmits the data reported by the protocol plugin in a publish-subscribe manner. The running module is used to call the running interface to make the protocol plugin run continuously, issue management commands through the command channel and receive the corresponding command processing results, and receive the data reported by the protocol plugin through the data channel; The status check module is used to send a collection request to the protocol plugin through the instruction channel at a predetermined period, and determine the running status of the protocol plugin based on whether the protocol plugin returns a valid collection result within a preset time. The fault recovery module is used to perform fault recovery on the protocol plugin when the running state is a fault state: call the exit interface to stop the protocol plugin, and reload and start the protocol plugin; and stop the fault recovery of the protocol plugin when the number of restarts of the protocol plugin reaches a preset limit within a predetermined time.

[0017] The advantages of this invention compared to existing technologies are as follows: This invention encapsulates each communication protocol as an independent protocol plugin in the form of a dynamic library and unifies the initialization / running / exit lifecycle interface, enabling each protocol to run with independent process resources and be independent of each other, thus naturally achieving mutual isolation; the protocol manager is responsible for uniformly loading plugins, establishing resources and connections, and building a request-response command channel and a publish-subscribe data channel for each plugin. The two channels are independent of each other, ensuring that management commands and business data are transmitted separately and do not interfere with each other; the manager issues collection requests periodically and checks the plugin running status based on timeout and result validity. Once a fault is detected, the exit interface is called to uninstall the plugin and reload and start it. Recovery stops when the maximum number of restarts is reached, thereby achieving independent operation, fault isolation, and independent maintenance of each protocol plugin without consuming too much gateway resources.

[0018] The present invention will be further described below with reference to the accompanying drawings and specific embodiments. Attached Figure Description

[0019] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This is a schematic diagram illustrating an application scenario of an IoT protocol plug-in independent operation method provided by an embodiment of the present invention; Figure 2 A flowchart illustrating a method for independent operation of plug-in IoT protocols provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the standard lifecycle interface for the protocol plugin provided in an embodiment of the present invention; Figure 4 This is a schematic diagram of the dual-channel inter-process communication and independent communication path for each component provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of the protocol plug-in state machine transition provided in an embodiment of the present invention; Figure 6 This is a schematic diagram of the health check and frequency limiting restart timing provided in an embodiment of the present invention; Figure 7 This is a schematic diagram of the plugin loading and callback registration process provided in an embodiment of the present invention; Figure 8 This is a schematic diagram of the overall closed loop provided by the embodiment of the present invention, which connects with the three-layer configuration at the component level; Figure 9 A schematic block diagram of a computer device provided for an embodiment of the present invention. Detailed Implementation

[0021] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0022] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0023] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0024] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0025] Please see Figure 1 and Figure 2 , Figure 2 This is a flowchart illustrating a method for the independent operation of IoT protocol plug-ins, as provided in an embodiment of the present invention. The method encapsulates each communication protocol as an independent protocol plug-in, providing unified initialization, operation, and exit lifecycle interfaces in the form of a dynamic library. A protocol manager loads these plug-ins uniformly, assigning each plug-in a separate communication address and independently creating command and data channels. This allows each protocol plug-in to be loaded and run independently in a modular manner within a resource-constrained embedded gateway, without interfering with each other. The command channel transmits management commands such as start configuration, data acquisition, stop, restart, and status query using a request-response method. The data channel uses a publish-subscribe method, carrying only device events, acquired data, and status information, without management commands. The two channels are independent of each other; even if the data channel is blocked, the manager can still perform status queries, stop, and restart operations on the plug-in through the command channel, thereby achieving isolation between the control plane and the data plane. Simultaneously, the manager periodically sends acquisition requests, distinguishing between no response and non-response based on whether the plug-in returns valid acquisition results within a preset time. The system identifies and resolves various fault types, including no valid data and abnormal data channels. When a fault occurs, it cleans up resources, calls the exit interface to uninstall and reload the startup plugin, and rebuilds the dual channels. If the restart limit is reached, the fault status is maintained and reported to the upper layer for maintenance. Furthermore, the manager creates protocol plugin instances for each component or managed device connected to the gateway. Each instance has its own communication address, acquisition cycle, and fault recovery parameters. Multiple devices using the same protocol are also independently instantiated and do not affect each other. During upgrades, only the target plugin is stopped and replaced without interrupting the gateway and other plugins. When devices are added, instances are dynamically created as needed, and acquisition cycles, communication parameters, and retry counts can be set for each instance. Combined with a unified message format between the plugin and the manager, and the event handling, data acquisition processing, and command result processing interfaces provided to the upper layer, the system ultimately achieves independent operation, isolation, and independent maintenance of multiple communication protocols within the embedded gateway.

[0026] Please see Figure 1The method provided in this embodiment can be applied to embedded IoT gateways in scenarios such as smart kitchen appliances, smart weighing, industrial gateways, and agricultural IoT. These gateways need to simultaneously support multiple north-south communication protocols within the same device, such as Modbus, MQTT, ZMQ, proprietary protocols, OTA upgrade protocols, and LED control protocols. In this embodiment, an IoT gateway refers to an embedded computing device deployed on the device side to connect lower-level components or managed devices with upper-level business systems; north-south communication protocols refer to the collective communication protocols used by the IoT gateway in the direction of connecting to lower-level components or managed devices (i.e., southward) and in the direction of connecting to the cloud platform or upper-level business systems (i.e., northward); OTA upgrade refers to a mechanism for remotely upgrading device firmware or software via over-the-air download; upper-level business and upper-level system both refer to business programs running on the IoT gateway or cloud platform that consume data collected by protocol plugins and issue control commands to devices.

[0027] Figure 2 This is a flowchart illustrating a method for the independent operation of plug-in IoT protocols provided in an embodiment of the present invention. Figure 2 As shown, the method includes the following steps S110 to S130.

[0028] S110. Each communication protocol is encapsulated as an independent protocol plugin. The protocol plugin provides a unified lifecycle interface in the form of a dynamic library. The lifecycle interface includes an initialization interface, a running interface, and an exit interface.

[0029] In this embodiment, the communication protocol refers to the agreed-upon rules followed by the IoT gateway for data interaction with external devices or platforms, such as Modbus, MQTT, ZMQ, and vendor-defined proprietary protocols. A protocol plugin is a software module that encapsulates the complete protocol stack and its operational logic of a communication protocol, and can be independently loaded and unloaded. A dynamic library is a compiled output that exists independently as a file and can be dynamically loaded and called during program execution, such as a .so file in Linux. A lifecycle interface refers to a set of standardized function interfaces provided by the protocol plugin to manage the entire process of the protocol plugin from startup to exit.

[0030] Specifically, the initialization interface is used to establish the resources, parameters, and communication connections required for the protocol plugin to run; The runtime interface is used to perform the continuous work of the protocol plugin; The exit interface is used to release the resources occupied by the protocol plugin and stop the protocol plugin; The initialization interface, the running interface, and the exit interface have a unified interface form in the protocol plugins corresponding to different types of communication protocols.

[0031] like Figure 2 As shown, for example, the function prototypes of the three interfaces can be int microservice_init(), void microservice_run(), and void microservice_cleanup(), respectively.

[0032] The protocol manager opens dynamic library files through dynamic loading functions and obtains the function addresses of three interfaces according to fixed symbol names, thus eliminating the need to adapt loading logic separately for each communication protocol; the compilation artifacts of protocol plugins can be named according to the communication protocol name and stored in a unified plugin directory, and the protocol manager can find the protocol plugins that can be loaded by scanning the plugin directory.

[0033] Therefore, when a new communication protocol is needed, the corresponding protocol plugin can be created according to the unified lifecycle interface to be integrated into the existing protocol management process. There is no need to modify the core control program of the protocol manager, which reduces the difficulty of new protocol access, replacement and maintenance, and also reduces the workload of regression testing when adding a new protocol.

[0034] In an alternative implementation, the protocol plugin can also be provided as an independent executable module. The protocol manager loads and runs the independent executable module by creating a subprocess, which also enables the independent loading, running and stopping of the protocol plugin.

[0035] S120. The protocol manager loads the protocol plugin and calls the initialization interface to establish the resources and communication connections required for operation. It establishes an instruction channel and a data channel for each protocol plugin. The instruction channel and the data channel are independent of each other. The instruction channel transmits management instructions and their processing results in a request-response manner. The data channel transmits the data reported by the protocol plugin in a publish-subscribe manner.

[0036] In this embodiment, the protocol manager refers to a unified management program running on the IoT gateway, responsible for loading, monitoring, and fault recovery of various protocol plugins. The command channel is an inter-process communication channel between the protocol manager and the protocol plugins used to transmit management commands and their processing results; it belongs to the control plane channel. The data channel is an inter-process communication channel between the protocol manager and the protocol plugins used to transmit data reported by the protocol plugins; it belongs to the data plane channel. The request-response method is a one-to-one communication method where one party sends a request and the other party returns a response upon receiving the request. The publish-subscribe method is a communication method where the data producer publishes a message and the party that has subscribed to the corresponding message receives the message. Management commands are instructions issued by the protocol manager to the protocol plugins to control the behavior of the protocol plugins or to query the status of the protocol plugins.

[0037] Specifically, the protocol manager assigns a communication address to each protocol plugin individually, and establishes the instruction channel and the data channel corresponding to the protocol plugin based on the assigned communication address; The management commands include start configuration commands, device acquisition commands, stop commands, restart commands, and running status query commands; if the protocol manager does not receive the corresponding command processing result within the specified waiting time after issuing the management command through the command channel, it determines that the command communication is abnormal. The data channel is also used to transmit device events actively generated by the protocol plugin, periodically collected data, and status change information. The data channel does not carry the management instructions, so that when the data channel is blocked, the protocol manager can still perform running status query, stop, and restart operations on the protocol plugin through the instruction channel.

[0038] For example, both command and data channels can be implemented based on the ZMQ message library: the command channel uses ZMQ request-response socket pairs, and the data channel uses ZMQ publish-subscribe socket pairs; the communication addresses can use local inter-process communication paths starting with ipc: / / , and be named according to the identifiers of the protocol plugins, such as... Figure 4 As shown, the communication paths of different protocol plugins are independent of each other.

[0039] like Figure 7 As shown, the process of the protocol manager loading a protocol plugin may include: allocating communication addresses for the instruction channel and data channel to the protocol plugin; registering event callbacks, data acquisition callbacks, and instruction result callbacks; loading the dynamic library and obtaining the lifecycle interface; calling the initialization interface, and if the initialization fails, stopping the protocol plugin and reporting it; otherwise, starting an independent running unit to execute the running interface, and then entering the running status check cycle.

[0040] Therefore, the control plane and the data plane use independent communication channels. Even if the amount of data reported by the protocol plugin is too large, the data transmission speed is slowed down, or the data channel is blocked, the protocol manager can still perform status checks, stop and restart operations through the command channel. This avoids the problem of protocol plugins being unmanageable due to abnormal data transmission and improves the reliability of protocol plugin fault handling.

[0041] In alternative implementations, the instruction channel and the data channel can also be implemented based on other inter-process communication mechanisms such as message queues, shared memory, or UNIX domain sockets. This embodiment does not limit the specific implementation method of inter-process communication, as long as the two channels are independent of each other.

[0042] In alternative implementations, the specified waiting time can be set according to the response characteristics of different communication protocols. For example, a longer waiting time can be set for serial port protocols with slower response, and a shorter waiting time can be set for Ethernet protocols with faster response.

[0043] S130. Call the running interface to make the protocol plugin run continuously, issue management instructions through the instruction channel and receive the corresponding instruction processing results, and receive the data reported by the protocol plugin through the data channel.

[0044] In this embodiment, the instruction processing result refers to the execution status feedback returned to the protocol manager after the protocol plugin executes the received management instruction, such as execution success, execution failure, and the corresponding failure reason.

[0045] The protocol plugins continue to work in a separate thread or process, so that a deadlock or crash of a single protocol plugin will not spread to the protocol manager and other protocol plugins in the process.

[0046] S140. Send a collection request to the protocol plugin through the instruction channel according to a predetermined cycle, and determine the running status of the protocol plugin based on whether the protocol plugin returns a valid collection result within a preset time.

[0047] In this embodiment, a data acquisition request refers to a request periodically sent by the protocol manager to the protocol plugin, requesting the plugin to acquire and return data from the devices it is responsible for. This acquisition request directly reuses the existing default acquisition function of the protocol plugin. A valid acquisition result refers to the complete acquisition data returned by the protocol plugin in response to the acquisition request, conforming to the agreed format. The running status refers to the status information maintained by the protocol manager for each protocol plugin, used to characterize the current working status of the protocol plugin.

[0048] The operating states include initialization state, normal operation state, stopped state, and fault state. The transition relationships between these states are as follows: Figure 5 As shown.

[0049] Within a specified startup time after the protocol plugin is started, the protocol plugin is checked multiple times to determine its running status. If no valid data is collected, the protocol plugin is determined to have failed to start and its running status is marked as faulty. When the protocol plugin is in normal operation, if the protocol plugin fails to return valid collection results within a preset time period multiple times in a row, the running status of the protocol plugin will be changed from normal operation to fault status to trigger fault recovery of the protocol plugin.

[0050] For example, the protocol manager can maintain a continuous failure counter for each protocol plugin: the counter is cleared to zero each time a valid acquisition result is received, and the counter is incremented by one each time a valid acquisition result is not received for a preset time. When the counter reaches the preset failure count threshold, it is determined that a valid acquisition result has not been returned for multiple consecutive times.

[0051] In one embodiment, determining the operating status of the protocol plugin based on whether the protocol plugin returns valid collection results within a preset time period includes: When the protocol plugin does not respond to the acquisition request, it is determined that the protocol plugin has stopped running; When the protocol plugin responds to the collection request, but the response does not contain valid collection data, it is determined that the protocol plugin is running but cannot return valid collection data. When the response contains valid collected data, but the data channel does not receive the data reported by the protocol plugin, the data channel is determined to be abnormal. The running status and fault type of the protocol plugin are determined based on the judgment result.

[0052] Therefore, this embodiment directly utilizes the existing default acquisition function of the protocol plugin to check the running status, without requiring the development of additional dedicated detection instructions for each communication protocol, thus reducing the workload of repeatedly developing detection functions; at the same time, by analyzing the acquisition results and response status, different fault conditions can be distinguished, improving the accuracy of fault diagnosis and facilitating the implementation of targeted recovery measures.

[0053] In alternative implementations, the protocol plugin may also proactively send heartbeat messages to the protocol manager at predetermined intervals, and the protocol manager may determine the operating status of the protocol plugin based on the arrival of the heartbeat messages; or the operating status may be checked by combining collection requests with heartbeat messages.

[0054] S150. When the running state is a fault state, perform fault recovery on the protocol plugin, wherein the exit interface is called to stop the protocol plugin, and the protocol plugin is reloaded and started; when the number of restarts of the protocol plugin reaches a preset upper limit within a predetermined time, the fault recovery of the protocol plugin is stopped.

[0055] In this embodiment, fault recovery refers to a series of processing operations automatically performed by the protocol manager to restore the normal operation of a protocol plugin that is in a faulty state.

[0056] The fault recovery also includes: clearing the communication resources occupied by the protocol plugin and re-establishing the command channel and the data channel; After reloading and restarting the protocol plugin, the method further includes: checking the running status of the protocol plugin again; if the protocol plugin returns valid collection results within a preset time, the running status of the protocol plugin is restored to normal operation; otherwise, the running status of the protocol plugin is kept in fault state. After stopping the fault recovery of the protocol plugin, the protocol plugin is kept in a fault state, and fault information is reported to the upper-layer system to await maintenance processing. The complete timing sequence of the above health check and frequency limiting restart is as follows: Figure 6 As shown.

[0057] For example, the number of restarts can be counted using a sliding time window: the protocol manager records the timestamp of each restart operation and counts the number of restarts within the nearest predetermined time period from the current time; the preset upper limit can be set to 3 to 5 times, and the predetermined time can be set to 10 minutes, and the specific values ​​can be configured according to the gateway's computing power and service reliability requirements.

[0058] Therefore, the continuous operation capability of the protocol plugin is improved through automatic inspection and automatic recovery mechanisms; at the same time, frequency-limited restarts avoid the waste of system resources caused by repeated restarts of the protocol plugin, and maintain the fault state and report fault information after reaching the restart limit, so that maintenance personnel can promptly discover and handle faults that cannot be automatically recovered.

[0059] In an alternative implementation, when the number of restarts reaches a preset limit, the time interval between two adjacent restarts can be extended in an exponential backoff manner before continuing to attempt recovery, rather than directly stopping fault recovery, so as to take into account the self-healing capability in temporary fault scenarios.

[0060] In one embodiment, the protocol manager creates protocol plugin instances according to the components or managed devices connected to the IoT gateway. Each protocol plugin instance is responsible for only one corresponding component or managed device and uses an independent communication address, acquisition cycle, and fault recovery parameters. When the IoT gateway is connected to multiple devices using the same communication protocol, an independent protocol plugin instance is created for each device, and the operation of each protocol plugin instance does not affect the others.

[0061] In this embodiment, a protocol plugin instance refers to an independently running protocol plugin instance created by the protocol manager for a specific component or managed device based on the protocol plugin.

[0062] Therefore, when one of the protocol plugin instances crashes, deadlocks, or experiences a communication anomaly, it only affects the corresponding component or device, without causing other devices' corresponding protocol plugins to stop working or affecting other types of protocol plugins, thus achieving fault isolation at the protocol level and even the device level.

[0063] In an alternative implementation, when the data volume of multiple devices using the same communication protocol is small, a single protocol plugin instance can manage these multiple devices uniformly, thereby saving system resources of the IoT gateway.

[0064] In one embodiment, the method further includes: The protocol plugin instances are maintained independently; The independent maintenance includes at least one of the following: When upgrading the target protocol plugin, stop and replace the target protocol plugin and then restart the corresponding protocol plugin instance, without stopping the operation of the IoT gateway and other protocol plugin instances; When the number of connected devices increases, create a corresponding number of protocol plugin instances according to the number of additional devices. Set the collection period, communication parameters, and retry count for the protocol plugin instances corresponding to different devices.

[0065] Therefore, protocol plugins can be upgraded, stopped, and restarted independently without requiring a system reboot; as the number of connected devices increases, protocol plugin instances can be flexibly expanded according to the number of devices; different protocol plugins for different devices can also be configured with different collection cycles, communication parameters, and retry counts, achieving independent upgrades, independent expansion, and independent configuration.

[0066] In this embodiment, the component-level three-layer configuration refers to the hierarchical configuration information organized by component, which includes a model layer for describing the product model to which the component belongs, a sub-device layer for describing the component access identifier, and a communication layer for describing the acquisition parameters and command parameters.

[0067] like Figure 8 As shown, the above protocol plugin instance can be integrated with the component-level three-layer configuration: the instructions issued by the upper-layer business are routed to the corresponding protocol plugin instance through the component-level configuration, and the data collected and the events generated by the protocol plugin instance are then sent back to the upper-layer business through a unified message channel, forming a complete closed loop from device access, data collection to business processing.

[0068] In one embodiment, the messages transmitted between the protocol plugin and the protocol manager adopt a unified message format, and each message includes at least a message number, message type, generation time, and message content; the protocol manager parses, classifies, and forwards the received messages according to the unified message format, and provides event processing interfaces, data acquisition processing interfaces, and instruction result processing interfaces to upper-layer services; The event handling interface is used to handle device online, offline, alarm, and status change events. The data processing interface is used to process the device data collected by the protocol plugin; The instruction result processing interface is used to process control instructions issued by upper-layer services and their execution results.

[0069] In this embodiment, the unified message format refers to the message organization form with the same structure that is followed by all types of protocol plugins and the protocol manager. The message content is used to distinguish different types of information such as device acquisition data, control commands, command processing results, and device events. The event processing interface, acquisition data processing interface, and command result processing interface refer to the standardized interfaces provided by the protocol manager to the upper-layer business for callback processing of corresponding types of information.

[0070] For example, the message can be serialized in JSON format, the message number is used for message deduplication and matching between requests and responses, the message type is used to identify the type of information carried by the message content, and the generation time is used for message chronological sorting and timeout removal.

[0071] Therefore, regardless of whether the underlying protocol plugin is responsible for Modbus, MQTT or other communication protocols, the upper-layer business can receive data, process events and obtain command results in the same way. There is no need to know which communication protocol the underlying protocol plugin uses, nor is it necessary to write different message processing flows separately. This reduces the coupling between the upper-layer business and the specific communication protocol, and makes it easier to add new communication protocols in the future.

[0072] In alternative implementations, the message may also be in a binary serialization format such as Protocol Buffers or MessagePack to further reduce message transmission overhead.

[0073] The above method encapsulates each communication protocol as an independent protocol plugin in the form of a dynamic library and unifies the initialization / run / exit lifecycle interface, enabling each protocol to run with independent process resources and be independent of each other, thus naturally achieving mutual isolation. The protocol manager is responsible for uniformly loading plugins, establishing resources and connections, and building a request-response command channel and a publish-subscribe data channel for each plugin. The two channels are independent of each other, ensuring that management commands and business data are transmitted separately and do not interfere with each other. The manager issues collection requests periodically and checks the plugin running status based on timeout and result validity. Once a fault is detected, the exit interface is called to uninstall the plugin and reload and start it. Recovery stops when the maximum number of restarts is reached, thereby achieving independent operation, fault isolation, and independent maintenance of each protocol plugin without consuming too much gateway resources.

[0074] This invention also provides an IoT protocol plug-in independent operating system. The system includes a protocol manager and at least one protocol plug-in. Each protocol plug-in encapsulates a communication protocol as a dynamic library, providing a unified lifecycle interface, including an initialization interface, a running interface, and an exit interface. The protocol manager includes a loading module, a running module, a status checking module, and a fault recovery module. The loading module loads the protocol plug-in and calls the initialization interface to establish running resources and communication connections, establishing independent command and data channels for each protocol plug-in. The running module calls the running interface to keep the protocol plug-in running continuously, issuing management commands and receiving corresponding command processing results through the command channel, and receiving data reported by the protocol plug-in through the data channel. The status checking module sends collection requests to the protocol plug-in via the command channel at predetermined intervals, determining the running status of the protocol plug-in based on whether it returns valid collection results within a preset time. The fault recovery module performs fault recovery on the protocol plug-in when its running status is faulty, and stops fault recovery when the number of restarts of the protocol plug-in reaches a preset limit within a predetermined time. The specific working process of each of the above modules corresponds one-to-one with steps S110 to S150 in the aforementioned method embodiment, and will not be repeated here.

[0075] The system is deployed on an IoT gateway running an embedded Linux system. The protocol manager and various protocol plugins run within the same IoT gateway, without relying on a container orchestration system, making it suitable for resource-constrained embedded environments.

[0076] In summary, this invention enables multiple communication protocols to run separately, isolate themselves, and be independently maintained in resource-constrained embedded IoT gateways by establishing a unified protocol plugin runtime interface, setting independent command and data channels for each protocol plugin, using service acquisition requests for runtime status checks and automatic recovery, running protocol plugin instances separately according to components or managed devices, and adopting a unified message format and result processing method. This allows for: adding new communication protocols without modifying the core control program of the protocol manager, reducing the difficulty of protocol access; a failure in one protocol plugin will not directly affect other protocol plugins or the entire gateway system; protocol plugins can be upgraded, stopped, and restarted individually without requiring a system restart; protocol plugin instances can be created separately according to the number of components or devices, facilitating expansion; automatic checking and automatic recovery mechanisms improve the continuous operation capability of protocol plugins; a unified message format and processing interface reduce the coupling between upper-layer services and specific communication protocols; and the ability to perform stop, restart, and fault handling operations even in the event of data transmission anomalies improves system maintainability.

[0077] It should be noted that those skilled in the art can clearly understand that the specific implementation process of the above-mentioned IoT protocol plug-in independent operating system and each unit can be referred to the corresponding description in the foregoing method embodiments. For the sake of convenience and brevity, it will not be repeated here.

[0078] The aforementioned plug-in stand-alone IoT protocol system can be implemented as a computer program, which can be used in, for example... Figure 9 It runs on the computer device shown.

[0079] Please see Figure 9 , Figure 9 This is a schematic block diagram of a computer device provided in an embodiment of this application. The computer device 500 can be a terminal, wherein the terminal can be an electronic device with communication functions such as a smartphone, tablet computer, laptop computer, desktop computer, personal digital assistant, and wearable device.

[0080] See Figure 9 The computer device 500 includes a processor 502, a memory, and a network interface 505 connected via a system bus 501. The memory may include a non-volatile storage medium 503 and internal memory 504.

[0081] The non-volatile storage medium 503 may store an operating system 5031 and a computer program 5032. The computer program 5032 includes program instructions that, when executed, cause the processor 502 to perform a plug-in, stand-alone method for operating an Internet of Things (IoT) protocol.

[0082] The processor 502 provides computing and control capabilities to support the operation of the entire computer device 500.

[0083] The internal memory 504 provides an environment for the operation of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute an IoT protocol plug-in independent operation method.

[0084] This network interface 505 is used for network communication with other devices. Those skilled in the art will understand that... Figure 9 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device 500 to which the present application is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0085] The processor 502 is used to run the computer program 5032 stored in the memory to implement all the steps of the IoT protocol plug-in independent operation method.

[0086] It should be understood that in the embodiments of this application, the processor 502 may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.

[0087] It will be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program includes program instructions and can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.

[0088] Therefore, the present invention also provides a storage medium. This storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein when executed by a processor, the computer program causes the processor to perform all steps of the described IoT protocol plug-in independent operation method.

[0089] The storage medium can be any computer-readable storage medium capable of storing program code, such as a USB flash drive, portable hard drive, read-only memory (ROM), magnetic disk, or optical disk.

[0090] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0091] In the embodiments provided by this invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For example, the division of each unit is only a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.

[0092] The steps in the method of this invention can be adjusted, merged, or reduced in order according to actual needs. The units in the system of this invention can be merged, divided, or reduced according to actual needs. Furthermore, the functional units in the various embodiments of this 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.

[0093] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or 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, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.

[0094] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for modularizing and independently operating Internet of Things (IoT) protocols, characterized in that, include: Each communication protocol is encapsulated as an independent protocol plugin, and the protocol plugin provides a unified lifecycle interface in the form of a dynamic library. The lifecycle interface includes an initialization interface, a running interface, and an exit interface. The protocol manager loads the protocol plugin and calls the initialization interface to establish the resources and communication connections required for operation. It establishes an instruction channel and a data channel for each protocol plugin. The instruction channel and the data channel are independent of each other. The instruction channel transmits management instructions and their processing results in a request-response manner. The data channel transmits the data reported by the protocol plugin in a publish-subscribe manner. The protocol plugin is continuously run by calling the running interface, management commands are issued through the command channel and corresponding command processing results are received, and data reported by the protocol plugin is received through the data channel. According to a predetermined cycle, a collection request is sent to the protocol plugin through the instruction channel. The running status of the protocol plugin is determined based on whether the protocol plugin returns a valid collection result within a preset time. When the running state is a fault state, fault recovery is performed on the protocol plugin, wherein the exit interface is called to stop the protocol plugin, and the protocol plugin is reloaded and started; when the number of restarts of the protocol plugin reaches a preset limit within a predetermined time, fault recovery of the protocol plugin is stopped.

2. The method for independent operation of IoT protocol plug-ins according to claim 1, characterized in that, The initialization interface is used to establish the resources, parameters, and communication connections required for the protocol plugin to run. The runtime interface is used to perform the continuous work of the protocol plugin; The exit interface is used to release the resources occupied by the protocol plugin and stop the protocol plugin; The initialization interface, the running interface, and the exit interface have a unified interface form in the protocol plugins corresponding to different types of communication protocols.

3. The method for independent operation of IoT protocol plug-ins according to claim 1, characterized in that, The protocol manager assigns a communication address to each protocol plugin individually, and establishes the instruction channel and the data channel corresponding to the protocol plugin based on the assigned communication address; The management commands include start configuration commands, device acquisition commands, stop commands, restart commands, and running status query commands; if the protocol manager does not receive the corresponding command processing result within the specified waiting time after issuing the management command through the command channel, it determines that the command communication is abnormal. The data channel is also used to transmit device events actively generated by the protocol plugin, periodically collected data, and status change information. The data channel does not carry the management instructions, so that when the data channel is blocked, the protocol manager can still perform running status query, stop, and restart operations on the protocol plugin through the instruction channel.

4. The method for independent operation of IoT protocol plug-ins according to claim 1, characterized in that, The operating states include initialization state, normal operation state, stopped state, and fault state; Within a specified startup time after the protocol plugin is started, the protocol plugin is checked multiple times to determine its running status. If no valid data is collected, the protocol plugin is determined to have failed to start and its running status is marked as faulty. When the protocol plugin is in normal operation, if the protocol plugin fails to return valid collection results within a preset time period multiple times in a row, the running status of the protocol plugin will be changed from normal operation to fault status to trigger fault recovery of the protocol plugin.

5. The method for independent operation of a plug-in IoT protocol according to claim 4, characterized in that, The step of determining the operating status of the protocol plugin based on whether the protocol plugin returns valid collection results within a preset time period includes: When the protocol plugin does not respond to the acquisition request, it is determined that the protocol plugin has stopped running; When the protocol plugin responds to the collection request, but the response does not contain valid collection data, it is determined that the protocol plugin is running but cannot return valid collection data. When the response contains valid collected data, but the data channel does not receive the data reported by the protocol plugin, the data channel is determined to be abnormal. The running status and fault type of the protocol plugin are determined based on the judgment result.

6. The method for independent operation of IoT protocol plug-ins according to claim 1, characterized in that, The fault recovery also includes: clearing the communication resources occupied by the protocol plugin and re-establishing the command channel and the data channel; After reloading and restarting the protocol plugin, the method further includes: checking the running status of the protocol plugin again; if the protocol plugin returns valid collection results within a preset time, the running status of the protocol plugin is restored to normal operation; otherwise, the running status of the protocol plugin is kept in fault state. After stopping the fault recovery of the protocol plugin, the protocol plugin is kept in a fault state and the fault information is reported to the upper layer system to await maintenance processing.

7. The method for independent operation of IoT protocol plug-in according to claim 1, characterized in that, The protocol manager creates protocol plugin instances according to the components or managed devices connected to the IoT gateway. Each protocol plugin instance is only responsible for one corresponding component or managed device and uses an independent communication address, acquisition cycle and fault recovery parameters. When the IoT gateway is connected to multiple devices using the same communication protocol, an independent protocol plugin instance is created for each device, and the operation of each protocol plugin instance does not affect the others.

8. The method for independent operation of a plug-in IoT protocol according to claim 7, characterized in that, The method further includes: The protocol plugin instances are maintained independently; The independent maintenance includes at least one of the following: When upgrading the target protocol plugin, stop and replace the target protocol plugin and then restart the corresponding protocol plugin instance, without stopping the operation of the IoT gateway and other protocol plugin instances; When the number of connected devices increases, create a corresponding number of protocol plugin instances based on the number of additional devices. Set the collection period, communication parameters, and retry count for the protocol plugin instances corresponding to different devices.

9. The method for independent operation of IoT protocol plug-in according to claim 1, characterized in that, The messages transmitted between the protocol plugin and the protocol manager adopt a unified message format. Each message includes at least a message number, message type, generation time, and message content. The protocol manager parses, classifies, and forwards the received messages according to the unified message format, and provides event processing interfaces, data acquisition processing interfaces, and instruction result processing interfaces to upper-layer services. The event handling interface is used to handle device online, offline, alarm, and status change events. The data processing interface is used to process the device data collected by the protocol plugin; The instruction result processing interface is used to process control instructions issued by upper-layer services and their execution results.

10. A modular, independently operating system for Internet of Things (IoT) protocols, characterized in that: Includes a protocol manager and at least one protocol plugin; Each communication protocol is encapsulated as an independent protocol plugin. The protocol plugin provides a unified lifecycle interface in the form of a dynamic library. The lifecycle interface includes an initialization interface, a running interface, and an exit interface. The protocol manager includes: The loading module is used to load the protocol plugin and call the initialization interface to establish the resources and communication connections required for operation. It establishes an instruction channel and a data channel for each protocol plugin. The instruction channel and the data channel are independent of each other. The instruction channel transmits management instructions and their processing results in a request-response manner. The data channel transmits the data reported by the protocol plugin in a publish-subscribe manner. The running module is used to call the running interface to make the protocol plugin run continuously, issue management commands through the command channel and receive the corresponding command processing results, and receive the data reported by the protocol plugin through the data channel; The status check module is used to send a collection request to the protocol plugin through the instruction channel at a predetermined period, and determine the running status of the protocol plugin based on whether the protocol plugin returns a valid collection result within a preset time. The fault recovery module is used to perform fault recovery on the protocol plugin when the running state is a fault state: call the exit interface to stop the protocol plugin, and reload and start the protocol plugin; and stop the fault recovery of the protocol plugin when the number of restarts of the protocol plugin reaches a preset limit within a predetermined time.