Getting Started with Rule Engine

What is NDU Rule Engine?

Rule Engine is an easy to use framework for building event-based workflows. There are 3 main components:

Typical Use Cases

NDU Rule Engine is a highly customizable framework for complex event processing. Here are some common use cases that one can configure via NDU Rule Chains:

Hello-World Example

Let’s assume your device is using DHT22 sensor to collect and push temperature to the NDU. DHT22 sensor can measure temperature from -40°C to +80°C.

In this tutorial we will configure NDU Rule Engine to store all temperature within -40 to 80°C range and log all other readings to the system log.

Adding temperature validation node

In NDU UI go to Rule Chains section and open Root Rule Chain. image

Drag and Drop Script Filter rule node to the chain. Node configuration window will be opened. We will use this script for data validation:

return typeof msg.temperature === 'undefined' 
        || (msg.temperature >= -40 && msg.temperature <= 80);


If temperature property not defined or temperature is valid - script will return True, otherwise it will return False. If script returns True incoming message will be routed to the next nodes that are connected with True relation.

Now we want that all telemetry requests pass through this validation script. We need to remove the existing Post Telemetry relation between Message Type Switch node and Save Telemetry node:


And connect Message Type Switch node with Script Filter node using Post Telemetry relation:



Next, we need to connect Script Filter node with Save Telemetry node using True relation. So all valid telemetry will be saved:


Also, we will connect Script Filter node with Log Other node using False relation. So that all not valid telemetry will be logged in the system log:


Press Save button to apply changes.

Validate results

For validating results we will need to create Device and submit telemetry to the NDU. So go to Devices section and create new Device:


For posting device telemetry we will use Rest API. To do this this we will need to copy device access token from the device Thermostat Home.


Lets post temperature = 99. We will see that telemetry was not added in Device Latest Telemetry section:

curl -v -X POST -d '{"temperature":99}' http://localhost:8080/api/v1/$ACCESS_TOKEN/telemetry --header "Content-Type:application/json"

*you need to replace $ACCESS_TOKEN with actual device token


Lets post temperature = 24. We will see that telemetry was saved successfully.

curl -v -X POST -d '{"temperature":24}' http://localhost:8080/api/v1/$ACCESS_TOKEN/telemetry --header "Content-Type:application/json"


See Also:

You can use the next links for learning more about Netcad Digital Universe Rule Engine:

Next steps