OneNET designs the basic message format of the system as json, of which the data can be mapped to a virtual table, with Key corresponding to the column and Value corresponding to the column value. Rule Engine supports SQL statements to process the data, as shown below:
When device data point message is selected as source, the basic message format is as follows:
{
"sysProperty": {
"messageType": "deviceDatapoint",
"productId": "90273"
},
"appProperty":{
"deviceId": "102839",
"dataTimestamp": 15980987429000,
"datastream":"weather"
},
"body":{
"temperature": 30,
"humidity": "47%"
}
}
SQL example:
SELECT appProperty.deviceId as did, body as weather FROM /deviceDatapoint/ds WHERE body.temperature > 10
This SQL statement indicates:
Select the message uploaded to the data point by the device. When the value of body is bigger than 10, extract appProperty.deviceId property and rename it as did; extract body property and rename it as temperature, and forward it after message restructuring.
The message processed by this SQL outputs the following information:
{
"did": "90273",
"weather": {
"temperature": 30,
"humidity": "47%"
}
}
SELECT body as temperature
SELECT appProperty.deviceId as did
SELECT appProperty.deviceId as did, appProperty.dataTimestamp as t
The WHERE statement is used to define rule trigger conditions.
SELECT * WHERE body.temperature > 10
SELECT * WHERE body.temperature = 10
SELECT * WHERE body.humidity = '47%'
SELECT * WHERE body.temperature > 10 AND body.temperature < 30
See the table below for further information about expression support.Operator | Description | Example |
---|---|---|
= | Equal to | temperature=20 |
!= | Not equal to | temperature!=20 |
AND | Logical AND | temperature=20 AND country='CN' |
OR | Logical OR | temperature=20 OR country='CN' |
( ) | Give priority to evaluating expressions in parentheses | temperature=20 AND (country='CN' OR online = true) |
+ | Arithmetic addition | 4+5 |
- | Arithmetic subtraction | 5-4 |
/ | Arithmetic division | 10/5 |
* | Arithmetic multiplication | 2*5 |
% | Remainder | 20%7 |
< | Less than | 5<6 |
<= | Less than or equal to | 5<=6 |
> | Greater than | 5>4 |
>= | Greater than or equal to | 5>=4 |