loading data to keen.io through json from array in electric imp

43 views
Skip to first unread message

Kamalakannan Elangovan

unread,
Mar 7, 2015, 8:35:24 AM3/7/15
to keen-i...@googlegroups.com
Dear all,

I'm a newbie to Electricimp and keen.io. I'm working on a IOT project. we have sensor data that we want to upload to keen.io to electric imp. 

There are about 256 integer values we wanted to upload every one minute(which may vary). This data is sent as a array from the device to the agent. What we wanted to do was upload to the keen.io dynamically, if there are 1 to n variables we will send a log data like this {p1 = 40, p2 = 30, p3 = 60..pn = 70}. The keen io example that are existing is loading only a fixed couple of values like shown below

what i would like to know is how can i convert my array in to a data that can be uploaded to keen.io ?

So far i have attempted to concatenate as a string and tried sending it but didn't work. 

Code:
for (local i = 0 ; i < 10 ; i++)
{
roll = 1.0 * math.rand() / RAND_MAX
roll = (roll * 12) + 1
arry.insert(i, 78)
if (keyst)
keyst = format("%s,P%i:%i", keyst, i, roll)
else
keyst = format("P%i:%i", i, roll)
}

keyst = format ("[{%s}]", keyst)

keen.sendEvent("tempBugs", keyst, function(resp) {
server.log(resp.body);
Keen.IO data sent and response received:

015-03-07 18:39:23 UTC+5.5 [Agent] "[{P0:9,P1:3,P2:11,P3:8,P4:2,P5:1,P6:8,P7:2,P8:2,P9:5}]"
2015-03-07 18:39:23 UTC+5.5 [Agent] {"message": "An event should be a JSON object of properties.", "error_code": "InvalidEventError"}
I get the following error 

David Knaack

unread,
Mar 7, 2015, 11:19:15 AM3/7/15
to keen-i...@googlegroups.com
I'm not sure how you want your data to appear in Keen.io. You may want something like this:

{
    "P0":9,
    "P1":3,
    "P2":11,
    "P3":8,
    "P4":2,
    "P5":1,
    "P6":8,
    "P7":2,
    "P8":2,
    "P9":5
}    

This would give you an event with 10 different named properties that could be queried. This format would imply that the value P0 is a different kind of data than the value of P1.

If the values are all the same, such as if they were all readings from the same sensor and you are batching them together for transmission, you would probably not format them as above. Doing so would make it hard to build a visualization of the data.

In that case it would be best to send them as separate events:

{"P":9}
{"P":3}
etc.

Another option would be to send an array of values:

{ "P":[9,3,11, 8,2,1,8,2,2,5]}

If you want to tell us more about how you want the data to appear in your Keen.io collection I or someone else can give some more specific help about how to format it.

Reply all
Reply to author
Forward
0 new messages