[SOLVED] What is correct webhook format to send multiple data points of the same variable?


#1

Hi there!
I am using Particle devices connected through webhooks to Ubidots. I’d like to send more than one data point of the same variable in the same Particle.publish. What is the correct webhook format for this?

Example: If I send only one data point, this is what I have to send the value “3” of the variable “LOAD”:

at firmware: Particle.publish("LOAD","3",PRIVATE,NO_ACK);
the webhook is programmed as per the Ubidots tutorial using the Particle webhook builder creating a template reference like this (omitting the token):

{
    "event": "LOAD",
    "responseTopic": "{{PARTICLE_DEVICE_ID}}/hook-response/{{PARTICLE_EVENT_NAME}}",
    "url": "https://things.ubidots.com/api/v1.6/devices/{{PARTICLE_DEVICE_ID}}/?token=xxxx-xxxxx",
    "requestType": "POST",
    "noDefaults": true,
    "rejectUnauthorized": true,
    "form": {
        "LOAD": "{{PARTICLE_EVENT_VALUE}}"
    },
    "errors": []
}

To send 2 or more values of the same variable, I put the values in an array and then use the Particle.Publish at firmware level like this:

Particle.publish("LOAD", String::format("%d,%d", LOAD[0],LOAD[1]));

Monitoring the above Publish in the Particle console, I see something like this (omitting the core id digits):

{"data":"1,2","ttl":60,"published_at":"2018-04-10T13:34:22.126Z","coreid":"xxxxxxxxx", "name": "LOAD"}

If I send 2 data points of the same variable, I’d like to receive and store in Ubidots 2 entries.

Thanks for the help


#2

Dear @fabioenriquez,

The Webhook Particle feature offers more options to build your request, not just the one provided in the Ubidots initial guides. For this reason, I highly recommend you to refer to the Particle Webhook official documentation, where you can find all the options available to build your Webhook specialized for the needs of your IoT solution.

Also, after read a little bit I found the following topics that can help structure the payload to be sent:

In this case, using the JSON format instead of Form will be friendly to build the payload desired. To give you a better idea, to send more than one value to the same variable you have to send the values with different timestamps following the structure below:

{"temperature": [{"value": 11, "timestamp":1523523600000}, {"value": 12, "timestamp":1523523900000}]}

For more information about you can see the Ubidots REST API Reference.

From another hand, if you desire to keep the structure that you already which provides the following answer, you can use Ubidots Parser, which let you receive and parse the data incoming (message below) to be publish them at Ubidots:

{"data":"1,2","ttl":60,"published_at":"2018-04-10T13:34:22.126Z","coreid":"xxxxxxxxx", "name": "LOAD"}

I hope this would help you!

All the best,
Maria C.