Cosm (originally Pachube) has now left Beta and been rebranded (again) as Xively. In the process they have removed some of the functionality on their front page which allowed you to view the data you were sending to them. I presume this is to encourage others to write applications for their API. So, to enable access to my own environmental data that I log to Xively from my Freetronics Etherten I wrote a quick sketch in Processing to format an html file showing the four main plots of my data. All you have to do is enter your feed ID and the names of your datastreams and it will write the appropriate file for you.
I wanted to write this in Javascript so that I could incorporate the code into the html but I’m still working that out so this is a stop-gap solution for now which still lets me see my data nad easily change things like the range of data requested.
// Xively html file writer.
// Chris Pook
// May 2013
// This sketch writes a text file with current links to Xively .png plots from your feed
// set up the file to output to
PrintWriter output;
String folderPath = “”; // enter the path to the folder where you want the html file to be saved
String file = folderPath + “” + “Xively .png feed.html”; // name of the text file to save to
int write = 1; // if you want to write to file set this to one, if you just want to debug the output in the terminal set it to zero
output = createWriter(file);
println(file);
// feed ID
String feedID = “”; // put your feed ID here between the quotation marks
// duration
// set this to the appropriate variable from the array ‘duration’, below
int e = 3;
String[] duration = {“60minutes”, “6hours”, “24hours”, “5days”, “30days”}; // five time scale options. Specify which on the line above
String[] interval = {“0”, “0”, “60”, “300”, “1800”}; // the relevant resolution of data to request, relates to the duration
String[] datastream = {“light”, “DSt”, “DHTh”, “BMPp”}; // enter your datastreams here, I have four but you can use as many as you like
String[] title = {“light”, “temp”, “humidity”, “pressure”}; // these are the titles for each .png plot, doesn’t seem to work currently, not sure why
String[] colour = {“000000”, “ff4f00”, “008a00”, “00ABA9”}; // you can edit the colou rof each datastream
// some variables if()s for assembling properly formatted time stamps
String mnth;
String dy;
String hr;
String mns;
String scs;
int range;
String URL;
if(month() < 10) { mnth = “0” + str(month());}
else {mnth = str(month());}
if(day() < 10) {dy = “0” + str(day());}
else {dy = str(day());}
if(hour() < 10) {hr = “0” + str(hour());}
else {hr = str(hour());}
if(minute() < 10) {mns = “0” + str(minute());}
else {mns = str(minute());}
if(second() < 10) {scs = “0” + str(second());}
else {scs = str(second());}
// assembling the timestamp
String now = year() + “-” + mnth + “-” + dy + “T” + hr + “:” + mns + “:” + scs + “+12”;
println(now); // output the timestamp to terminal for debugging purposes
// writing the URLs
for(int i=0; i < 4; i++) { // this writes four different datastreams because that’s how many I want, edit your appropriately
URL = “https://api.xively.com/v2/feeds/” + feedID + “/datastreams/” + datastream[i] + “.png?” + “duration=” + duration[e] + “&s=1&b=true&g=true&scale=Datastream&w=1000&h=299&c=” + colour[i] + “&t=”” + title[i] + “””;
println(URL); // output to terminal
if(write > 0) { // if we’re not debugging output the URLs to file
output.print(“<IMG SRC=””);
output.print(URL);
output.println(“” WIDTH=1000 HEIGHT=299>”);
}
}
output.flush();
output.close();
exit();