{ "id":"rule1", "sql":"SELECT avg(temperature) AS avg_temperature FROM demo WHERE temperature != nil and meta(deviceName)= \"TCP-5900\" GROUP BY TUMBLINGWINDOW(ss, 5) HAVING avg(temperature) > 20.0", "actions":[ { "rest":{ "url":"http://edgex-core-command:59882/api/v2/device/name/Random-Boolean-Device/WriteBoolValue", "method":"put", "dataTemplate":"{\"Bool\":\"false\", \"EnableRandomization_Bool\": \"false\"}", "sendSingle":true } }, { "log":{} } ] }
查看kuiper的log以及布尔型虚拟设备的值,规则生效
下面测试触发规则引擎后设置温湿度设备的高温预警值:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
{ "id":"rule2", "sql":"SELECT avg(temperature) AS avg_temperature FROM demo WHERE temperature != nil and meta(deviceName)= \"TCP-5900\" GROUP BY TUMBLINGWINDOW(ss, 5) HAVING avg(temperature) > 20.0 ", "actions":[ { "rest":{ "url":"http://edgex-core-command:59882/api/v2/device/name/TCP-5900/HighTemperatureAlarm", "method":"put", "dataTemplate":"{\"HighTemperatureAlarm\":\"66\"}", "sendSingle":true } }, { "log":{} } ] }
rule2触发并且生效
下面测试当10秒内平均温度大于高温预警值的时候,发送数据给云端,规则如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
{ "id":"rule3", "sql":"SELECT avg(temperature) AS avg_temperature , avg(HighTemperatureAlarm) AS avg_hightemperaturealarm FROM event WHERE temperature != nil and meta(deviceName)= \"TCP-5900\" and meta(sourceName)=\"Data\" GROUP BY TUMBLINGWINDOW(ss, 10) HAVING avg(temperature) > avg(hightemperaturealarm) ", "actions":[ { "rest":{ "url":"http://10.116.169.252:8888/kuiper", "method":"post", "dataTemplate":"{\"Temperature\": \"{{.avg_temperature}}\",\"HighTemperatureAlarm\": \"{{.avg_hightemperaturealarm}}\"}", "sendSingle":true } }, { "log":{} } ] }