I’m having difficulty getting my data over to Ubidots via JSON webhook. It seems that the string values in my JSON are causing the problem. I’m hoping someone can point out what I’m doing wrong.
My Photon’s Particle.publish()
function looks like this:
char data[256];
snprintf(data, sizeof(data), "{\"windSpeedMph\": %.2f, \"windSpeedKnots\": %.2f, \"windScale\": \"%s\", \"windDir\": \"%s\"}", windSpeedMph, windSpeedK, windScale, windDir);
Particle.publish("anemometer", data, PRIVATE);
Variables windSpeedMPH
and windSpeedKnots
are floats, while windScale
and windDir
are strings. The webhook I’ve built (in Particle Console) looks like this:
{
"speedMPH": "{{{windSpeedMph}}}",
"speedKnots": "{{{windSpeedKnots}}}",
"scale": "{{{windScale}}}",
"direction": "{{{windDir}}}"
}
This webhook response shows “400” errors for the two string values direction
and scale
:
{"speedknots":[{"status_code":204}],"direction":[{"status_code":400,"errors":{"value":["A valid number is required."]}}],"scale":[{"status_code":400,"errors":{"value":["A valid number is required."]}}],"speedmph":[{"status_code":204}]}
If I create a JSON webhook that sends just the two float values it gets through fine, but when I send all four values nothing gets through.
I’ve tried a webhook that has double brackets—instead of triple {{{ }}}
—for windScale
and windDir
but that doesn’t seem to fix the issue. What am I doing wrong? Thanks in advance for any help.