Condition-triggered multistage matching rule engine for Internet of Things system
By triggering a multi-level matching rule engine based on conditions, the problem of small size and low correlation of rules in the IoT system is solved, efficient rule processing and development efficiency are improved, hardware processing capacity requirements are reduced, and the popularity of the IoT system is promoted. .
Patent Information
- Application Number
- CN202410638437.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-09-06
AI Technical Summary
Due to the small size and low relevance of rules in IoT systems, existing large-scale rule engines are difficult to efficiently process on gateway devices, and there is a lack of simple and efficient lightweight rule engine solutions.
A condition-triggered multi-level matching rule engine is designed, which works in a trigger-matching manner. It includes a rule data description module, a multi-level rule matching module and a function execution interface module. It uses a 5-tuple description method and a multi-level matching mechanism to adapt to complex Algorithms and application scenarios to reduce the complexity of rule matching.
It greatly reduces the workload of functional development and maintenance, reduces communication and design costs during the development process, improves the reliability of business development, reduces the requirements for hardware processing capabilities, and promotes the popularization and promotion of IoT systems.
Smart Images

Figure CN118612274A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of Internet of Things and M2M, and in particular relates to a condition-triggered multi-level matching rule engine for an Internet of Things system. Background Art
[0002] In the IoT environment, many applications implement closed-loop control operations, which require output operations to be determined based on various input states. These operations have many common parts, such as the sending and receiving of sensor / execution data, network transmission, and routing selection. On the application side, these data need to be used and controlled according to certain strategies. If these strategies can be described through data, the flexibility of the IoT system can be improved, the application of the IoT can be facilitated, the development of application programs can be simplified, and the popularization of the IoT can be promoted. Introducing and using the rule engine method in IoT application services is an effective measure to describe strategies with data.
[0003] Since the scale of IoT application rules is generally small and the correlation is low, and the processing power of IoT gateway devices is relatively weak, there is no need and no way to use a large-scale rule engine like Drool. Instead, a lightweight rule engine with more concise expression and more efficient processing is needed. Summary of the invention
[0004] The present invention proposes an efficient and convenient condition-triggered multi-level matching rule engine for the Internet of Things system, which is suitable for the use of rules in the Internet of Things and related application devices. Different from the static matching method of general rule engines, this rule engine works in a trigger-matching mode, which includes a two-level matching mechanism: the first level is the trigger matching, which determines whether to continue to start the second-level rule matching according to the triggering conditions; the second level is the core matching, which obtains the output (products) based on the comprehensive judgment of the status of various variables. The rule engine can be run in a service mode, that is, one instance serves multiple applications; it can also be implemented in an embedded mode as a module of an application to implement rule operations. In terms of matching algorithms, due to the small scale and weak correlation, no complex algorithm is used, but matching is performed directly. However, the expression of rule data definition can meet the needs of various complex algorithms (such as Rete).
[0005] A condition-triggered multi-level matching rule engine for an Internet of Things system comprises a rule data description module, a multi-level rule matching module, and a function execution interface module.
[0006] The rule definition module implements the graphical input, saving and dynamic loading of rule data; the multi-level matching module uses the sensor node input information and rule definition data to realize trigger condition matching and control operation matching; the function execution interface module uses the matching results to send direct state modification instruction data to the controlled node or call the function processing function to realize related processing functions.
[0007] Furthermore, in the rule data description module, the overall structure of the rule data adopts a 5-tuple description method of (variable, trigger, rule, output, function processing).
[0008] Among them, variables are used to input and store intermediate results; triggering rules and outputs are internal factors of the engine, which adopt a single variable triggering method and combine intermediate variable temporary storage to support the simultaneous triggering of multiple variables; output operations include directly changing variables and calling functions. Variables refer to variables inside or buffered by the rule engine, as well as directly changing the value or function of the data endpoint in the target device.
[0009] The expression of rules is adaptable to different algorithms, as well as different application fields and scenarios, and provides an interface for generating rules for visualization methods.
[0010] Furthermore, the variable description method in the 5-tuple adopts a 2-tuple method of (device identifier, endpoint identifier) to uniformly describe variables and intermediate variables, and ordinary variables that are not intermediate variables are consistent with the address identifier used in the Internet of Things.
[0011] Furthermore, in the multi-level rule matching module, a multi-level matching mechanism is used to reduce the complexity of rule matching. The first level determines whether to trigger the rule engine to perform a rule matching operation, and the second level and subsequent levels are the matching of the main rules.
[0012] Furthermore, in the multi-level rule matching module, the execution generated by the match directly controls the state of the data node and is saved in the system as an intermediate variable to serve as the judgment condition for subsequent matching operations, thereby being competent for the execution of complex business operation logic or functions.
[0013] Furthermore, for complex business execution logic, mechanisms such as function calls, restful, and message processing are used to drive execution based on matching operation results.
[0014] Furthermore, a cyclic trigger mechanism is adopted, that is, each trigger only receives and processes a single trigger event. If necessary, the status is recorded in a 2-tuple form of (device ID, endpoint ID). When other related events occur later, this related intermediate status is combined to comprehensively determine whether the rule matching requirements are met.
[0015] Furthermore, a subscription mechanism is used to select system sensor data, custom data, and data from other sources that are useful for the current business scenario from the massive data nodes that can receive information as triggering or matching conditions for the rule engine.
[0016] Compared with the prior art, the present invention provides an IoT system rule engine application having the following beneficial effects:
[0017] (1) Greatly reduces the workload of related function development and maintenance. With the continuous accumulation of development results, various input and output meta-operations are recorded as basic items in the rule configuration file. As a result, most of the new requirements can be realized directly by filtering the relevant items from the original configuration file for reasonable combination. If necessary, a small number of items may be added to form a new input and output processing effect, which can be quickly put into use. Moreover, such configuration work will become more and more convenient in future development work as data accumulates.
[0018] (2) Reduced communication and design costs during the development process. With a simple and unified rule data description method, there is a relatively standardized and effective routine method for future business description and implementation. That is, the business logic can always be described from the aspects of trigger conditions, matching conditions, output operations, etc. This will inevitably greatly reduce aimless communication and ineffective design, thereby improving the development efficiency of the system.
[0019] (3) Improved reliability of business development. As mentioned above, with the continuous accumulation of development results, the possibility of generating new configuration file entries when developing new requirements will become smaller and smaller, which will lead to higher stability in the operation of the rule engine. The reason is that the various meta-operations in it have been repeatedly verified by the system, and their reliability is obviously lower than that of newly developed functions.
[0020] (4) The processing power requirements of the hardware device where the rule engine program resides are greatly reduced. This type of equipment is needed in large quantities, and reducing the cost of each one will greatly reduce investment and facilitate the promotion of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 The members and structure of the rule engine class RuleEngine in the specific implementation of the present invention, which describes the main members of the rule engine object. This class is the core class of the rule engine implementation module. The members include variable lists, rule lists, triggers, etc.
[0022] Figure 2 It is a static class in the rule engine in the specific implementation mode of the present invention, which describes the static data structure required to be used in the rule processing process, including variables, rules, conditions, trigger conditions, rule conditions, etc.
[0023] Figure 3 The rule processing flow in the specific implementation mode of the present invention describes the standard process of rule processing according to the rule engine of the present invention. DETAILED DESCRIPTION
[0024] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings.
[0025] A condition-triggered multi-level matching rule engine for IoT systems. The core is the expression of rule data. The specific description is as follows:
[0026] (1) The main elements are variables (input and storage), triggers, rules, outputs, and functions. Triggers, rules, and outputs are internal factors of the engine; variables are the input / output of the engine, and output operations include changing variables and calling functions;
[0027] (2) In order to enable continuous storage, JSON is used as the basic expression method;
[0028] (3) It uses a single variable triggering method, and can also handle multiple variables being triggered simultaneously. That is, when a variable is triggered, the intermediate variable generated by the previous trigger can be used as a condition, thereby achieving multi-variable triggering and generating the expected output;
[0029] (4) There are two types of variable changes: directly changing the state of the data endpoint in the target device or changing the value of the variable inside the rule engine or in the buffer;
[0030] (5) The expression method of rules can adapt to different application scenarios and algorithms, such as direct algorithm, Rete algorithm, etc.
[0031] (6) The data engine can be run as an embedded process (thread) or provided as a service to various applications;
[0032] (7) Different visualization methods can be used to generate rule definitions according to different scenarios and fields.
[0033] In the rule data description module, the core rule data definition includes the following steps:
[0034] (1) The variable part definition contains all the variables involved in the rule operation. The variable part is an array, each member describes a variable, and the variable description includes: device identification, endpoint identification, data direction, and default value. The endpoint identification is a list that can list multiple endpoints, and the data direction and default value are also lists that list the direction and default value of the corresponding endpoint;
[0035] (2) Trigger part definition, which is an array. Each item represents a trigger condition, represented by a key-value pair. The trigger starts from a variable update operation. The variable identifier is identified by the variable_id field, where the first item is device_id and the second item is endpoint_id. When the variable is updated, a trigger condition judgment is introduced. The main purpose is to reduce the complexity of subsequent condition judgments. This condition is described in trig_rule. product is one or more outputs. These outputs are intermediate outputs. The subsequent condition matching is executed. It is an array, which represents the array subscript index of the rule part;
[0036] (3) Rule definition, which is an array containing all the rules that need to be matched. When the trigger condition is met, one or more matching rules will be executed. Each matching rule contains a set of (one or more) matching conditions (match) and a set of (one or more) outputs (products). When there are multiple matching conditions, these matching conditions are in an "and" relationship;
[0037] (4) Output description. This is an array. There can be multiple data items. Each item is a subscript combination. The first item indicates the position of the output (array) in the array; the second item indicates the subscript of the value (value_set).
[0038] (5) Function processing module expression, using addr and name to represent the address and function name of the relevant processing module respectively.
[0039] (6) The JSON representation of the core structure described above is as follows:
[0040]
[0041]
[0042]
[0043] The following two specific embodiments are given.
[0044] Embodiment 1: Variable switch control.
[0045] This example is a relatively simple structure where input directly controls output, which does not involve intermediate buffering and complex condition matching processing, nor does it perform too many intelligent and complex relationship settings between input and output. It contains two IoT devices, a button device and a relay device, and the specific configuration is as follows:
[0046] 1) The device ID of the push button device is 1073741856, and the device ID of the relay device is 1073741847;
[0047] 2) The button device has four buttons, all of which are resettable buttons, that is, they can be reset by pressing and then lifting;
[0048] 3) The relay device has two relays, and the contacts are normally open (power off);
[0049] 4) The endpoints of the four buttons are marked as 32, 33, 34, and 35;
[0050] 5) The terminal labels of the two relays are: 32 and 33 respectively.
[0051] The designed control rules are as follows:
[0052] 1) Press button 32: the two relays flip (i.e. the one that was originally on becomes off, and the one that was originally off becomes on);
[0053] 2) Press button 33: Both relays turn off the power supply;
[0054] 3) Press button 34: both relays are powered on;
[0055] 4) Press button 35 and relay 32 flips.
[0056] Based on this, the following rule data is configured:
[0057] Table 1-1 Variables domain settings
[0058]
[0059] Table 1-2 Trigger rules (triggers) domain settings
[0060]
[0061]
[0062] Table 1-3 Rules domain settings
[0063]
[0064] Table 1-4 Output (products) domain settings
[0065]
[0066]
[0067] Embodiment 2: Intelligent temperature control.
[0068] This example is a more typical processing process in an intelligent scenario that better reflects the advantages of the present invention. It not only involves complex condition matching, but also requires the use of some intermediate cache processing to achieve multi-condition matching, and the output after rule matching is more diverse. It involves three IoT devices, including an air conditioner with a control interface, a temperature and humidity sensor, and a human body sensor. In addition, some date intermediate variables are set. The specific configuration is as follows:
[0069] 1) The equipment identifier of the air conditioner is 1000001001, and its 32, 33, 34, and 35 data nodes respectively represent the switch status (input), dehumidification (output), cooling (output), and heating (output) of the air conditioner;
[0070] 2) The device ID of the temperature and humidity sensor is 1000001002, and its 32 and 33 data nodes are input quantities, representing the temperature and humidity values of the environment respectively;
[0071] 3) The device ID of the human body sensor is 1000001003, and the value of its 32 data nodes indicates whether there is someone at home;
[0072] 4) The intermediate (cache) variable is identified by 103, and its three components 32, 33, and 34 represent the year, month, and day values of the date respectively.
[0073] The designed control rules are as follows:
[0074] 1) When the home changes from occupied to unoccupied, if the air conditioner is on, turn it off;
[0075] 2) There is someone at home, the month is June or July, the humidity is greater than 90, turn on the air conditioner and set it to "dehumidification" mode;
[0076] 3) There is someone at home, the month is from August to October, the temperature is above 32 degrees, turn on the air conditioner and set it to "cooling" mode, and the target temperature is set to 26 degrees;
[0077] 4) When someone is at home, the month is December to February, the temperature is below 10 degrees, turn on the air conditioner and set it to "heating" mode, and the target temperature is set to 22 degrees.
[0078] Table 2-1 Variables domain settings
[0079]
[0080] Table 2-2 Trigger rules (triggers) domain settings
[0081]
[0082]
[0083]
[0084] Table 2-3 Rules domain settings
[0085]
[0086] Table 2-4 Output (products) domain settings
[0087]
[0088]
[0089] The above description is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiment. Any equivalent modifications or changes made by ordinary technicians in this field based on the contents disclosed by the present invention should be included in the protection scope recorded in the claims.
Claims
1. A condition-triggered multi-level matching rule engine for an Internet of Things system, characterized by: The rule engine includes a rule data description module, a multi-level rule matching module, and a function execution interface module; The rule definition module implements the graphical input, saving and dynamic loading of rule data; the multi-level matching module uses the sensor node input information and rule definition data to realize trigger condition matching and control operation matching; the function execution interface module uses the matching results to send direct state modification instruction data to the controlled node or call the function processing function to realize related processing functions.
2. The condition-triggered multi-level matching rule engine for an Internet of Things system according to claim 1, characterized in that: In the rule data description module, the overall structure of rule data adopts the description method of 5-tuple (variable, trigger, rule, output, function processing); Among them, variables are used to input and store intermediate results; triggering rules and outputs are internal factors of the engine, using a single variable trigger method, combined with intermediate variable temporary storage, so as to support multiple variables triggering at the same time; output operations include directly changing variables and calling functions. Variables refer to variables inside or buffered by the rule engine, as well as directly changing the value of the data endpoint in the target device or function processing; The expression of rules is adaptable to different algorithms, as well as different application fields and scenarios, and provides an interface for generating rules for visualization methods.
3. The condition-triggered multi-level matching rule engine for an Internet of Things system according to claim 3, characterized in that: The variable description method in the 5-tuple adopts a 2-tuple method of (device identifier, endpoint identifier) to uniformly describe variables and intermediate variables, and ordinary variables that are not intermediate variables are consistent with the address identifier used in the Internet of Things.
4. The condition-triggered multi-level matching rule engine for an Internet of Things system according to claim 1, characterized in that: In the multi-level rule matching module, a multi-level matching mechanism is used to reduce the complexity of rule matching. The first level determines whether to trigger the rule engine to perform rule matching operations, and the second level and later levels are the matching of the main rules.
5. The condition-triggered multi-level matching rule engine for an Internet of Things system according to claim 1, characterized in that: In the multi-level rule matching module, the execution generated by the match directly controls the state of the data node and is saved in the system as an intermediate variable to serve as the judgment condition for subsequent matching operations, thereby being competent for the execution of complex business operation logic or functions.
6. The condition-triggered multi-level matching rule engine for an Internet of Things system according to claim 1, characterized in that: For complex business execution logic, function calls, restful, message processing and other mechanisms are adopted to drive execution based on matching operation results.
7. The condition-triggered multi-level matching rule engine for an Internet of Things system according to claim 1, characterized in that: A cyclic trigger mechanism is adopted, that is, each trigger only receives and processes a single trigger event. If necessary, the status is recorded in a 2-tuple form of (device ID, endpoint ID). When other related events occur later, this related intermediate status is combined to comprehensively determine whether the rule matching requirements are met.
8. The condition-triggered multi-level matching rule engine for an Internet of Things system according to claim 1, characterized in that: A subscription mechanism is used to select system-wide sensor data, custom data, and data from other sources that are useful for the current business scenario from the massive data nodes that can receive information as trigger or matching conditions for the rule engine.
