Saturday, 20 October 2012

A COSM(ic) Experience

The answer to my "what should I do with my on{X} measurements" came again from the internet of things Twitter feed.  The answer was COSM, an online system designed to allow all and sundry measurements to be uploaded, stored, graphed and shared.  COSM publish an API that can be used to add, remove and edit measurements.

Some simple on{X} code like this:


device.ajax(
      {
      url: 'http://api.cosm.com/v2/feeds/' + MyFeedID + '/datastreams/' + MyDataStream + '/datapoints.csv',
      type: 'POST',
      headers: {
        'X-ApiKey': MyAPIKey
        //'Content-Length': '30',
        //'Content-Type': 'text/csv',
        //'Accept': 'text/csv'
      },
      data: StringToSend
      //data: '2012-09-30T22:00:00.676045+01:00,66'
    }


...allows battery measurements to be uploaded.  Here MyFeedID, MyDataStream and MyAPIKey are variables that hold various things associated with my COSM account.  It's very easy to get an account, set up a feed (in my case my Android handset), a datastream (in this case battery) and a API key.  You then just post data to the API in the format shown on the penultimate line above.  It took a bit of tinkering to get right, (hence all the //comments I've not removed yet), but in the end was not too hard.

Doing this allows you to produce graphs like this:

Here we can see battery measurements that I take and upload every 15 mins.  So what does this tell me? 
  • When I charge my battery the battery % goes up (what a surprise!).
  • When I don't charge the battery the % goes down (wow!).
  • AC charging is quicker than USB charging.
  • With the handset idle it uses less battery than when active (e.g.on a call).
  • There's an interesting charging profile to be seen on the right of the chart.  As the battery charges it starts fast, then slows down (sort of exponentially) then the last ~20% jumps up somewhere between 2 15 minute intervals.  

Now to take more measurements and see if they are useful!