Unit 2: Building the Routing Rule


A routing rule is made up of a series of rule nodes that process the incoming messages from devices.

Step 1: Creating A Rule

  1. Log in to EnOS Management Console and click Routing Rule from the left navigation menu.
  2. Click New Routing Rule.
  3. Enter the rule name Temp Sensor Rule and description, and click OK.

Step 2: Designing the Rule

You will enter a design canvas page with the Rule Entry node.


Design and connect the rule with the following nodes in the order shown below.


../../_images/s1_rule.png

Rule Entry Node

Every routing rule must start with the Rule Entry node.

  1. Click the Rule Entry node.
  2. Select EnOS IoT from the Gateway Type drop-down.
  3. Select Temperature Sensor Product from Product so that all incoming data from devices under this product will come to this rule to be processed.


../../_images/s1_rule_rule_entry.png


For more information, see the Rule Entry node.

Message Type Switch Node

The Message Type Switch node routes the incoming message when the devices under the Temperature Sensor Product post their measurement points.

  1. Click the Message Type Switch node.
  2. Select Post Measurement Point from the Message Type drop-down.


../../_images/s1_rule_msg_type_switch.png


For more information, see the Message Type Switch node.

Multicast Node

The Multicast node forwards the input to multiple nodes to be processed in different ways. In this tutorial, the input is processed in 2 ways: sends a command to the air-con device if the temperature is higher than 30, and routes the rule to the EnOS_default rule which will send the measurement points to a Kafka topic and save the measurement points posted to EnOS.


For more information, see the Multicast node.

Script Switch Node

The Script Switch node routes the output from the Multicast node according to the results of the written JavaScript. In this tutorial, the script checks that the temperature value from the input is a number and if the value is higher than 30, will route to the next node.

  1. Click the Script Switch node.
  2. Click the Script tab and enter the script as per the below.


if (typeof msg.temperature === 'number') {
  return msg.temperature > 30;
} else {
  throw new Error('Temperature type unsupported');
}


../../_images/s1_rule_script_switch.png


For more information, see the Script Switch node.

Send Command Node

The Send Command node sends a command to the Air Con Device to adjust the temperature to 26.

  1. Click the Send Command node.

  2. Select Mixed Message from the Message Source drop-down.

  3. Select Air Con Product from the Product drop-down, select Device Name for Device, and select Air Con Device.

  4. Select Invoke Service for Command Message Type.

  5. Select ctrlTemperature from the Service drop-down, and enter the following for Message.


    {
     "ctrlTemperature": 26
    }
    


  6. Select Send command immediately from the Method drop-down.


../../_images/s1_rule_send_command.png


For more information, see the Send Command node.

Checkpoint Node

The Checkpoint node routes the rule to the EnOS_default rule.

  1. Click the Checkpoint node.
  2. Select Use Default Rule from the Action drop-down.


../../_images/s1_rule_checkpoint_.png


For more information, see the Checkpoint node.