系统基础消息数据格式为JSON,可将其映射为虚拟数据表,数据表中的key对应表的列,value对应列值,规则引擎通过SQL语句对数据进行处理,如图所示:
{
"projectId": "990909090",
"productId": "00001",
"deviceName": "iot-0001",
"messageType": "notify",
"notifyType":"property",
"data": {
"id": "12345",
"params": {
"Power": {
"value": "on",
"time": 1524448722123
},
"WF": {
"value": 23.6,
"time": 1524448722123
}
}
}
}
SQL 示例:
SELECT productId, deviceName, data FROM /deviceDatapoint/ds WHERE notifyType = 'property'
该SQL语句表示:
筛选设备物模型数据中的属性功能点数据, 提取productId、deviceName和data三个属性字段。
经过该SQL处理的消息输出如下消息
{
"productId": "00001",
"deviceName": "iot-0001",
"data": {
"id": "12345",
"params": {
"Power": {
"value": "on",
"time": 1524448722123
},
"WF": {
"value": 23.6,
"time": 1524448722123
}
}
}
}
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 |