Assign data from webhook response to Spark.variable - please help

I'm trying to assign data coming from a webhook response to a Spark.variable and am getting a compilation error I can't resolve.

error: cannot convert 'char**' to 'char*' for argument '1' to 'char* strcpy(char*, const char*)'

char *msg[256];

void setup() {
Spark.subscribe("hook-response/pulltext_/0", hookResonseHandler, MY_DEVICES);
Spark.variable("message", &msg, STRING);
}
void loop() {}

void hookResonseHandler(const char *event, const char *data)
{
strcpy(msg, String(data));
}

The webhook response looks like:

{"name":"hook-response/pulltext_/0","data":""Hello "","ttl":"60","published_at":"2015-08-19T10:39:17.030Z","coreid":"null"}

I don't know enough C to really understand why this won't compile. But when I try a few reasonable variations, the variable does not get set. How can I make this work? Thx!

@vinceallenvince, the passed “data” is already a pointer to a char string so no need to convert it to a String. Also, you are declaring msg as an array of pointers which I don’t believe is what you had in mind. Here is what should work:

char msg[256];

void setup() {
Spark.subscribe("hook-response/pulltext_/0", hookResonseHandler, MY_DEVICES);
Spark.variable("message", msg, STRING);
}
void loop() {}

void hookResonseHandler(const char *event, const char *data)
{ 
strcpy(msg, data);
}

:slight_smile:

1 Like

Thanks!

In testing this, I’m having an awfully hard time getting the hookResponseHandler to execute. I can see the webhook response when monitoring my events via the CLI. Any ideas?

@vinceallenvince, is the publish() event you are firing the webhook with called “pulltext_”? You need to remove the “/0” in your subscribe().