cosmxively

COSM feed receiving updates but graph is flatlined at zero


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?


Solution

  • 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.