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 |
* | 算術乘法 | 25 |
% | 取餘 | 20%7 |
\< | 小於 | 56 |
\<= | 小於等於 | 5\<=6 |
> | 大於 | 54 |
>= | 大於等於 | 5>=4 |