[SOLVED] Web Hook Response, receiving NULL data

Hey guys.

I’m new to web hooks and looking for some help with a Subscribe() issue.

I’ve set up a web hook “command” with a GET request to adafruit IO, and set up a small piece of test code more or less cut-and-paste from the reference.

int i = 0;

void myHandler(const char *event, const char *data)
{
  i++;
  Serial.print(i);
  Serial.print(event);
  Serial.print(", data: ");
  if (data)
    Serial.println(data);
  else
    Serial.println("NULL");
}

void setup() {
  Particle.subscribe("command", myHandler);
  Serial.begin(115200);
  Serial.println(); Serial.println();
  Serial.println(F("Initialized"));

}

void loop() {

    //pingsensor.turnOnffRx();
    Serial.println(F("Publish Command"));
    Particle.publish("command");

    Serial.println(F("finsihed"));
    delay(20000);
}

The myHandler function is just printing “NULL” to the terminal, but in the console it looks like I’m getting a good response, “78” is the data I’m looking for.

Terminal:

Console:

I have tried removing the if statement and just print data but it’s still NULL. Also tried casting to string with no luck.

Anyone who can tell me what I’m doing wrong?

-Marius

You should not subscribe to your own event - which in deed has NULL payload -, but you need to subscribe to hook-response/command

With the current handler you’d need to Particle.publish("command", "some payload") then you’d get some payload :wink:

BTW, forget this F() macro on these devices - it’s not doing anything at all.

1 Like

Thanks, that make sense.
…but I’m still having trouble, changed the setup() as follows:

void setup() {
  Particle.subscribe("hook-response/command", myHandler);
  Serial.begin(115200);
  Serial.println(); Serial.println();
  Serial.println("Initialized");
}

Now the handler does not seem to ever get called, IE neither the data or “NULL” is printed. The hook response events are still rolling in to the console.

got it to work:)

Turns out I had to include the MY_DEVICES constant in the subscribe() function.
Kind of surprising to me since the reference makes it look like this as a more restricted subscription (… listen to events published only by your own devices…). But whatever works, right :slight_smile:

Thanks for your help !

-Marius

1 Like