Get Channel Feed Summaries

Overview

The Get Channel Feed Summaries API is used to read feed summaries from all the sensor fields in a channel. This method can return either a JSON or CSV object. Each feed summary record consists hourly sum total, average, number of records, standard deviation, maximum and minimum values of each individual field.

If you only need to access the latest readings from the channel, using the Get Channels API is recommended. It will return latest readings from all the channels in once. 

API URL

To return a JSON object:

https://webapi.ubibot.com/channels/CHANNEL_ID/summary.json?parameters

To return a CSV file:

https://webapi.ubibot.com/channels/CHANNEL_ID/summary.csv?parameters 

Where CHANNEL_ID is the ID of the target channel.

HTTP Method

GET

URL Parameters

Name Type Required Description
api_key or token_id String Required for private channels Specify the API write key or read key of the channel, or token_id obtained after the user logged in.
results Integer Optional Number of entries to retrieve. The maximum number is 8,000
start Datetime Optional Start date in format YYYY-MM-DD%20HH:NN:SS.
end Datetime Optional End date in format YYYY-MM-DD%20HH:NN:SS.
timezone String Optional Identifier from Time Zones Reference for this request.
callback String Optional Function name to be used for JSONP cross-domain requests.

 Response

An HTTP code of 200 is responded for each successful data requests. Body contains a JSON object with the feed summaries in the requested format. If is_truncated is presented in the response JSON and value is true, it means the result has been truncated because of the maximum number of entries for retrieving has been reached. You can change the start and end value to shrink the range.

Error: See the list of error codes for details.

Examples

GET https://webapi.ubibot.com/channels/123/summary?api_key=XXXXXXXXXXXXX

The response is a JSON object, for example:

{
 "result": "success",
 "server_time": "2019-02-07T13:13:15Z",
 "is_truncated": false,
 "start": "2019-02-07T02:00:00+00:00",
 "end": "2019-02-07T11:00:00+00:00",
 "timezone": "Europe/London",
 "num_records": 10,
 "results": 10,
 "channel": {
 "channel_id": "1419",
 "name": "C-1419",
 "field1": "Temperature",
 "field2": "Humidity",
 "field3": "Light",
 "field4": "Voltage",
 "field5": "WIFI RSSI",
 "field6": "Vibration Index",
 "field7": "Knocks",
 "field8": "External Temperature Probe",
 "field9": "Reed Sensor",
 "field10": null,
 "latitude": "41.7922",
 "longitude": "123.4328",
 "elevation": null,
 "created_at": "2018-12-07T03:15:40Z",
 "public_flag": "false",
 "user_id": "8D5F3ACB-87A5-4D80-AA5F-FC64E8647990",
 "last_entry_date": "2019-02-07T13:10:26Z",
 "last_entry_id": "50982",
 "vconfig": "{\"field1\":{\"h\":\"0\",\"u\":\"1\"},\"field2\":{\"h\":\"0\",\"u\":\"3\"},\"field3\":{\"h\":\"0\",\"u\":\"4\"},\"field4\":{\"h\":\"0\",\"u\":\"5\"},\"field5\":{\"h\":\"0\",\"u\":\"6\"},\"field6\":{\"h\":\"0\",\"u\":\"7\"},\"field7\":{\"h\":\"0\",\"u\":\"8\"},\"field8\":{\"h\":\"0\",\"u\":\"1\"},\"field9\":{\"h\":\"0\",\"u\":\"9\"}}",
 "full_dump": "0",
 "plan_code": "ubibot_free",
 "username": "cloudleader"
 },
 "feeds": [{
 "created_at": "2019-02-07T11:00:00+00:00",
 "field3": {
 "sum": 0.24,
 "avg": 0.06,
 "count": 4,
 "sd": 0,
 "max": 0.06,
 "min": 0.06
 },
 "field1": {
 "sum": 94.515136,
 "avg": 23.628784,
 "count": 4,
 "sd": 0.018257971122225,
 "max": 23.646141,
 "min": 23.603416
 },
 "field2": {
 "sum": 40,
 "avg": 10,
 "count": 4,
 "sd": 0,
 "max": 10,
 "min": 10
 },
 "field5": {
 "sum": -160,
 "avg": -40,
 "count": 4,
 "sd": 0,
 "max": -40,
 "min": -40
 }
 }, {
 "created_at": "2019-02-07T10:00:00+00:00",
 "field3": {
 "sum": 0.69,
 "avg": 0.062727272727273,
 "count": 11,
 "sd": 0.0044536177141512,
 "max": 0.07,
 "min": 0.06
 },
 "field1": {
 "sum": 260.85257,
 "avg": 23.71387,
 "count": 11,
 "sd": 0.035359001690453,
 "max": 23.803696,
 "min": 23.675514
 },
 "field2": {
 "sum": 110,
 "avg": 10,
 "count": 11,
 "sd": 0,
 "max": 10,
 "min": 10
 },
 "field5": {
 "sum": -487,
 "avg": -44.272727272727,
 "count": 11,
 "sd": 4.3294112362875,
 "max": -40,
 "min": -49
 },
 "field4": {
 "sum": 4.472982,
 "avg": 4.472982,
 "count": 1,
 "sd": 0,
 "max": 4.472982,
 "min": 4.472982
 }
 }, {
 "created_at": "2019-02-07T09:00:00+00:00",
 "field3": {
 "sum": 22.48,
 "avg": 11.24,
 "count": 2,
 "sd": 1.74,
 "max": 12.98,
 "min": 9.5
 },
 "field1": {
 "sum": 48.264282,
 "avg": 24.132141,
 "count": 2,
 "sd": 0.021362,
 "max": 24.153503,
 "min": 24.110779
 },
 "field2": {
 "sum": 20,
 "avg": 10,
 "count": 2,
 "sd": 0,
 "max": 10,
 "min": 10
 },
 "field5": {
 "sum": -80,
 "avg": -40,
 "count": 2,
 "sd": 0,
 "max": -40,
 "min": -40
 }
 }, {
 "created_at": "2019-02-07T08:00:00+00:00",
 "field3": {
 "sum": 457.879989,
 "avg": 38.15666575,
 "count": 12,
 "sd": 12.868984722494,
 "max": 57.32,
 "min": 16.779999
 },
 "field1": {
 "sum": 294.736777,
 "avg": 24.561398083333,
 "count": 12,
 "sd": 0.27719641719199,
 "max": 25.056076,
 "min": 24.209579
 },
 "field2": {
 "sum": 113,
 "avg": 9.4166666666667,
 "count": 12,
 "sd": 0.49300664859163,
 "max": 10,
 "min": 9
 },
 "field5": {
 "sum": -512,
 "avg": -42.666666666667,
 "count": 12,
 "sd": 4.0892813821284,
 "max": -40,
 "min": -51
 },
 "field4": {
 "sum": 4.475632,
 "avg": 4.475632,
 "count": 1,
 "sd": 0,
 "max": 4.475632,
 "min": 4.475632
 }
 }, {
 "created_at": "2019-02-07T07:00:00+00:00",
 "field3": {
 "sum": 200.879997,
 "avg": 100.4399985,
 "count": 2,
 "sd": 2.6000025,
 "max": 103.040001,
 "min": 97.839996
 },
 "field1": {
 "sum": 56.227211,
 "avg": 28.1136055,
 "count": 2,
 "sd": 0.2456705,
 "max": 28.359276,
 "min": 27.867935
 },
 "field2": {
 "sum": 16,
 "avg": 8,
 "count": 2,
 "sd": 0,
 "max": 8,
 "min": 8
 },
 "field5": {
 "sum": -90,
 "avg": -45,
 "count": 2,
 "sd": 4,
 "max": -41,
 "min": -49
 }
 }, {
 "created_at": "2019-02-07T06:00:00+00:00",
 "field3": {
 "sum": 31344.398927,
 "avg": 2612.0332439167,
 "count": 12,
 "sd": 2824.6816531297,
 "max": 7016.959961,
 "min": 116.199997
 },
 "field1": {
 "sum": 378.384835,
 "avg": 31.532069583333,
 "count": 12,
 "sd": 2.9701401037999,
 "max": 35.892273,
 "min": 26.377892
 },
 "field2": {
 "sum": 87,
 "avg": 7.25,
 "count": 12,
 "sd": 1.0103629710818,
 "max": 9,
 "min": 6
 },
 "field5": {
 "sum": -491,
 "avg": -40.916666666667,
 "count": 12,
 "sd": 0.27638539919628,
 "max": -40,
 "min": -41
 },
 "field4": {
 "sum": 4.487029,
 "avg": 4.487029,
 "count": 1,
 "sd": 0,
 "max": 4.487029,
 "min": 4.487029
 }
 }, {
 "created_at": "2019-02-07T05:00:00+00:00",
 "field3": {
 "sum": 197.159996,
 "avg": 98.579998,
 "count": 2,
 "sd": 1.579998,
 "max": 100.159996,
 "min": 97
 },
 "field1": {
 "sum": 46.082627,
 "avg": 23.0413135,
 "count": 2,
 "sd": 0.0146865,
 "max": 23.056,
 "min": 23.026627
 },
 "field2": {
 "sum": 20,
 "avg": 10,
 "count": 2,
 "sd": 0,
 "max": 10,
 "min": 10
 },
 "field5": {
 "sum": -89,
 "avg": -44.5,
 "count": 2,
 "sd": 4.5,
 "max": -40,
 "min": -49
 }
 }, {
 "created_at": "2019-02-07T04:00:00+00:00",
 "field3": {
 "sum": 1133.039978,
 "avg": 94.419998166667,
 "count": 12,
 "sd": 6.4416674668395,
 "max": 115.040001,
 "min": 89.68
 },
 "field1": {
 "sum": 277.075209,
 "avg": 23.08960075,
 "count": 12,
 "sd": 0.015318618498007,
 "max": 23.114746,
 "min": 23.069351
 },
 "field2": {
 "sum": 120,
 "avg": 10,
 "count": 12,
 "sd": 0,
 "max": 10,
 "min": 10
 },
 "field5": {
 "sum": -535,
 "avg": -44.583333333333,
 "count": 12,
 "sd": 5.3456888133232,
 "max": -40,
 "min": -52
 },
 "field4": {
 "sum": 4.469537,
 "avg": 4.469537,
 "count": 1,
 "sd": 0,
 "max": 4.469537,
 "min": 4.469537
 }
 }, {
 "created_at": "2019-02-07T03:00:00+00:00",
 "field3": {
 "sum": 153.099998,
 "avg": 76.549999,
 "count": 2,
 "sd": 0.549999,
 "max": 77.099998,
 "min": 76
 },
 "field1": {
 "sum": 46.242844,
 "avg": 23.121422,
 "count": 2,
 "sd": 0.0066760000000006,
 "max": 23.128098,
 "min": 23.114746
 },
 "field2": {
 "sum": 20,
 "avg": 10,
 "count": 2,
 "sd": 0,
 "max": 10,
 "min": 10
 },
 "field5": {
 "sum": -82,
 "avg": -41,
 "count": 2,
 "sd": 0,
 "max": -41,
 "min": -41
 }
 }, {
 "created_at": "2019-02-07T02:00:00+00:00",
 "field3": {
 "sum": 1153.739984,
 "avg": 96.144998666667,
 "count": 12,
 "sd": 50.714404305812,
 "max": 256.320007,
 "min": 73.059998
 },
 "field1": {
 "sum": 278.933775,
 "avg": 23.24448125,
 "count": 12,
 "sd": 0.069417701157708,
 "max": 23.352409,
 "min": 23.141449
 },
 "field2": {
 "sum": 122,
 "avg": 10.166666666667,
 "count": 12,
 "sd": 0.37267799624997,
 "max": 11,
 "min": 10
 },
 "field5": {
 "sum": -536,
 "avg": -44.666666666667,
 "count": 12,
 "sd": 7.3861732687201,
 "max": -40,
 "min": -66
 },
 "field4": {
 "sum": 4.497895,
 "avg": 4.497895,
 "count": 1,
 "sd": 0,
 "max": 4.497895,
 "min": 4.497895
 }
 }]
}

PHP Quickstarts

<?php
// +----------------------------------------------------------------------
// | UbiBot
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2019 https://www.ubibot.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: UbiBot <[email protected]>
// +----------------------------------------------------------------------
 
//----------------------------------
// Get Channel Summaries (Get Channel Summaries)
// To view a channel feed, send an HTTP GET replacing CHANNEL_ID with the ID of your channel
// https://webapi.ubibot.com/docs/
//----------------------------------
 
header('Content-type:text/html;charset=utf-8');
 
 
//yours channel read key, can be obtained from web console panel
$apikey = "xxxxxxxxx";
 

$channel_id = 'XXXXXX'; //channel ID of your device
$url = 'https://webapi.ubibot.com/channels/'.$channel_id.'/summary';

$params = array(
		"api_key" => $apikey,// (string) is Read or Write key for this specific channel (no key required for public channels) 
 		"results" => 30,//(integer) Number of entries to retrieve, 8000 max (optional)
// 		"start" => "",//(datetime) Start date in format YYYY-MM-DD%20HH:NN:SS (optional)
// 		"end" => "",//(datetime) End date in format YYYY-MM-DD%20HH:NN:SS (optional)
// 		"timezone" => "",//(string) Identifier from Time Zones Reference for this request (optional)
// 		"callback" => "",//(string) Function name to be used for JSONP cross-domain requests (optional)
);
$paramstring = http_build_query($params);
$content = getcurl($url,$paramstring);
$result = json_decode($content,true);

if($result){
    if($result['result']=='success'){
    	
    	$result['channel']['vconfig'] = json_decode($result['channel']['vconfig'],true);
    	//Filter channels that need to be displayed
    	$filter_fields = array('field1','field2','field3','field4','field5','field6','field7','field8','field9','field10');
    	//Sensor unit
    	$unit = array('temperature_celcius','temperature_feh','humidity','light_lux','voltage','WIFI_dbm','vibration','knocks','magnetic_switch','soil_absolute_moisture');
    	
    	$list = array();
    	foreach ($filter_fields as $value) {
    		$list[$value]['name'] = $result['channel'][$value];
    		
    		if (isset($result['channel']['vconfig'][$value])) {
    			$list[$value]['show'] = $result['channel']['vconfig'][$value]['h']?0:1;
    			$list[$value]['unit'] = $unit[$result['channel']['vconfig'][$value]['u']];
    		} else {
    			$list[$value]['show'] = 0;
    			$list[$value]['unit'] = null;
    		}
    	}
    	
    	foreach ($result['feeds'] as $value) {
    		
    		foreach ($value as $k => $val) {
    			$tmp = array();
    			if (in_array($k, $filter_fields)) {
    				$val['created_at'] = $value['created_at'];
    				$list[$k]['data'][] = $val;
    			}
    		}
    	}
    }else{
        echo $result['errorCode'].":".$result['desp'];
    }
}else{
    echo "failed";
}
//**************************************************
 
 
 
 
 
/**
 * @param  string $url
 * @param  string $params 
 * @param  int $ispost 
 * @return  string
 */
function getcurl($url,$params=false,$ispost=0){
    $httpInfo = array();
    $ch = curl_init();
 
    curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
    curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
    curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    if( $ispost )
    {
        curl_setopt( $ch , CURLOPT_POST , true );
        curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
        curl_setopt( $ch , CURLOPT_URL , $url );
    }
    else
    {
        if($params){
            curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
        }else{
            curl_setopt( $ch , CURLOPT_URL , $url);
        }
    }
    $response = curl_exec( $ch );
    if ($response === FALSE) {
        //echo "cURL Error: " . curl_error($ch);
        return false;
    }
    $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
    $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
    curl_close( $ch );
    return $response;
}

?>


<html>
<head>
<style type="text/css">
table
{
	border-collapse: collapse;
	border: none;
	width: 100%;
}
td,th
{
	border: solid #000 1px;
	text-align:center;
}
li{ display:inline}
</style>
</head>

<body>
<table>
<tr>
<th>KEY</th>
<th>Sensor name</th>
<th>Show</th>
<th>Unit</th>
<th>Summary Feeds</th>
</tr>
 	 	<?php foreach ($list as $key => $value) :?>
 	 		<tr>
 	 			<td><?php echo $key;?></td>
				<td><?php echo $value['name'];?></td>
				<td><?php echo $value['show']?'是':'否';?></td>
				<td><?php echo $value['unit'];?></td>
				<td style="text-align: left;">
				<?php if (empty($value['data'])) :?>
					No data
				<?php else :?>
					<?php foreach ($value['data'] as $val):?>
					<ul>
						<li>avg:<?php echo $val['avg'];?></li>
						<li style="margin-left:20px;">sum:<?php echo $val['sum'];?></li>
						<li style="margin-left:20px;">count:<?php echo $val['count'];?></li>
						<li style="margin-left:20px;">sd:<?php echo $val['sd'];?></li>
						<li style="margin-left:20px;">min:<?php echo $val['min'];?></li>
						<li style="margin-left:20px;">max:<?php echo $val['max'];?></li>
						<li style="margin-left:20px;">created_at:<?php echo $val['created_at'];?></li>
					</ul>
					<?php endforeach;?>
				<?php endif;?>
				</td>
 	 		</tr>
 	 	<?php endforeach;?>
 		</table>
 	 </body>
 </html>

Node JS

const http = require("http");
let channel_id = xxxx;
let url = 'http://webapi.ubibot.io/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 = "xxxxxxxxxxxxxxx"
channel_id = xxxxx;
url = "http://webapi.ubibot.io/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")