Hi
Im using the switch to turn some relays on and off. Everything is working except for the response on my particle webhook event logs. Is this correct for the switch widget?
HTTP/1.1 400 Bad Request
Server: nginx
Date: Mon, 13 Apr 2020 12:04:22 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Allow: GET, POST, HEAD, OPTIONS
Vary: Origin, Cookie
{“detail”: “The payload 1 is not a valid json document.”}
Hi there @Melt777, a 400 response code error means that you are attempting to send a non-valid JSON. From the detail message, your payload has a non valid character, probably a NaN or Null value, please check your payload structure (maybe you are sendind a null value from your firmware?).
All the best
That what I would have thought Jose, but this is your sample switch widget code
I have created new tokens on both particle and ubidots. I have also created a new trigger.
The payload is indeed not correct
The led does switch on and off.
Under ubidot devices I keep getting this ‘api device’ that shows up. It was not created by me.
Hi @Melt777,
I hope all is well,
Can you please share with us an image of the Payload you are sending so we can identify the error? Additionally, I will take a look at the device “api device” to detect where this device is coming from, to this, can you please let me know your account username?
All the best,
-Isabel
HI @isalogi . Thanks for the reply. From what I see there is no proper payload sent back. the switch widget just returns a 0 or a 1 and from the webhook all that is sent is “1” or " ". thats why I thought the 400 response is probably correct. Below is an screenshot of two triggers im using one is from my one hook (working) and the other from the switch widget (also working but 400 response.
If its normal then no problem was just wondering why its returning the “1” and “0” to ubidots and not keeping it local. I presume this is also what is creating the API under “my devices”
float setControl(float value) {
if (value == 3) {
return 3;
}
if (value == 1) {
return 1;
}
return 2;
}
void myHandler(const char *event, const char *data) {
// Handle the integration response
i++;
Serial.println(i);
Serial.print(event);
Serial.print(", data: ");
if (data) {
// Serial.println(data);
shuttercontrol = setControl(atof(data));
Serial.printf("%f\n",shuttercontrol);
} else {
Serial.println("NULL");
}
}
username CRS if you want to have a look.
thank you
@dsr As requested it seems that the switch widget and sliders are returning their values “1” or what ever it may be back to ubidots via the webhook resulting in a 400 response due to be incorrect payload. I just wanted to now if this is correct.
thanks