物接入IoT Hub

    修改带TSDB格式的规则

    方法 API 说明
    PUT /v3/iot/rules/device/{deviceName}/format 修改单个规则

    请求参数

    参数名 参数类型 是否必须 说明 示例
    name String 可选 规则名称 过滤传感器温度过高消息的规则
    sources List<DeviceRuleSource> 可选 需要存储的数据的属性和其条件
    destinations List<DeviceRuleDestination> 可选 处理后的消息写往的目的地数组(TSDB, KAFKA,另一个MQTT主题)
    目前只支持TSDB
    format DeviceRuleFormat 可选 转存TSDB数据的格式定义 { "mode": "field","metric": "newMetricName"}

    返回参数

    DeviceFormatRuleResponse

    请求示例

    PUT /v3/iot/rules/device/myDeviceName/format HTTP/1.1
    Host: iotdm.gz.baidubce.com
    Authorization:{authorization}
    Content-Type: application/json; charset=utf-8
     
    // 全修改
    {
        "name": "device xxxx to TSDB yyyy",
        "sources": [{
            "description": "",
            "name": "name",
            "type": "string",
            "condition": "<>",
            "value": "bbbbb"
        }, {
            "description": "This is condition 2",
            "name": "temperature",
            "type": "number",
            "condition": "<=",
            "value": "100000"
        }],
        "destinations": [
            {
                "value": "TSDB_NAME", // e.g. test.tsdb.iot.gz.baidubce.com
                "kind": "TSDB"
            }
        ],
        "format" : {
            "mode" : "field",
            "metric" : "newMetricName",
            "tags" : {
                "tag1" : "aaa"
            }
        }
    }
      
    // 只修改名字
    {
        "name": "cccc"  // 亦可为空
    }
    {
        "name": "cccc",
        "sources": []   // 亦可为空
    }
      
    // 只修改 sources
    {
        "sources": [{
            "description": "",
            "name": "name",
            "type": "string",
            "condition": "<>",
            "value": "bbbbb"
        }, {
            "description": "This is condition 2",
            "name": "temperature",
            "type": "number",
            "condition": "<=",
            "value": "100000"
        }]
    }
      
    // 只修改 destinations
    {
         
        "destinations": [
            {
                "value": "TSDB_NAME",  // e.g. test.tsdb.iot.gz.baidubce.com
                "kind": "TSDB"
            }
        ]
    }
     
    // 只修改 format
    {
        "format" : {
            "mode" : "field",
            "metric" : "newMetricName",
            "tags" : {
                "tag1" : "aaa"
            }
        }
    }

    返回示例

    HTTP/1.1 200 OK
    Content-Type: application/json; charset=utf-8
    x-bce-request-id: 993ff7e9-018b-4246-a7ba-5dddac970054
     
    {
        "id": "63d92c1de2bd46e0b257c6df67b4a7e9",
        "deviceName": "myDeviceName",
        "name": "device xxxx to TSDB yyyy",
        "sources": [{
            "description": "This is condition 1"
            "name": "name",
            "type": "string",
            "displayName": "名字",
            "unit": "count",
            "defaultValue": "0",
            "condition": "<>",
            "value": "aaa",
            "lastSaveTime": 0
        }, {
            "description": "This is condition 2",
            "name": "temperature",
            "type": "number",
            "displayName": "数量",
            "unit": "piece",
            "defaultValue": "1",
            "condition": ">=",
            "value": "20",
            "lastSaveTime": 1494904250
        }, {
            "description": "This is condition 3",
            "name": "speed",
            "type": "number",
            "displayName": "速度",
            "unit": "km/s",
            "defaultValue": "60",
            "condition": ">",
            "value": "0",
            "lastSaveTime": 1494904250
        }, {  // 这个规则是来自Schema里的新的属性,用户在之前的规则建立的时候并没有创建对应的规则。 如果创建的规则在Schema里没有对应的属性,则那条规则不会显示
            "description": "",
            "name": "temp",
            "type": "number",
            "displayName": "温度",
            "unit": "c",
            "defaultValue": "36",
            "condition": "",
            "value": "",
            "lastSaveTime": 0
     
        }],
        "destinations": [
            {
                "uuid": "6653da99bf9a4e35ba4f997e000a699f",
                "value": "test.tsdb.iot.gz.baidubce.com",
                "kind": "TSDB"
            }
        ],
        "format" : {
            "mode" : "field",
            "metric" : "newMetricName",
            "tags" : {
                "tag1" : "aaa"
            }
        },
        "enable": true,
        "createTime": 1494904250,
        "updateTime": 1494904250
    }
    上一篇
    获取带TSDB格式的规则详情
    下一篇
    参数定义