OneNET将系统的基础消息格式设计为json格式,其数据可以映射为虚拟的表,数据中的Key对应表的列,Value对应列值,规则引擎支持SQL语句对该数据进行处理,如下图所示:
消息源选择为设备数据点消息,基础消息格式示例如下:
{
"sysProperty": {
"messageType": "deviceDatapoint",
"productId": "90273",
},
"appProperty":{
"deviceId": "102839",
"dataTimestamp": 15980987429000,
"datastream":"weather"
},
"body":{
"temperature": 30,
"humidity": "47%"
}
}
SQL示例:
SELECT appProperty.deviceId as did, body as weather FROM /deviceDatapoint/ds WHERE body.temperature > 10
该SQL语句表示:
筛选设备上传数据点的消息,当body的value大于10的时候,提取 appProperty.deviceId 属性,并重命名为 did;提取body属性,重命名为temperature ,消息重组后进行转发
经过该SQL处理的消息输出如下消息
{
"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
WHERE语句用于定义规则触发条件
SELECT * WHERE body.temperature > 10
SELECT * WHERE body.temperature = 10
SELECT * WHERE body.humidity = '47%'
SELECT * WHERE body.temperature > 10 AND body.temperature < 30
表达式支持详情见下表操作符 | 说明 | 举例 |
---|---|---|
= | 相等 | temperature=20 |
!= | 不等于 | temperature!=20 |
AND | 逻辑与 | temperature=20 AND country='CN' |
OR | 逻辑或 | temperature=20 OR country='CN' |
( ) | 括号中表达式优先计算 | temperature=20 AND (country='CN' OR online = true) |
+ | 算术加法 | 4+5 |
- | 算术减法 | 5-4 |
/ | 算术除法 | 10/5 |
* | 算术乘法 | 2*5 |
% | 取余 | 20%7 |
< | 小于 | 5<6 |
<= | 小于等于 | 5<=6 |
> | 大于 | 5>4 |
>= | 大于等于 | 5>=4 |