规则引擎

相比服务端订阅只单纯流转上行数据,规则引擎功能更强大。可对上下行数据进行操作,支持用户自定义筛选规则以及指定推送内容,对要流转的数据进行过滤,支持HTTP和MQTT两种流转方式。

规则引擎中通过编写SQL来解析和处理数据,SQL表达式为:

SELECT 【转发的字段】 FROM "数据流" WHERE "过滤条件"

【注意】

平台以HTTP POST请求形式向第三方平台URL地址推送数据时,第三方平台接收到数据后需要返回HTTP状态码 2xx,否则IoT OS会认为此次推送无效并重试,最多重试3次。且等待客户端的响应都设有时限(目前是5秒),在规定时限内没有收到响应会认为发送失败,连续失败100次(包括重试次数,并且计数规则是根据URL计算。相同URL下的不同规则都会被计算在内。)则会认为第三方地址不可用,推送服务将停止,对应订阅或者规则状态显示为"未启用"。建议第三方应用接收程序接收到数据时,先做数据缓存,再做业务逻辑处理。 其中请求的Content-Typeapplication/json

操作说明

1. 登录平台;
2. 在左侧导航栏中选择“规则引擎”;
3. 单击“创建规则”;
4. 选择产品、填写推送字段以及过滤条件;
5. 选择数据转发操作;
6. 添加目的地址(要求服务端使用POST请求)。

【说明】

1. SELECT中“*”表示转发数据中所有字段;
2. WHERE操作符支持“=、>=、<=、>、<、<>(不等于)、and、or”,不支持函数。

SELECT字段说明

可选字段 字段说明
iot_sys_event 事件(devSend\devLogin等事件)
iot_sys_devId 设备ID
iot_sys_pk 设备所属产品pk
iot_sys_req 解析后的KLink数据
iot_sys_resp 云端针对该事件的数据回复
iot_sys_raw 原始请求数据
iot_sys_timestamp 请求时间(ms)
iot_sys_cmd 设备命令
【协议参数】 协议中定义的所有参数标识符

过滤条件WHERE

可选字段 字段说明 可取值
iot_sys_event 事件 dataChanged:数据变化;
cloudSend:控制下发;
cloudSendResp:控制下发回复;
devSend:设备上报;
devLogin:设备登录;
devLogout:设备登出;
reportFirmware:设备上报固件信息;
devUpgradeProgress:设备上报升级进度;
devUpgrade:控制设备升级(包括远程配置);
devUpgradeResp:设备升级回复;
register:注册设备。
iot_sys_devId 设备ID 设备ID,例如:10001
iot_sys_pk 设备所属产品pk 设备pk,例如:c54b2bc00c164e569ac6666aa6a81e8c
iot_sys_cmd 设备命令 协议中定义的命令,例如:iot_sys_cmd="reportPower"
【协议参数】 协议中定义的所有参数标识符 例如:hum>90

用户可以通过规则引擎推送实例中的三个实例来更好的理解规则引擎的用法和功能。

设备操作事件对应推送数据格式详情

下述数据结构表示在一个不进行任何字段筛选(SELECT)或条件过滤(WHERE)的规则引擎下,设备进行相应操作(如设备进行devlogin)时,用户通过HTTP或Topic获得到的数据。

推送实例中的对照实例所获取到的推送数据。

【注意】

用户在进行字段筛选或条件过滤时需要保证字段或者条件被包含在下述数据格式中,尤其是对参数的过滤条件需要被参数的数据类型支持。

设备登录(devLogin)

{
    "iot_sys_devId": "8237948938472348",
    "iot_sys_pk": "fb4327cdcfe5432e82ad217572bd8ebd",
    "iot_sys_req": "{\"action\":\"devLogin\",\"msgId\":0,\"random\":\"init\",\"hashMethod\":\"HmacSHA1\",\"sign\":\"4f6a95a54bad27a874132929781ff4fea1748b7c\"}",
    "iot_sys_event": "devLogin",
    "iot_sys_raw": "{\"action\":\"devLogin\",\"msgId\":0,\"random\":\"init\",\"hashMethod\":\"HmacSHA1\",\"sign\":\"4f6a95a54bad27a874132929781ff4fea1748b7c\"}",
    "iot_sys_resp": "{\"action\":\"devLoginResp\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"code\":0,\"desc\":\"success, \"}",
    "iot_sys_timestamp": 1576466870416
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 设备所属产品pk
iot_sys_req String 解析后的KLink数据
iot_sys_event String 事件
iot_sys_raw String 原始请求数据
iot_sys_resp String 云端针对该事件的数据回复
iot_sys_timestamp number 请求时间(ms)

设备登出(devLogout)

{
    "iot_sys_devId": "8237948938472348",
    "iot_sys_pk": "fb4327cdcfe5432e82ad217572bd8ebd",
    "iot_sys_req": "{\"action\":\"devLogout\",\"msgId\":0,\"reason\":\"device send disconnect\"}",
    "iot_sys_event": "devLogout",
    "iot_sys_raw": "{\"action\":\"devLogout\",\"msgId\":0,\"reason\":\"device send disconnect\"}",
    "iot_sys_resp": "{\"action\":\"devLogoutResp\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"code\":0,\"desc\":\"success\"}",
    "iot_sys_timestamp": 1576467109928
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 设备所属产品pk
iot_sys_req String 解析后的KLink数据
iot_sys_event String 事件
iot_sys_raw String 原始请求数据
iot_sys_resp String 云端针对该事件的数据回复
iot_sys_timestamp number 请求时间(ms)

设备上报(devSend)

{
    "iot_sys_devId": "8237948938472348",
    "iot_sys_pk": "fb4327cdcfe5432e82ad217572bd8ebd",
    "iot_sys_req": "{\"action\":\"devSend\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"data\":{\"cmd\":\"reportPower\",\"params\":{\"power\":0}}}",
    "iot_sys_params": {
        "power": 0
    },
    "iot_sys_event": "devSend",
    "iot_sys_cmd": "reportPower",
    "iot_sys_raw": "{\"action\":\"devSend\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"data\":{\"cmd\":\"reportPower\",\"params\":{\"power\":0}}}",
    "iot_sys_resp": "{\"action\":\"devSendResp\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"code\":0,\"desc\":\"success\"}",
    "iot_sys_timestamp": 1576467306280
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 设备所属产品pk
iot_sys_req String 解析后的KLink数据
iot_sys_params object 所属产品定义的参数
iot_sys_event String 事件
iot_sys_cmd String 所属产品定义的命令
iot_sys_raw String 原始请求数据
iot_sys_resp String 云端针对该事件的数据回复
iot_sys_timestamp number 请求时间(ms)

数据变化(dataChanged)

{
    "iot_sys_devId": "B03_BF01_002_ACVTES_00001",
    "iot_sys_pk": "a71989f93c59473eaaa11af0823985f1",
    "iot_sys_req": "{\"action\":\"devSend\",\"msgId\":0,\"pk\":\"a71989f93c59473eaaa11af0823985f1\",\"devId\":\"B03_BF01_002_ACVTES_00001\",\"data\":{\"cmd\":\"reportFrame\",\"params\":{\"ALM\":1,\"ART\":836.31,\"STS\":0,\"MODE\":0,\"PT_AM\":0,\"ARTIV\":515.14,\"AM\":0,\"CS_IC\":1}}}",
    "iot_sys_event": "dataChanged",
    "iot_sys_raw": "{\"last\":{\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"timestamp\":1576482068202,\"data\":{\"cmd\":\"reportPower\",\"params\":{\"hum\":23,\"light\":50,\"power\":1}}},\"current\":{\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"timestamp\":1576482072514,\"data\":{\"cmd\":\"reportPower\",\"params\":{\"power\":0}}},\"changed\":true}",
    "iot_sys_timestamp": 1591346264929,
    "iot_sys_snapshot": {
        "last": {
            "pk": "a71989f93c59473eaaa11af0823985f1",
            "devId": "B03_BF01_002_ACVTES_00001",
            "timestamp": 1591346253899,
            "data": {
                "cmd": "reportPower",
                "params": {
                    "hum": 23,
                    "light": 50,
                    "power": 1
                }
            }
        },
        "current": {
            "pk": "a71989f93c59473eaaa11af0823985f1",
            "devId": "B03_BF01_002_ACVTES_00001",
            "timestamp": 1591346264927,
            "data": {
                "cmd": "reportPower",
                "params": {
                    "power": 0
                }
            }
        }
    }
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 设备所属产品pk
iot_sys_req String 解析后的KLink数据
iot_sys_event String 事件
iot_sys_raw String 原始请求数据
iot_sys_resp String 云端针对该事件的数据回复
iot_sys_timestamp number 请求时间(ms)
iot_sys_snapshot object 设备快照

【注意】

设备快照中last字段表示数据改变前一次的快照,current字段表示数据改变时的快照。

如果是第一次上报数据,last 为 null。

设备上报固件信息(reportFirmware)

{
    "iot_sys_devId": "8237948938472348",
    "iot_sys_pk": "fb4327cdcfe5432e82ad217572bd8ebd",
    "iot_sys_req": "{\"action\":\"reportFirmware\",\"msgId\":1,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"type\":\"module\",\"version\":\"1.2.1\"}",
    "iot_sys_event": "reportFirmware",
    "iot_sys_raw": "{\"action\":\"reportFirmware\",\"msgId\":1,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"type\":\"module\",\"version\":\"1.2.1\"}",
    "iot_sys_resp": "{\"action\":\"reportFirmwareResp\",\"msgId\":1,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"code\":0}",
    "iot_sys_timestamp": 1576029149134
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 设备所属产品pk
iot_sys_req String 解析后的KLink数据
iot_sys_event String 事件
iot_sys_raw String 原始请求数据
iot_sys_resp String 云端针对该事件的数据回复
iot_sys_timestamp number 请求时间(ms)

控制下发(cloudSend)

{
    "iot_sys_devId": "8237948938472348",
    "iot_sys_pk": "fb4327cdcfe5432e82ad217572bd8ebd",
    "iot_sys_req": "{\"action\":\"cloudSend\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"data\":{\"cmd\":\"setPower\",\"params\":{\"power\":0}}}",
    "iot_sys_event": "cloudSend",
    "iot_sys_raw": "{\"action\":\"cloudSend\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"data\":{\"cmd\":\"setPower\",\"params\":{\"power\":0}}}",
    "iot_sys_resp": "{\"action\":\"cloudSendResp\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"code\":0,\"desc\":\"success\"}",
    "iot_sys_timestamp": 1576467240890
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 设备所属产品pk
iot_sys_req String 解析后的KLink数据
iot_sys_event String 事件
iot_sys_raw String 原始请求数据
iot_sys_resp String 云端针对该事件的数据回复
iot_sys_timestamp number 请求时间(ms)

控制下发回复(cloudSendResp)

{
    "iot_sys_devId": "8237948938472348",
    "iot_sys_pk": "fb4327cdcfe5432e82ad217572bd8ebd",
    "iot_sys_req": "{\"action\":\"cloudSendResp\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"code\":0}",
    "iot_sys_event": "cloudSendResp",
    "iot_sys_raw": "{\"action\":\"cloudSendResp\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"code\":0}",
    "iot_sys_timestamp": 1576029802710
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 设备所属产品pk
iot_sys_req String 解析后的KLink数据
iot_sys_event String 事件
iot_sys_raw String 原始请求数据
iot_sys_timestamp number 请求时间(ms)

控制设备升级-包括远程配置(devUpgrade)

{
    "iot_sys_devId": "8237948938472348",
    "iot_sys_pk": "fb4327cdcfe5432e82ad217572bd8ebd",
    "iot_sys_req": "{\"action\":\"devUpgrade\",\"msgId\":0,\"url\":\"http://123.59.81.102:9002/hekr/d40a16a8a6bf4d418aa8bd3b01026fb1.zip\",\"md5\":\"1ecbdec973be231e5a84a8803996d5e5\",\"version\":\"1.2.1\",\"type\":\"module\"}",
    "iot_sys_event": "devUpgrade",
    "iot_sys_raw": "{\"action\":\"devUpgrade\",\"msgId\":0,\"url\":\"http://123.59.81.102:9002/hekr/d40a16a8a6bf4d418aa8bd3b01026fb1.zip\",\"md5\":\"1ecbdec973be231e5a84a8803996d5e5\",\"version\":\"1.2.1\",\"type\":\"module\"}",
    "iot_sys_resp": "{\"action\":\"devUpgradeResp\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"code\":0,\"desc\":\"success\"}",
    "iot_sys_timestamp": 1576467452534
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 设备所属产品pk
iot_sys_req String 解析后的KLink数据
iot_sys_event String 事件
iot_sys_raw String 原始请求数据
iot_sys_resp String 云端针对该事件的数据回复
iot_sys_timestamp number 请求时间(ms)

设备升级回复(devUpgradeResp)

{
    "iot_sys_devId": "8237948938472348",
    "iot_sys_pk": "fb4327cdcfe5432e82ad217572bd8ebd",
    "iot_sys_req": "{\"action\":\"devUpgradeResp\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"code\":0}",
    "iot_sys_event": "devUpgradeResp",
    "iot_sys_raw": "{\"action\":\"devUpgradeResp\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"type\":\"module\",\"code\":0}",
    "iot_sys_timestamp": 1576467892152
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 设备所属产品pk
iot_sys_req String 解析后的KLink数据
iot_sys_event String 事件
iot_sys_raw String 原始请求数据
iot_sys_timestamp number 请求时间(ms)

设备上报升级进度(devUpgradeProgress)

{
    "iot_sys_devId": "8237948938472348",
    "iot_sys_pk": "fb4327cdcfe5432e82ad217572bd8ebd",
    "iot_sys_req": "{\"action\":\"devUpgradeProgress\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"progress\":19,\"type\":\"module\"}",
    "iot_sys_event": "devUpgradeProgress",
    "iot_sys_raw": "{\"action\":\"devUpgradeProgress\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"type\":\"module\",\"code\":0,\"progress\":19}",
    "iot_sys_resp": "{\"action\":\"devUpgradeProgressResp\",\"msgId\":0,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237948938472348\",\"code\":0,\"desc\":\"success\"}",
    "iot_sys_timestamp": 1576468087217
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 设备所属产品pk
iot_sys_req String 解析后的KLink数据
iot_sys_event String 事件
iot_sys_raw String 原始请求数据
iot_sys_resp String 云端针对该事件的数据回复
iot_sys_timestamp number 请求时间(ms)

注册设备(register)

{
    "iot_sys_devId": "8237942348",
    "iot_sys_pk": "fb4327cdcfe5432e82ad217572bd8ebd",
    "iot_sys_req": "{\"action\":\"register\",\"msgId\":1,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237942348\",\"random\":\"random\",\"hashMethod\":\"HmacMD5\",\"sign\":\"5e2b3d5b9023761a07dd8ca34c3db9c4\"}",
    "iot_sys_event": "register",
    "iot_sys_raw": "{\"action\":\"register\",\"msgId\":1,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237942348\",\"random\":\"random\",\"hashMethod\":\"HmacMD5\",\"sign\":\"5e2b3d5b9023761a07dd8ca34c3db9c4\"}",
    "iot_sys_resp": "{\"action\":\"registerResp\",\"msgId\":1,\"pk\":\"fb4327cdcfe5432e82ad217572bd8ebd\",\"devId\":\"8237942348\",\"code\":0,\"desc\":\"success\",\"devSecret\":\"817cbd2487064dd4a199618f29e12cbb\"}",
    "iot_sys_timestamp": 1576029701743
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 设备所属产品pk
iot_sys_req String 解析后的KLink数据
iot_sys_event String 事件
iot_sys_raw String 原始请求数据
iot_sys_resp String 云端针对该事件的数据回复
iot_sys_timestamp number 请求时间(ms)

网关登录(gatewayLogin)

以下字段只有在 action 为 gatewayLogin 或者 gatewayLogout

  • iot_sys_gatewayDevId 网关设备id
  • iot_sys_gatewayPk 网关设备pk
  • iot_sys_online 子设备当前状态

注意 因该条消息是网关登录联动触发子设备登录消息,所以 iot_sys_req 为网关的请求。

{
    "iot_sys_devId": "S01_S001_001_SDVDXL_00001",
    "iot_sys_pk": "2340cf841c944612866e717a5bca4d9f",
    "iot_sys_rawResp": "{\"action\":\"devLoginResp\",\"msgId\":0,\"code\":0,\"desc\":\"gateway login, pk:e4ac23c92e6648a9bdf734370e7f8601, devId:gateway1001\"}",
    "iot_sys_req": "{\"action\":\"devLogin\",\"msgId\":1,\"random\":\"init\",\"hashMethod\":\"HmacSHA1\",\"sign\":\"2e493cdc7bd2fff3f5dff79896088380160346c4\"}",
    "iot_sys_gatewayDevId": "gateway1001",
    "iot_sys_event": "gatewayLogin",
    "iot_sys_raw": "{\"action\":\"devLogin\",\"msgId\":1,\"random\":\"init\",\"hashMethod\":\"HmacSHA1\",\"sign\":\"2e493cdc7bd2fff3f5dff79896088380160346c4\"}",
    "iot_sys_resp": "{\"action\":\"devLoginResp\",\"msgId\":0,\"code\":0,\"desc\":\"gateway login, pk:e4ac23c92e6648a9bdf734370e7f8601, devId:gateway1001\"}",
    "iot_sys_online": true,
    "iot_sys_gatewayPk": "e4ac23c92e6648a9bdf734370e7f8601",
    "iot_sys_timestamp": 1591952706347
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 当前子设备所属产品pk
iot_sys_rawResp String 原始返回数据
iot_sys_req String 解析后的KLink网关请求数据
iot_sys_gatewayDevId String 子设备所属网关设备ID
iot_sys_event String 事件类型
iot_sys_raw String 原始请求数据
iot_sys_resp String 云端针对该事件的数据回复
iot_sys_online boolean 当前子设备是否在线
iot_sys_gatewayPk String 子设备所属网关设备产品pk
iot_sys_timestamp number 请求时间(ms)

网关离线(gatewayLogout)

以下字段只有在 action 为 gatewayLogin 或者 gatewayLogout

  • iot_sys_gatewayDevId 网关设备id
  • iot_sys_gatewayPk 网关设备pk
  • iot_sys_online 子设备当前状态

注意 因该条消息是网关登出联动触发子设备登出消息,所以 iot_sys_req 为网关的请求。

{
    "iot_sys_devId": "S01_S001_001_SDVDXL_00001",
    "iot_sys_pk": "2340cf841c944612866e717a5bca4d9f",
    "iot_sys_rawResp": "{\"action\":\"devLogoutResp\",\"msgId\":0,\"code\":0,\"desc\":\"gateway logout, pk:e4ac23c92e6648a9bdf734370e7f8601, devId:gateway1001\"}",
    "iot_sys_req": "{\"action\":\"devLogout\",\"msgId\":0,\"reason\":\"closed\"}",
    "iot_sys_gatewayDevId": "gateway1001",
    "iot_sys_event": "gatewayLogout",
    "iot_sys_raw": "{\"action\":\"devLogout\",\"msgId\":0,\"reason\":\"closed\"}",
    "iot_sys_resp": "{\"action\":\"devLogoutResp\",\"msgId\":0,\"code\":0,\"desc\":\"gateway logout, pk:e4ac23c92e6648a9bdf734370e7f8601, devId:gateway1001\"}",
    "iot_sys_online": true,
    "iot_sys_gatewayPk": "e4ac23c92e6648a9bdf734370e7f8601",
    "iot_sys_timestamp": 1591952686848
}
参数 类型 说明
iot_sys_devId String 设备ID
iot_sys_pk String 当前子设备所属产品pk
iot_sys_rawResp String 原始返回数据
iot_sys_req String 解析后的KLink网关请求数据
iot_sys_gatewayDevId String 子设备所属网关设备ID
iot_sys_event String 事件类型
iot_sys_raw String 原始请求数据
iot_sys_resp String 云端针对该事件的数据回复
iot_sys_online boolean 当前子设备是否在线
iot_sys_gatewayPk String 子设备所属网关设备产品pk
iot_sys_timestamp number 请求时间(ms)

results matching ""

    No results matching ""

    results matching ""

      No results matching ""