设备数据转储接入API

更新时间:2018-11-26 21:51:12

创建设备数据云产品流转规则

定义描述

path 版本 描述
/industry/ruleAction/create 1.0.4 创建设备数据云产品转储规则

请求参数

名称
类型
必要
描述
productKey
String
产品Key
deviceName
String
设备名称
ruleType
String
规则类型,
ONS or DATAHUB
configure
String
​云产品配置参数
accessKeyId
String
阿里云账号accessKeyId
accessSecret
String
阿里云账号accessSecret

请求示例

{
    "id": "1509086454180",
    "version": "1.0",
    "request": {
        "apiVer": "1.0.4"
    },
    "params": {
        "productKey": "您的产品Key",
        "deviceName": "您的设备名称",
        "ruleType": "ONS or DATAHUB",
        "configure": "参考如下:",
        "accessKeyId": "阿里云账号ak",
        "accessSecret": "阿里云账号secret"
    }
}

DataHub configure参数参考:

{
    "schemaVals": [
        {
            "name": "devicename",
            "value": "${items.devicename.value}",
            "type": "STRING"
        },
        {
            "name": "msgtime",
            "value": "${items.msgtime.value}",
            "type": "TIMESTAMP"
        }
    ],
    "role": {
        "roleArn": "acs:ram::31193008:role/aliyuniotaccessingdatahubrole",
        "roleName": "AliyunIOTAccessingDataHubRole",
        "roleId": "302701665740923801"
    },
    "projectName": "iot_datahub_stream",
    "topicName": "device_message",
    "regionName": "cn-hangzhou"
}

ONS configure参数参考:

{
    "topicName":"industry_ons_topic_demo_2",
    "regionId":"cn-qingdao-publictest"
}
private static ApiRequest buildRequest() throws UnsupportedEncodingException {
        String host = "api.link.aliyun.com";
        String path = "/industry/ruleAction/create";

        JSONObject request = new JSONObject();
        //api版本,必填
        request.put("apiVer", "1.0.4");

        JSONObject params = new JSONObject();
        // api入参
        params.put("productKey", "a1k3yOhhxRW");
        // api入参
        params.put("deviceName", "yMYkJtkj201J28FajvdT");
        params.put("ruleType", "ONS");
        params.put("accessKeyId", "aS4MT0IYrPSPxxxx");
        params.put("accessSecret", "QapYKAdhfa12R0r7SYboxxxx");

        Map<String, String> configMap = Maps.newHashMap();
        configMap.put("topicName", "iotx-lora-test");
        configMap.put("regionId", "mq-internet-access");
        params.put("configure", JSON.toJSONString(configMap));

        JSONObject requestBody = new JSONObject();
        //请求唯一标识,必填
        requestBody.put("id", System.currentTimeMillis());
        //协议版本,固定值1.0
        requestBody.put("version", "1.0");
        //请求唯一标识,必填
        requestBody.put("request", request);
        //api入参结构体
        requestBody.put("params", params);


        System.out.println(requestBody.toJSONString());

        byte[] body = requestBody.toJSONString().getBytes("UTF-8");

        ApiRequest apiRequest = new ApiRequest(Scheme.HTTPS, Method.POST_BODY, host, path, body);
        apiRequest.getHeaders().put("accept", "application/json");

        return apiRequest;
    }

role信息

  • 授权角色信息。通过授予工业平台指定的系统服务角色,您可以授权访问您的DataHub。

  • 授权角色信息格式如下:

    {
      "roleArn": "acs:ram::31193008:role/aliyuniotaccessingdatahubrole",
      "roleName": "AliyunIOTAccessingDataHubRole",
      "roleId": "302701665740923801"
    }
    
  • 请将31193***替换成您的阿里云账号ID。您可以登录控制台,在 账号安全设置 页面查看您的账号ID。

  • AliyunIOTAccessingDataHubRole是访问控制中定义的服务角色。用于授予工业平台访问DataHub。关于该角色的更多信息,请在访问控制控制台的角色管理页面进行角色管理。

  • roleId可以设置任意一串数字。

正常返回示例

{
    "code": 200,
    "data": true,
    "id": "1537952007134"
}

修改设备数据云产品流转规则

定义描述

path 版本 描述
/industry/ruleAction/update 1.0.4 修改设备数据云产品转储规则

请求参数

名称
类型
必要
描述
productKey
String
产品Key
deviceName
String
设备名称
ruleType
String
规则类型,
ONS or DATAHUB
configure
String
​云产品配置参数
accessKeyId
String
阿里云账号accessKeyId
accessSecret
String
阿里云账号accessSecret

请求示例

{
    "id": "1509086454180",
    "version": "1.0",
    "request": {
        "apiVer": "1.0.4"
    },
    "params": {
        "productKey": "您的产品Key",
        "deviceName": "您的设备名称",
        "ruleType": "ONS or DATAHUB",
        "configure": "参考如下:",
        "accessKeyId": "阿里云账号ak",
        "accessSecret": "阿里云账号secret"
    }
}

DataHub configure参数参考:

{
    "schemaVals": [
        {
            "name": "devicename",
            "value": "${items.devicename.value}",
            "type": "STRING"
        },
        {
            "name": "msgtime",
            "value": "${items.msgtime.value}",
            "type": "TIMESTAMP"
        }
    ],
    "role": {
        "roleArn": "acs:ram::31193008:role/aliyuniotaccessingdatahubrole",
        "roleName": "AliyunIOTAccessingDataHubRole",
        "roleId": "302701665740923801"
    },
    "projectName": "iot_datahub_stream",
    "topicName": "device_message",
    "regionName": "cn-hangzhou"
}

ONS configure参数参考:

{
    "topicName":"industry_ons_topic_demo_2",
    "regionId":"cn-qingdao-publictest"
}
private static ApiRequest buildRequest() throws UnsupportedEncodingException {
        String host = "api.link.aliyun.com";
        String path = "/industry/ruleAction/update";

        JSONObject request = new JSONObject();
        //api版本,必填
        request.put("apiVer", "1.0.4");

        JSONObject params = new JSONObject();
        // api入参
        params.put("productKey", "a1k3yOhhxRW");
        // api入参
        params.put("deviceName", "yMYkJtkj201J28FajvdT");
        params.put("ruleType", "ONS");
        params.put("accessKeyId", "aS4MT0IYrPSxxxx");
        params.put("accessSecret", "QapYKAdhfa12R0r7SYboatVxxxx");

        Map<String, String> configMap = Maps.newHashMap();
        configMap.put("topicName", "lora_nms_pre_test");
        configMap.put("regionId", "mq-internet-access");
        params.put("configure", JSON.toJSONString(configMap));

        JSONObject requestBody = new JSONObject();
        //请求唯一标识,必填
        requestBody.put("id", System.currentTimeMillis());
        //协议版本,固定值1.0
        requestBody.put("version", "1.0");
        //请求唯一标识,必填
        requestBody.put("request", request);
        //api入参结构体
        requestBody.put("params", params);


        System.out.println(requestBody.toJSONString());

        byte[] body = requestBody.toJSONString().getBytes("UTF-8");

        ApiRequest apiRequest = new ApiRequest(Scheme.HTTPS, Method.POST_BODY, host, path, body);
        apiRequest.getHeaders().put("accept", "application/json");

        return apiRequest;
    }

role信息

  • 授权角色信息。通过授予工业平台指定的系统服务角色,您可以授权访问您的DataHub。

  • 授权角色信息格式如下:

    {
      "roleArn": "acs:ram::31193008:role/aliyuniotaccessingdatahubrole",
      "roleName": "AliyunIOTAccessingDataHubRole",
      "roleId": "302701665740923801"
    }
    
  • 请将31193***替换成您的阿里云账号ID。您可以登录控制台,在 账号安全设置 页面查看您的账号ID。

  • AliyunIOTAccessingDataHubRole是访问控制中定义的服务角色。用于授予工业平台访问DataHub。关于该角色的更多信息,请在访问控制控制台的角色管理页面进行角色管理

  • roleId可以设置任意一串数字。

正常返回示例

{
    "code": 200,
    "data": "",
    "id": "1537952619631"
}

查询设备数据云产品流转规则

定义描述

path 版本 描述
/industry/ruleAction/query 1.0.4 查询设备数据云产品转储规则

请求参数

名称
类型
必要
描述
productKey
String
产品Key
deviceName
String
设备名称
ruleType
String
规则类型,
ONS or DATAHUB

请求示例

private static ApiRequest buildRequest() throws UnsupportedEncodingException {
        String host = "api.link.aliyun.com";
        String path = "/industry/ruleAction/query";

        JSONObject request = new JSONObject();
        //api版本,必填
        request.put("apiVer", "1.0.4");

        JSONObject params = new JSONObject();
        // api入参
        params.put("productKey", "a1k3yOhhxRW");
        // api入参
        params.put("deviceName", "yMYkJtkj201J28FajvdT");
        params.put("ruleType", "ONS");

        JSONObject requestBody = new JSONObject();
        //请求唯一标识,必填
        requestBody.put("id", System.currentTimeMillis());
        //协议版本,固定值1.0
        requestBody.put("version", "1.0");
        //请求唯一标识,必填
        requestBody.put("request", request);
        //api入参结构体
        requestBody.put("params", params);


        System.out.println(requestBody.toJSONString());

        byte[] body = requestBody.toJSONString().getBytes("UTF-8");

        ApiRequest apiRequest = new ApiRequest(Scheme.HTTPS, Method.POST_BODY, host, path, body);
        apiRequest.getHeaders().put("accept", "application/json");

        return apiRequest;
    }

正常返回示例

{
    "code": 200,
    "data": {
        "ruleActionStarted": false,
        "configure": "{\"uid\":\"1371643086916874\",\"endPoint\":\"http://onsaddr-internal.aliyun.com:8080/rocketmq/nsaddr4client-internal\",\"regionName\":\"mq-internet-access\",\"topic\":\"lora_nms_pre_test\"}",
        "productKey": "a1k3yOhhxRW",
        "deviceName": "yMYkJtkj201J28FajvdT"
    },
    "id": "1537952727481"
}

启动 or 停止设备数据流转规则

定义描述

path 版本 描述
/industry/ruleAction/control 1.0.4 启动 or 停止设备数据流转规则

请求参数

名称
类型
必要
描述
productKey
String
产品Key
deviceName
String
设备名称
ruleType
String
规则类型,
ONS or DATAHUB
isRuleActionStarted
Boolean
​true or false
accessKeyId
String
阿里云账号accessKeyId
accessSecret
String
阿里云账号accessSecret

请求示例

 private static ApiRequest buildRequest() throws UnsupportedEncodingException {
        String host = "api.link.aliyun.com";
        String path = "/industry/ruleAction/control";

        JSONObject request = new JSONObject();
        //api版本,必填
        request.put("apiVer", "1.0.4");

        JSONObject params = new JSONObject();
        // api入参
        params.put("productKey", "a1k3yOhhxRW");
        // api入参
        params.put("deviceName", "yMYkJtkj201J28FajvdT");
        params.put("ruleType", "ONS");
        params.put("accessKeyId", "aS4MT0IYrPddddxxx");
        params.put("accessSecret", "QapYKAdhfa12R0r7SYboatxxxxxxx");
        params.put("isRuleActionStarted", true);

        JSONObject requestBody = new JSONObject();
        //请求唯一标识,必填
        requestBody.put("id", System.currentTimeMillis());
        //协议版本,固定值1.0
        requestBody.put("version", "1.0");
        //请求唯一标识,必填
        requestBody.put("request", request);
        //api入参结构体
        requestBody.put("params", params);


        System.out.println(requestBody.toJSONString());

        byte[] body = requestBody.toJSONString().getBytes("UTF-8");

        ApiRequest apiRequest = new ApiRequest(Scheme.HTTPS, Method.POST_BODY, host, path, body);
        apiRequest.getHeaders().put("accept", "application/json");

        return apiRequest;
    }

正常返回示例

{
    "code": 200,
    "data": "",
    "id": "1537952819909"
}

删除设备数据流转规则

定义描述

path 版本 描述
/industry/ruleAction/delete 1.0.4 删除设备数据流转规则

请求参数

名称
类型
必要
描述
productKey
String
产品Key
deviceName
String
设备名称
ruleType
String
规则类型,
ONS or DATAHUB
accessKeyId
String
阿里云账号accessKeyId
accessSecret
String
阿里云账号accessSecret

请求示例

 private static ApiRequest buildRequest() throws UnsupportedEncodingException {
        String host = "api.link.aliyun.com";
        String path = "/industry/ruleAction/delete";

        JSONObject request = new JSONObject();
        //api版本,必填
        request.put("apiVer", "1.0.4");

        JSONObject params = new JSONObject();
        // api入参
        params.put("productKey", "a1k3yOhhxRW");
        // api入参
        params.put("deviceName", "yMYkJtkj201J28FajvdT");
        params.put("ruleType", "ONS");
        params.put("accessKeyId", "aS4MT0IYrPSxxxxx");
        params.put("accessSecret", "QapYKAdhfa12R0r7SYboatV0xxxxxx");

        JSONObject requestBody = new JSONObject();
        //请求唯一标识,必填
        requestBody.put("id", System.currentTimeMillis());
        //协议版本,固定值1.0
        requestBody.put("version", "1.0");
        //请求唯一标识,必填
        requestBody.put("request", request);
        //api入参结构体
        requestBody.put("params", params);


        System.out.println(requestBody.toJSONString());

        byte[] body = requestBody.toJSONString().getBytes("UTF-8");

        ApiRequest apiRequest = new ApiRequest(Scheme.HTTPS, Method.POST_BODY, host, path, body);
        apiRequest.getHeaders().put("accept", "application/json");

        return apiRequest;
    }

正常返回示例

{
    "code": 200,
    "data": "",
    "id": "1537952819909"
}

创建http2云云消息流转规则

定义描述

path 版本 描述
/industry/http2/ruleAction/create 1.0.4 创建http2云云消息流转规则

请求参数

名称 类型 必要 描述
productKey String 产品Key
deviceName String 设备名称
appKey String 服务调用租户维度appKey
msgType Integer 0:不订阅任何消息,1:设备上报消息,2:设备状态变化通知,3:设备上报消息+设备状态变化通知

请求示例

private static ApiRequest buildRequest() throws UnsupportedEncodingException {
        String host = "api.link.aliyun.com";
        String path = "/industry/http2/ruleAction/create";

        JSONObject request = new JSONObject();
        //api版本,必填
        request.put("apiVer", "1.0.4");

        JSONObject params = new JSONObject();
        // api入参
        params.put("productKey", "a1k3yOhhxRW");
        // api入参
        params.put("deviceName", "yMYkJtkj201J28FajvdT");
        params.put("appKey", "24932295");
        params.put("msgType", 3);

        JSONObject requestBody = new JSONObject();
        //请求唯一标识,必填
        requestBody.put("id", System.currentTimeMillis());
        //协议版本,固定值1.0
        requestBody.put("version", "1.0");
        //请求唯一标识,必填
        requestBody.put("request", request);
        //api入参结构体
        requestBody.put("params", params);


        System.out.println(requestBody.toJSONString());

        byte[] body = requestBody.toJSONString().getBytes("UTF-8");

        ApiRequest apiRequest = new ApiRequest(Scheme.HTTPS, Method.POST_BODY, host, path, body);
        apiRequest.getHeaders().put("accept", "application/json");

        return apiRequest;
    }

正常返回示例

{
    "code": 200,
    "data": {
        "msgType": 3,
        "productKey": "a1k3yOhhxRW",
        "deviceName": "yMYkJtkj201J28FajvdT"
    },
    "id": "1537952281064"
}

查询http2云云消息流转规则

定义描述

path 版本 描述
/industry/http2/ruleAction/query 1.0.4 查询http2云云消息流转规则

请求参数

名称 类型 必要 描述
productKey String 产品Key
deviceName String 设备名称

请求示例

private static ApiRequest buildRequest() throws UnsupportedEncodingException {
        String host = "api.link.aliyun.com";
        String path = "/industry/http2/ruleAction/query";

        JSONObject request = new JSONObject();
        //api版本,必填
        request.put("apiVer", "1.0.4");

        JSONObject params = new JSONObject();
        // api入参
        params.put("productKey", "a1k3yOhhxRW");
        // api入参
        params.put("deviceName", "yMYkJtkj201J28FajvdT");

        JSONObject requestBody = new JSONObject();
        //请求唯一标识,必填
        requestBody.put("id", System.currentTimeMillis());
        //协议版本,固定值1.0
        requestBody.put("version", "1.0");
        //请求唯一标识,必填
        requestBody.put("request", request);
        //api入参结构体
        requestBody.put("params", params);


        System.out.println(requestBody.toJSONString());

        byte[] body = requestBody.toJSONString().getBytes("UTF-8");

        ApiRequest apiRequest = new ApiRequest(Scheme.HTTPS, Method.POST_BODY, host, path, body);
        apiRequest.getHeaders().put("accept", "application/json");

        return apiRequest;
    }

正常返回示例

{
    "code": 200,
    "data": {
        "msgType": 3,
        "productKey": "a1k3yOhhxRW",
        "deviceName": "yMYkJtkj201J28FajvdT"
    },
    "id": "1537952447866"
}

results matching ""

    No results matching ""