目录

创建自动规则

适用平台

Android、iOS

请求消息

当需要创建自动规则时,WEB中调用js方法如下:

hilink.createRule(
"json_body", // body,string, 规则json字符串
"resultCallback" // resultCallback,成功或失败时,将调用传入resultStr返回结果
);
// web页面中需实现该函数,用来获取执行结果
function resultCallback  (resultStr) {
var result = resultStr; // REST请求的返回结果
}

json_body中携带需要创建的规则,格式如下:

{
    "name": "Rule01",
    "conditions": [
        {
            "type": "DEVICE_DATA",
            "deviceInfo": {
                "devId": "2323-1221-...",
                "devType": "005",
                "path": "switch/on"
            },
            "operator": "=",
            "value": "1"
        }
    ],
    "actions": [
        {
            "type": "DEVICE_CMD",
            "devId": "2323-1221-...",
            "devType": "01B",
            "cmd": {
                "sid": "switch",
                "messageType": "POST",
                "messageBody": {
                    "on": 1
                }
            }
        }
    ]
}

Body不能为空,否则将失败。

响应消息

当调用成功时,JSSDK将调用success对应的回调函数,将如下结果返回到resultStr中。

{
    "ruleId": "*******",
    "name": "Rule01",
    "conditions": [
        {
            "id": "****",
            "type": "DEVICE_DATA",
            "deviceInfo": {
                "devId": "2323-1221-...",
                "devType": "005",
                "path": "switch/on"
            },
            "operator": "=",
            "value": "1"
        }
    ],
    "author": "12222",
    "actions": [
        {
            "type": "DEVICE_CMD",
            "id": "****",
            "devId": "2323-1221-...",
            "devType": "01B",
            "cmd": {
                "sid": "switch",
                "messageType": "POST",
                "messageBody": {
                    "on": 1
                }
            }
        }
    ]
}

错误码

{
  "errcode": 11
}

错误码说明参见错误码。