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));
  });
});

3 Answers3

1

I didn't read the documentation right... The maximal duration for each query is 6 hrs, so changing the end time to "2013-09-10T06:00:00.703576Z solved my problem.

1

You can use parameters: duration, interval

xively.datapoint.history (feedID, datastreamID1, **{ duration: "14days", interval: "1000"}**,
    function(data){
        document.write(JSON.stringify(data, null, 4));
    }
);
Zippy
  • 1,804
  • 5
  • 27
  • 36
0

Alvinadi, That's correct. The other thing you could do is set the interval parameter to something greater than 0. This will reduce the density of datapoints and only return one datapoint for every number of seconds specified in the interval. However, this can be useful when trying to retrieve the average of large amounts of data.

Here is the API documentation explaining the available intervals: https://xively.com/dev/docs/api/quick_reference/historical_data/

Pro tip: Set the parameter limit=1000 to return the maximum number of results and not have to paginate through data.

calumb
  • 1,051
  • 2
  • 10
  • 24