Use Unix timestamp long integer - Webhook

Hi, Particle community, I’m start with Webhooks few days ago.
I try to use thingboards.org for dashboard and visual data,I install a Community version in aws server 1G RAM and 40G ssd, five bucks a month, looks great!
I use the follow code in my Electron:

char data[256];
t = Time.now(); //Unix Format
snprintf(data, sizeof(data), "{\"rain\":%i,\"battery\":%i,\"temp\":%i,\"time\":%ld}",pulses, stateOfCharge, temperatureC,t);
Particle.publish("telemetry",data, PRIVATE);

I want to send data to thingsboards with the particle timestamp, this json format :

{"ts":1451649600512, "values":{"key1":"value1", "key2":"value2"}}

is required, look at Unix Timestamp “ts”.
I configure this json webhook :

{
  "ts": "{{time}}",
  "values": {
    "Webhook": "{{{PARTICLE_EVENT_NAME}}}",
    "rain": "{{rain}}",
    "Bateria": "{{battery}}",
    "Temperatura": "{{temp}}",
    "Time": "{{time}}",
    "Published": "{{PARTICLE_PUBLISHED_AT}}"
  }
}

if I replace the "{{time}}" for a unix timestamp, "ts":1451649600512, whitout quotes, all is ok.
Is posible using the json webhook with integers?
thanks in advance
I spend all the day looking for answer :(((

This code will not compile for several reasons. Maybe a formatting issue with the message board. Could you repost your code and include it in code tags? i.e. the </> icon above.

Hi picsil, thank you for your fast response, the particle code compile without any problems.
The issue is in the webhook jason I can’t use “ts”:"{{time}}" whitout quotes “ts”:{{time}}.
if I change {{time}} directly for valid timestamp 1451649600512 , all works good.
If not, thingsboard reject the value, I figure the thingsboard service wait for a number not string.
I need a tip or workaround to “pass” the published timestamp in my case the variable t to json whitout quotes.

{
"ts": "{{time}}",  
"values": {
"Webhook": "{{{PARTICLE_EVENT_NAME}}}",
"rain": "{{rain}}",
"Bateria": "{{battery}}",
"Temperatura": "{{temp}}",
"Time": "{{time}}",
"Published": "{{PARTICLE_PUBLISHED_AT}}"
}
}

Any help will be very appreciated!
Thanks in advance

Hi there,finaly I found the error :((( the thingsboard.org “ts” timestamp variable have milisecond presicion, particle Time.now() just seconds.
I solve the issue adding three zeros in the snprintf command:
snprintf(data, sizeof(data), “{“rain”:%i,“battery”:%i,“temp”:%i,“time”:%ld%s}”,pulses, stateOfCharge, temperatureC,t,“000”);
Webhook and json …not guilty :slightly_smiling_face:

You can actually put the tripple zeros into the format string instead of adding it as a “substring”

snprintf(data, sizeof(data)
        , "{\"rain\":%i,\"battery\":%i,\"temp\":%i,\"time\":%ld000}"
        , pulses
        , stateOfCharge
        , temperatureC
        , t);
1 Like

I see that I misread the code earlier. Formatting made it difficult. Glad you solved your problem.