Webhooks and arrays

Hi again

Following on from my attempt at using webhooks with Lambdas (which I don’t believe will work) I have created an array of timestamped data in my electron and published it.

I have some additional questions.

  1. Why do the square brakcets and quotes disappear from my array data.
  2. what is the maximum length of the data field, so I know how many records I can post.

I’ll explan below,

I want to post this data using a webhook

{
  "key": "blah-blah",
  "tag": "SomeUniqueNameOrID",
  "units": "m³/hr",
  "description": "Description of the source if available",
  "values": [
    [ "2016-07-25T12:00:00Z", 0.0 ],
    [ "2016-07-25T13:00:00Z", 0.1 ],
    [ "2016-07-25T14:00:00Z", 0.2 ],
    [ "2016-07-25T15:00:00Z", 0.3 ],
    [ "2016-07-25T16:00:00Z", 0.4 ],
    [ "2016-07-25T17:00:00Z", 0.5 ],
    [ "2016-07-25T18:00:00Z", 0.6 ],
    [ "2016-07-25T19:00:00Z", 0.7 ],
    [ "2016-07-25T20:00:00Z", 0.8 ],
    [ "2016-07-25T21:00:00Z", 0.9 ],
    [ "2016-07-25T22:00:00Z", 1.0 ],
    [ "2016-07-25T23:00:00Z", 1.1 ],
    [ "2016-07-26T00:00:00Z", 1.2 ],
    [ "2016-07-26T11:00:00Z", 1.3 ]
  ]
}

here is my web hook.
{
“event”: “multi_post”,
“url”: “https://requestb.in/19hvwv61”,
“requestType”: “POST”,
“noDefaults”: “Yes”,
“body”:"{“key”: “blah-blah”, “tag”: “{{t}}”, “units”: “pulses”, “description”: “Meter {{t}}”,“values”:"{{{v}}}"}"
}

here is the publish from the electron (via a printf on the serial port)

log JSON is -> {"t":"test_meter","v":[["2017-06-12T03:54:50Z",0],["2017-06-12T03:54:51Z",0],["2017-06-12T03:54:52Z",0],["2017-06-12T03:54:53Z",0],["2017-06-12T03:06:33Z",0],["2017-06-12T03:06:34Z",0],["2017-06-12T03:06:35Z",0]]}

here is the event from the particle console
{
“name”: “multi_post”,
“data”: “{“t”:“test_meter”,“v”:[[“2017-06-12T03:54:50Z”,0],[“2017-06-12T03:54:51Z”,0],[“2017-06-12T03:54:52Z”,0],[“2017-06-12T03:54:53Z”,0],[“2017-06-12T03:06:33Z”,0],[“2017-06-12T03:06:34Z”,0],[“2017-06-12T03:06:35Z”,0]]}”,
“ttl”: 60,
“published_at”: “2017-06-12T03:54:54.843Z”,
“coreid”: “12234545432523453245” <—I edited this not sure if it is secret or not
}

and here is the post at Requestb.in
{"key": "blah-blah", "tag": "test_meter", "units": "pulses", "description": "Meter test_meter","values":"2017-06-12T03:54:50Z,0,2017-06-12T03:54:51Z,0,2017-06-12T03:54:52Z,0,2017-06-12T03:54:53Z,0,2017-06-12T03:06:33Z,0,2017-06-12T03:06:34Z,0,2017-06-12T03:06:35Z,0"}

As you can see it is really close to being correct but the square brackets and the quotes around the time have all disappeared. I did add an extra set of curly brackets to make a triple set around the array and also a set of quotes around the whole array, the extra quotes appear but are not wanted.

Any ideas?
Thanks
Marshall

This would be answered here
https://docs.particle.io/reference/firmware/photon/#particle-publish-

That’s great thanks,

I’ve broken it down to it’s smallest elements. using the tool here.
http://rickkas7.github.io/mustache/

in the top box - enter JSON to parse
{"t":"test_meter","v":[["marshall",2],["james",3]]}

In the second box
{{t}},{{{v}}}

Prcoessed result is
test_meter,marshall,2,james,3

what I was hoping for was
test_meter,[["marshall",2],["james",3]]

Any thoughts on where the square brackets are disappearing to? I’ve looked everywhere on how to keep them,

I was really just hoping to pass a more or less preformatted JSON string straight through the webhook, with out it messing with the data on the way through.

Thanks Marshall

OK - I think I have it - after reading the documentation a bit better I had to change my approach, I couldn’t just have a preformatted JSON string from the Electron passed straight through to my server. I have to have a super complicated mustache script to un ravel my array (of objects now)
as follows.

Still using the tool here http://rickkas7.github.io/mustache/ - I have to code the strings in the electron yet, but that will be easier than this !

first text box - this is how I will format it on the electron.
{"t":"meter name", "v": [ { "a":"marshall", "b":1 }, { "a":"james", "b":2 } ] }

second text box
"{{t}}", [{{#v}}["{{a}}",{{b}}],{{/v}}["{{v.0.a}}",{{v.0.b}}]]

Result
"meter name", [["marshall",1],["james",2],["marshall",1]]

The repeat of the last field is to get rid of the trailing comma - due thanks to wherever I read this. My application doesn’t care if the data is repeated.

YAY, I have it in the format that I want, Now to make it all work.

Regards
Marshall

Did you succeed? I really dislike this mustache business…

The mustache stuff is horrible, I got it working as above, but ditched the whole approach in the end, and just published to my own server where I can parse whatever I want.