1

I am new to Xively. Now I am trying to access the datapoints history from the feed that I get. From this documentation: http://xively.github.io/xively-js/docs/ It seems that I can use the method xively.datapoint.history(feedID, datastreamID, options{}, callback(data)) but I don't know how to use it.

I know the parameter feedID, datastreamID, but I am not sure about the options... from Xively site https://xively.com/dev/docs/api/quick_reference/historical_data/, I think I should put start and end parameter. I used feed id:40053 and datastream id:airpressure. You can try to input the feed id here to get more info about it:http://xively.github.io/xively-js/demo/

I tried the code below but its not working. Am I doing something wrong, or the datapoints history itself is restricted and cant be accessed?

// Make sure the document is ready to be handled
$(document).ready(function($) {

  // Set the Xively API key (https://xively.com/users/YOUR_USERNAME/keys)
  xively.setKey("yWYxyi3HpdqFCBtKHueTvOGoGROSAKxGRFAyQWk5d3JNdz0g"  );

  // Replace with your own values
  var feedID        = 40053;          
   var   datastreamID  = "airpressure";       // Datastream ID

  // Get datastream data from Xively
  xively.datapoint.history(feedID, datastreamID,
  {
   start:"2013-09-10T00:00:00.703576Z",
   end:"2013-10-10T00:00:00.703576Z"
  },
  function(data){
  //data.forEach(function(datapoints){document.write(JSON.stringify(datapoints["value"], null, 4));});
 document.write(JSON.stringify(data, null, 4));
  });
});

4

3 回答 3

1

我没有正确阅读文档...每个查询的最长持续时间为 6 小时,因此将结束时间更改为“2013-09-10T06:00:00.703576Z”解决了我的问题。

于 2013-10-28T11:32:12.490 回答
1

您可以使用参数:duration,interval

xively.datapoint.history (feedID, datastreamID1, **{ duration: "14days", interval: "1000"}**,
    function(data){
        document.write(JSON.stringify(data, null, 4));
    }
);
于 2016-02-17T17:43:16.887 回答
0

阿尔维纳迪,没错。您可以做的另一件事是将间隔参数设置为大于 0 的值。这将降低数据点的密度,并且仅针对间隔中指定的秒数返回一个数据点。但是,这在尝试检索大量数据的平均值时很有用。

以下是解释可用间隔的 API 文档:https ://xively.com/dev/docs/api/quick_reference/historical_data/

专业提示:设置参数limit=1000以返回最大数量的结果,而不必对数据进行分页。

于 2013-11-01T18:48:47.857 回答