Sensor Based

Sensor based MR rule is created when filtering is based on sensor of the input JSON data. Here the sensor name is provided in MR rule which is supposed to filter the provided sensor only and discard the other features.

  • Below is the create rule JSON based on sensor only:

{
  "RuleName": "Demo rule sensor",
  "RuleDescription": "Demo rule for user guide",
  "input": {
     "DirectExchange": "Direct.Exchange",
     "RoutingKey": "e325f4fe-a0e3-4252-82af-4c24deb8c0cf"
  },
  "params": [
     {
         "name": "feature",
         "value": ""
     },
     {
         "name": "sensorID",
         "value": "NEXUS1"
     },
     {
         "name": "time",
         "value": {
             "starttime": "",
             "endtime": ""
         }
     },
     {
         "name": "expression",
         "value": {
             "if": "",
             "then": "",
             "else": ""
         }
     },
     {
         "name": "",
         "type": "rectangle/circles/polygon",
         "geoFencing": "YES/NO",
         "value": {
             "points": [
                 {
                     "x": "",
                     "y": ""
                 },
                 {
                     "x": "",
                     "y": ""
                 }
             ]
         }
     },
     {
         "name": "ObservedProperties",
         "value": [
             {
                 "name": "",
                 "type": "Text/quantity/count",
                 "value": "",
                 "operator": ""
             }
         ]
      }
    ],
   "output": {
     "TopicExchange": "DemoExchange",
     "Topic": "demo2"
   }
 }

As we can see in the above JSON the sensor value provided is NEXUS1 which acts as filtering condition for input data and routes the input data with the sensor as NEXUS1 only. In case the input data has sensor value other than NEXUS1, it will discard the data. Topic exchange name is DemoExchange which we have already created in the topic exchange section.

Now we will create the above rule in the following 2 ways:

  • Using MR API swagger

  • Using MR portal

Using MR API swagger

  • Click on POST /routingRules API in swagger, use the above JSON template and hit Try it out! button, it will create a new MR rule with sensor as shown in the image below:

../../../_images/sensorRule1.jpg

As we can see in the above image, MR rule created with rule ID - 1114 will be used to start this rule. We can refer to Start the Routing Channel to start the rule.

Using MR portal

  • Click on Create Rule button in MR rule, fill in all the details as mentioned in the image below and click Create Rule button, it will create a new MR rule with sensor as shown in the image below:

../../../_images/sensorRule2.jpg
  • After clicking Create Rule button the below message will be dispalyed at the upper right corner with rule ID. Here in our case rule ID is 1115.

../../../_images/sensorRule3.jpg

As we can see in the above image, MR rule created with rule ID - 1115 will be used to start this rule. You can refer to Start the Routing Channel section to start the rule.

Send Request operation

After the rule is created it needs to be started as mentioned above and then input JSON can be posted to MR rule using send request API. For this we have to configure and start SSE viewer page and send the observation matching to the MR rule.

  • Below is the input SOS observation JSON

{
  "version": "1.0.1",
  "observations": [
    {
         "sensor": "NEXUS1",
         "feature": "room1",
         "record": [
             {
                 "starttime": "1-JAN-2014 15:30:03 IST",
                 "output": [
                     {
                         "name": "OutsideSensorTemp",
                         "value": "46.0",
                         "type": "decimal"
                     },
                     {
                         "name": "temp",
                         "value": "99",
                         "type": "quantity"
                     }
                 ]
             }
         ],
         "meta-data": []
      }
    ]
 }

Here in input JSON we can see that sensor name is NEXUS1 which is same as MR rule sensor. We can now use send request API to verify this rule. Please refer Execute and View Result section to send the request and view the output in SSE viewer.