1

context:

My first project with COSM is recording datapoints from my electric meter. When I look at the graph of the feed, it's flatlined at zero even though the datapoints appear to be correctly received.

Any idea what's wrong, or things I should look for in order to debug it?

more info:

When I debug my feed, I see it receiving approximately eight API requests per minute expected.

Here's an instance of a received datapoint as viewed by COSM's 'debug feed' interface. Note in particular that the response is 200 [ok], and the request body has a sensible timestamp and a non-zero value:

200 POST /api/v2/feeds/129722/datastreams/1/datapoints 06-05-2013 | 08:16:54 +0000

Request Headers
Version HTTP/1.0
Host    api.cosm.com
X-Request-Start 1367828214422267
X-Apikey    <expunged>
Accept-Encoding gzip, deflate, compress
Accept  */*
User-Agent  python-requests/1.2.0 CPython/2.7.3 Linux/3.6.11+
Origin  

Request Body
{"at": "2013-05-06T08:16:57", "value": 164.0}

Response Headers
X-Request-Id    245ee3ca6bd99efd156bff2416404c33f4bb7f0f
Cache-Control   max-age=0
Content-Type    application/json; charset=utf-8
Content-Length  0

Response Body
[No Body]

update

Even though the docs specify that JSON is the default, I explicitly added a ".json" to the POST URL (/api/v2/feeds/129722/datastreams/1/datapoints.json) but that didn't appear to make any difference.

update 2

I enclosed the "value" value in strings, so the request body now reads (for example):

{"at": "2013-05-06T15:37:06", "value": "187.0"}

Still behaving the same: I see updates in the debug view, but only zeros are reported in the graph view.

update 3

I tried looking at the data using the API rather than the COSM-supplied graph. My guess is that the datapoints are not being stored for some reason (despite the 200 OK return status). If I put this URL in the web browser:

http://api.cosm.com/v2/feeds/129722.json?interval=0

I get this in response:

{"id":129722,
 "title":"Rainforest Automation RAVEn",
 "private":"false",
 "tags":["power"],
 "feed":"https://api.cosm.com/v2/feeds/129722.json",
 "status":"frozen",
 "updated":"2013-05-06T05:07:30.169344Z",
 "created":"2013-05-06T00:16:56.701456Z",
 "creator":"https://cosm.com/users/fearless_fool",
 "version":"1.0.0",
 "datastreams":[{"id":"1",
                 "current_value":"0",
                 "at":"2013-05-06T05:07:29.982986Z",
                 "max_value":"0.0",
                 "min_value":"0.0",
                 "unit":{"type":"derivedSI","symbol":"W","label":"watt"}}],
 "location":{"disposition":"fixed","exposure":"indoor","domain":"physical"}
}

Note that the status is listed as "frozen" (last update received > 15 minutes ago) despite the fact that the debug tool is showing seven or eight updates per minute. Where are my datapoints going?

lebreeze
  • 5,094
  • 26
  • 34
fearless_fool
  • 33,645
  • 23
  • 135
  • 217

2 Answers2

2

Resolved. As @Calum at cosm.com support kindly pointed out, I wasn't sending a properly formed request. I was sending the following JSON:

{"at": "2013-05-06T08:16:57", "value": 164.0}

when I should have be sending:

{
  "datapoints":[
    {"at": "2013-05-06T08:16:57", "value": 164.0}
  ]
}

Calum also points out that I could batch up several points at a time to cut down the number of transactions. I'll get to that, but for now, suffice it to say that fixing the body of the request made everything start working.

fearless_fool
  • 33,645
  • 23
  • 135
  • 217
  • Looks like this is in the [docs](http://cosm.com/docs/v2/datapoint/create.html)... – errordeveloper May 07 '13 at 07:55
  • As @errordeveloper pointed out, I should just be using the official [cosm-python module](https://github.com/cosm/cosm-python) on github. I agree -- that would have saved me some befuddlement! – fearless_fool May 07 '13 at 12:39
0

That sounds like a bug in the graphs, I have seen something very similar a few times.

I often use Cosm Feed Viewer Chrome extension, which displays the latest values in real-time using the WebSocket endpoint.

It should be not too hard to put together custom graphs with Rickshaw and CosmJS.

errordeveloper
  • 6,716
  • 6
  • 41
  • 54
  • For grins I installed the Cosm Feed Viewer. The viewer knows the name of the feed, but shows last update "about 10 hours ago", which is when I created the Datastream. It seems the Datapoints are taking effect somehow... – fearless_fool May 06 '13 at 15:18
  • @fearless_fool I can see you have update the post with more details, the version I have read did seem really like one of the graphs bugs, and you title _"...graph is flatlined at zero"_ does also suggest that. – errordeveloper May 07 '13 at 08:03
  • Agreed! When I first observed the problem, the only evidence I had was that the graph was flatlined. Given the available information at the time, your answer was good. – fearless_fool May 07 '13 at 12:35
  • @fearless_fool i should have posted that as comment :) – errordeveloper May 07 '13 at 17:42