Guides

Explore NDU tutorials and guides.

Create and Clear Alarms

Use case

Let’s assume your device is using DHT22 sensor to collect and push temperature readings to NDU. DHT22 sensor is good for -40 to 80°C temperature readings. We want generate Alarms if temperature is out of good range.

In this tutorial we will configure NDU Rule Engine to

Prerequisites

We assume you have completed the following guides and reviewed the articles listed below:

Adding the device

Add Device entity in NDU. Its name is Thermostat Home and its type is Thermostat.

image


Message flow

In this section, we explain the purpose of each node in this tutorial:


Configure Rule Chains

In this tutorial, we modified our Root Rule Chain and also created Rule Chain Create & Clear Alarms


The following screenshots show how the above Rule Chains should look like:

image

image


Download the attached json file for the Create & Clear Alarms rule chain. Create Node D as shown on the image above in the root rule chain to forward telemetry to the imported rule chain.

The following section shows you how to create this rule chain from scratch.

Create new Rule Chain (Create & Clear Alarms)

Go to Rule Chains -> Add new Rule Chain

Configuration:

image

New Rule Chain is created. Press Add button and configure Chain.

Adding the required nodes

In this rule chain, you will create 3 nodes as it will be explained in the following sections:

Node A: Filter Script
1
return msg.temperature < -40 || msg.temperature > 80;

If the temperature is in the expected interval the script will return False, otherwise True will be returned.

image

Node B: Create alarm

image

Node C: Clear Alarm

image

Modify Root Rule Chain

The following screenshot shows the initial Root Rule Chain.

image

The initial Rule Chain has been modified by adding the following node:

Node D: Rule Chain

image




How to verify the Rule Chain and Post telemetry

For posting device telemetry we will use the Rest APIs, Telemetry upload APIs. For this we will need to copy device access token from the device Thermometer.

1
**you need to replace $ACCESS_TOKEN with actual device token**

Let’s pushed debug mode button in Clear Alarm and Create Alarm node to verify the results.
Open “Create & Clear Alarms” Rule Chain –> Click on “Clear Alarms or Create Alarms –> And then open the “edit mode”

image
image

sent temperature = 99. Alarm should be created:

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

image image

Lets post temperature = 180. Alarm should be updated:

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

image image

Lets post temperature = 30. Alarm should be cleared:

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

image image


Also, you can:

Please refer to the links from the second to the fourth under the See Also section to see how to do this.


See Also

Next steps