Hi,
I got my project working, but I am trying to streamline it a little bit and leverage some of the additional features offered by Particle Cloud, primarily webhooks, to post data to ubidots.
I have created the following webhook, based on Ubidots documentation:
{
"event": "Ubidots",
"url": "https://industrial.api.ubidots.com/api/v1.6/devices/{{{PARTICLE_DEVICE_ID}}}",
"requestType": "POST",
"noDefaults": false,
"rejectUnauthorized": true,
"headers": {
"X-Auth-Token": "XXXXXX",
"Content-Type": "application/json"
},
"body": "{{{PARTICLE_EVENT_VALUE}}}"
}
And for the life of me, I can’t figure out why it is not working. I created the webhook and then clicked on “Test” and it gave me an error status 400 from industrial.api.ubidots.com
.
In my application if, instead of using UBI_PARTICLE
when defining my ubidots
, I use UBI_HTTP
, my code works perfectly fine.
Here is my simple code to test it:
#include <Ubidots.h>
Ubidots ubidots("webhook", UBI_PARTICLE);
void setup() {
// Put initialization like pinMode and begin functions here.
Serial.begin(9600);
Particle.subscribe("hook-response/Ubidots", ubidotsHandler, MY_DEVICES);
ubidots.setDebug(true);
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
delay(10000);
Serial.println("main: Starting loop");
// The core of your code will likely live here.
Serial.println("main: posting data to ubidots");
ubidots.add("sensor-0", 12345);
ubidots.add("sensor-1", 67890);
bool bufferSent = false;
bufferSent = ubidots.send("Ubidots", PUBLIC);
if(bufferSent) {
Serial.println("main: data sent correctly to ubidots");
}
delay(30000);
}
void ubidotsHandler(const char *event, const char *data) {
Serial.printlnf("ubidotsHandler: data = %s", data);
if(!data) {
Particle.publish("ubidotsResp", "No data");
return;
}
int respCode = atoi(data);
if((respCode == 200 || respCode == 201)) {
Particle.publish("ubidotsHook", "Success");
} else {
Particle.publish("ubidotsHook", data);
}
}
In my event log, I can see the hook-set/Ubidots
, but then followed by hook-error/Ubidots
.
Any idea where the issue is.
Thanks a lot in advance,
B.