Ubidots Community

Particle Integrations with Ubidots

I have a problem with integrating Ubidots to Particle, I followed the tutorial but I can’t get it to work, I’m getting an error:

“error status 400 from industrial.api.ubidots.com

Here is my integration example on Particle:

{
    "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": "MY_TOKEN",
        "Content-Type": "application/json"
    },
    "body": "{{{PARTICLE_EVENT_VALUE}}}"
}

and here is the sample of my Argon code:

long randNumber;

void setup()
{
  Particle.function("controlPnl", controlPnl);
  Particle.connect();
}

void loop()
{
}

int controlPnl(String command)
{
  if (command == "temperature")
  {
    randNumber = random(90);
    Particle.publish("ubidots", String(randNumber), PRIVATE);
  }
  return randNumber;
}

Please advise, thank you :stuck_out_tongue:

Okay, I found my mistake, payload had to be in JSON format so I got this to work with following code:

long randNumber;

void setup()
{
  Particle.function("controlPnl", controlPnl);
  Particle.connect();
}

void loop()
{
}

int controlPnl(String command)
{
  if (command == "temperature")
  {
    randNumber = random(90);

    // JSONWriter &beginArray();
    char buf[622];
    memset(buf, 0, sizeof(buf));
    JSONBufferWriter writer(buf, sizeof(buf) - 1);
    writer.beginObject();
    writer.name("temperature").value(randNumber);
    writer.endObject();

    Particle.publish("ubidots", String(buf), PRIVATE);
  }
  return randNumber;
}

Hello @codev3rt

That’s correct, the Ubidots API expects a JSON, not a “raw” number and anything else.
I’d recommend taking a look at our library for Particle devices at