Basic configuration of rule chains

Version 3.1 by Hera Guo on 2024/10/31 14:54

Table of Contents:

1.About rule chains

The system provides a rule chain library for developers to configure message transformation, filtering, computation, and transmission on their own.

2.Rule chain creation

The system provides a default root rule chain that supports user use. No changes are made on the root rule chain, but the root rule chain is exported and re imported, and then modified and configured in the newly imported rule chain.

Firstly, follow the steps below to export the root rule chain. After clicking on export, the system will automatically download it, and the exported file will be in JSON format.

1730343544790-113.png

Re import the exported configuration into the system. After clicking on import, the system will directly jump to the configuration page of the newly imported rule chain. Simply click on the "Apply Change" button in the bottom right corner.

Re exit to the rule chain library menu to see the newly imported rule chain library configuration.

1730344152898-509.png4

1730344348542-260.png

3.Rule chain modification

Follow the steps below to modify the basic information of the rule chain. You can rename the rule chain imported in the previous section.

1730344632740-435.png

1730345137320-999.png

1730345353615-959.png

4.Rule chain deletion

You can delete a newly created rule chain by following the following steps.

note: the default root rule chain provided by the system cannot be deleted.

1730346321550-495.png

5.Rule chain configuration

If you need to configure the rule chain, you need to follow the following steps to enter the configuration page of the rule chain.

1730346571913-889.png

1730346890962-926.png

1730347084731-765.png

1730347231071-931.png

Next, we will explain the configuration of rule nodes that may be commonly used in different classes to manipulate data. As the default device configuration was applied in the creation of the previous device ,

the rule chain used in the default device configuration is the Root Rule Chain. Therefore, the following demonstrations are all configurations made in the Root Rule Chain.

6.About Nodes

6.1 filter

6.1.1 check fidles presence

This rule node is used to verify the existence of certain attributes in the message body or metadata, and distribute the message based on the verification results. The configuration content of this node includes:

  • Name: required field, indicating the name of the node;
  • Message field names: The name of the attribute to be verified in the message body, which is the content of the message actively sent by the device. Multiple attributes can be configured here, and after entering each attribute, press' Enter 'to enter;
  • Metadata field names: The attribute names that need to be validated in the message metadata. The metadata is the data attached to the system and generally includes three metadata attributes: DeviceType, DeviceName, and ts. Multiple attributes can be configured here, and after entering each attribute, press' Enter 'to enter;
  • Check that all specified fields are present: Select the box, and when performing the above attribute verification, connect each verification condition with "and"; When not selected, during the above attribute verification, each verification condition is connected by "or";
  • Explanation: Non mandatory field, additional explanation;

According to the judgment result, there are two types of exits for this rule node: true and false.

A simple usage example is as follows:

1730353965218-437.png

6.1.2 script

This rule node allows developers to implement data filtering through programming, that is, to distribute messages using custom filtering rules. The configuration content of this node includes:

  • Name: required field, indicating the name of the node;
  • Function Filter: Code (customizing filtering rules through code), the function parameters include msg (message), metadata (metadata), msgType (message type pushed by the previous node), and the return value should be a Boolean value;
  • Explanation: Non mandatory field, additional explanation;

According to the code logic, there are two types of exits for this rule node: true and false.

A simple usage example is as follows:

1730354366308-318.png

6.1.3 switch

This rule node allows developers to implement data grouping filtering through programming, that is, to distribute data using custom distribution rules. The configuration content of this node includes:

  • Name: required field, indicating the name of the node;
  • Function Switch: Code (customizing grouping rules through code), function parameters include msg (message), metadata (metadata), msgType (message type pushed by the previous node), return value should be a string array, indicating the path to be distributed;
  • Explanation: Non mandatory field, additional explanation;

According to the code logic, the exit of this rule node is defined by the coding personnel, as shown in the example.

A simple usage example is as follows

if (msg.temperature > 25) {
    return ['High temperature'];
} else if (msg.temperature < 18) {
    return ['Low temperature'];
} else {
    return ['Normal temperature'];
}

The above code defines three exits, namely High temperature, Low temperature, and Normal temperature. Therefore, when connecting to the next node, we need to customize the connection according to our defined exit path, as shown in the following figure. After completing the input, press "Enter" to create a link label, and then click "Add".

 

1730355203367-790.png

1730355288161-463.png

6.2 properties

6.2.1 calculate delta

This rule node is used to calculate the difference between the data in this message and the corresponding data in the previous message, and to refine and distribute the message content based on the calculation results. The configuration content of this node includes:

  • Name: required field, indicating the name of the node;
  • Input value Key: required field, the name of the attribute to be incrementally calculated;
  • Output value Key: required field, the attribute name of the incremental value calculated and added to the message body;
  • Decimals: Accuracy of incremental computation;
  • Use cache: Select option to store the value of the previous data in memory, checked by default;
  • Tell Failure if delta is negative: Select option. If the increment value is negative, it is considered a message processing failure and is checked by default;
  • Add period between messages: Select option to add the time difference from the previous message in the message body, not checked by default. After selecting, you need to fill in the Period value key as the attribute name added to the message body as the calculated time difference;
  • Exclude zero deltas from outbound message:Only output data with delta difference non-zero.
  • Explanation: Non mandatory field, additional explanation;

According to the running results, there are three types of exits for this rule node: Success, Failure, and Other:

  • Success: The data export for successful incremental calculation;
  • Failure: The data exit for message processing failure. If Tell Failure if delta is negative is checked, the data with a negative increment will be calculated and output from this exit;
  • Other: The data export for the attribute value to be incrementally calculated is missing from the message;

A simple usage example is as follows:

1730356036784-417.png

6.2.2 customer attributes

This rule node is used to add some attributes configured for users to the metadata of messages and distribute data based on the processing results. The configuration content of this node includes:

  • Name: required field, indicating the name of the node;
  • Latest telemetry: a selection option that will retrieve the latest attribute values reported remotely by the client based on the configured key. Unchecking it will query the server attributes of the client to which the device belongs, and it will be unchecked by default;
  • Source telemetry key: input item, the name of the customer attribute to be added to the message metadata;
  • Target attribute: Input item, the attribute name to be added to the message metadata, which appears in conjunction with the Source telemetry key and can add multiple pairs of attributes;
  • Explanation: Non mandatory field, additional explanation;

According to the running results, there are two types of exits for this rule node: Success and Failure. When the customer to which the device belongs is not configured, data is output from the Failure exit.

This involves setting user attributes, which can be configured as follows.

1730357095598-358.png

A simple example of using this rule node is as follows:

1730357340823-311.png

6.2.3 customer details

This rule node is used to add some detailed information configured for users to the message and distribute data based on the processing results. The configuration content of this node includes:

  • Name: required field, indicating the name of the node;
  • Select entity details: Multiple options, select the detailed information of the customer to be added to the message (the information configured when creating the customer, including country, city, address, email, etc.), and the attribute name format of the added information is "customer-specific content name";
  • Add selected details to message metadata: If checked, the corresponding information will be added to the metadata and passed to downstream nodes; If not checked, the corresponding information will be added to the data and passed to downstream nodes. Not selected by default;
  • Explanation: Non mandatory field, additional explanation;

According to the running results, there are two types of exits for this rule node: Success and Failure. When the customer to which the device belongs is not configured, data is output from the Failure exit.

A simple usage example is as follows:

1730357528275-219.png

6.2.4 tenant attributes

6.2.5 tenant details

6.2.6 fetch device credentials

6.3 transformation

6.3.1 copy keys

6.3.2 delete keys

6.3.3 rename keys

6.3.4 deduplication

6.3.5 script

6.4 action

6.4.1 math function

6.4.2 create alarm && clear alarm

6.4.3 delay

6.4.4 generator

6.4.5 log

6.5 external

6.5.1 kafka

6.5.2 mqtt

6.5.3 rest api call