空间详情

功能描述

通过空间详情(View a Channel)接口可读取指定空间(Channel)的详细基础信息(metadata),包括最后一次的传感器数据值

请求地址

https://webapi.ubibot.cn/channels/CHANNEL_ID

请将CHANNEL_ID替换成空间编号。

请求方式

HTTP GET

请求参数

名称 类型 是否必须 描述
account_key String 根据空间权限决定 账户的account_key密钥

返回说明

  • 其中write_key可用于写入空间数据(Channel Feed)

返回中所包含空间常用数据字段:

数据字段 描述
public_flag 是否公开设备信息
usage 设备已使用存储空间
size_storage 套餐总存储空间
traffic_in 设备上传流量
traffic_out 设备下载流量
size_out 套餐流量上限
last_values 设备最新的传感器数值
last_entry_date 设备最后一次与平台同步的时间
last_ip 设备最后一次与平台同步时的IP地址
name 空间名称
channel_id 空间编号
field1, field2….field10 每个数据空间对应名称(传感器名)
net 0->离线,1->在线,2->未知,-1->手动上传
vconfig 每个数据空间对应的内容(含数值、单位等值),内容与传感器名相对应

调用示例

GET https://webapi.ubibot.cn/channels/CHANNEL_ID?account_key=xxxxx-xxxxx-xxxxx-xxxx
调用示例1
调用示例2

{“
 result”: ”success”,
 ”server_time”: ”2017 - 08 - 20 T10: 01: 54 Z”,
 ”channels”: [{“
 channel_id”: ”395″,
 ”field1″: ”\u6e29\ u5ea6″,
 ”field2″: ”\u6e7f\ u5ea6″,
 ”field3″: ”\u5149\ u7167″,
 ”field4″: ”\u7535\ u91cf”,
 ”field5″: ”\u4fe1\ u53f7\ u5f3a\ u5ea6″,
 ”field6″: ”\u52a0\ u901f\ u5ea6″,
 ”field7″: ”\u6572\ u51fb”,
 ”field8″: ”\u5916\ u63a5\ u6e29\ u5ea6″,
 ”field9″: ”\u95e8\ u78c1″,
 ”field10″: null,
 ”latitude”: null,
 ”longitude”: null,
 ”name”: ”\u8bbe\ u5907 395″,
 ”public_flag”: ”false”,
 ”tags”: null,
 ”url”: null,
 ”metadata”: ”{\”
 fn_th\”: 60,
 \”fn_light\”: 60,
 \”fn_mag\”: 0,
 \”fn_mag_int\”: 2,
 \”fn_acc_tap1\”: 0,
 \”fn_acc_tap2\”: 0,
 \”fn_acc_act\”: 0,
 \”fn_acc_min\”: 5,
 \”fn_bt\”: 0,
 \”fn_ext_t\”: 300,
 \”fn_battery\”: 3600,
 \”fn_dp\”: 600,
 \”cg_data_led\”: 1
 }”,
 ”description”: null,
 ”traffic_out”: ”0″,
 ”traffic_in”: ”0″,
 ”created_at”: ”2017 - 07 - 11 T03: 17: 44 Z”,
 ”updated_at”: ”2017 - 07 - 11 T03: 17: 44 Z”,
 ”usage”: ”549397″,
 ”last_entry_id”: ”15403″,
 ”last_entry_date”: ”2017 - 07 - 14 T06: 41: 27 Z”,
 ”product_id”: ”ubibot - ws1 - cn”,
 ”device_id”: ”4 b1fca94ad758faab349bbd7a01cf00ea39e8ba4″,
 ”channel_icon”: null,
 ”last_ip”: ”175.171 .43 .88″,
 ”attached_at”: ”2017 - 07 - 11 T03: 17: 44 Z”,
 ”firmware”: null,
 ”serial”: ”E57 ** * WS1″,
 ”size_out”: ”5368709120″,
 ”size_storage”: ”1073741824″,
 ”plan_code”: ”ubibot_1g”,
 ”plan_start”: ”2017 - 07 - 11 T03: 17: 44 Z”,
 ”plan_end”: null,
 ”bill_start”: ”2017 - 08 - 10 T03: 17: 44 Z”,
 ”bill_end”: ”2017 - 09 - 09 T03: 17: 44 Z”,
 ”last_values”: ”{\”
 field1\”: {\”
 value\”: 26.220337,
 \”created_at\”: 1500014464
 },
 \”field3\”: {\”
 value\”: 0.4,
 \”created_at\”: 1500014464
 },
 \”field4\”: {\”
 value\”: 2.901859,
 \”created_at\”: 1500013142
 },
 \”field2\”: {\”
 value\”: 57,
 \”created_at\”: 1500014464
 },
 \”field5\”: {\”
 value\”: -49,
 \”created_at\”: 1500014484
 },
 \”field9\”: {\”
 value\”: 1,
 \”created_at\”: 1499749687
 },
 \”field8\”: {\”
 value\”: 25.6875,
 \”created_at\”: 1500014396
 }
 }”,
 ”vconfig”: ””,
 ”net”: ”0″,
 ”c_icon_base”: null
 }]
 }

Node JS

const http = require("http");
let channel_id = xxxx;
let url = 'http://webapi.ubibot.cn/channels/' + channel_id + '/summary';
let data = {
    api_key: "xxxxxxxxxxxxxxxxxx",
    results: 30
    // ...
};
let querystring = require('querystring');
let content = querystring.stringify(data);

http.get(url + '?' + content, (resp) => {
    let data = '';
    resp.on('data', (chunk) => {
        data += chunk;
    });
    resp.on('end', () => {
        let json = JSON.parse(data);
        if (json.error_code == 'success') {
            console.log(json);
        } else {
            console.log(json["errorCode"] + ":" + json["desp"]);
        }
    });
}).on('error', (e) => {
    console.log('request api error');
});

Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import requests
from urllib.parse import urlencode

api_key = "xxxxxxxxxxxxxxxxxxxxxxxx"
channel_id = xxxx;
url = "http://webapi.ubibot.cn/channels/%s/summary" % (channel_id)
params = {
    "api_key": api_key,
    "results": 30,
    # ......
}
params = urlencode(params)
r = requests.get("%s?%s" % (url, params))
res = r.json()
if res:
    error_code = res["result"]
    if error_code == 'success':
        print(res)
    else:
        print("%s:%s" % (res["errorCode"], res["desp"]))
else:
    print("request api error")