JSON template for Open Weathermap webhook

Apologies if this has been covered elsewhere, I’m struggling with setting up a response template in webhooks.
I’m polling the open weathermap API with a webhook and I’m receiving a response, the following works:

void myHandler(const char *event, const char *data) 
{  
if (data)
// do the thing
}

But I only want to use a small part of the JSON response so I added a response template to the webhook. The JSON specifiction for open weathermap is here:
http://openweathermap.org/current#current_JSON

And my response template in webhooks looks like this:

{{weather.main}}

The code below isn’t working.

void myHandler(const char *event, const char *data) 
{  
if (data == "the current value")
// do the thing
}

Obviously data being returned isn’t matching the condition in the if statement but I can’t see why.
Two questions, hoping you guys can help:

Does the response template I’ve written look right?
How can I view the value of the “data” variable?

Many thanks

With char* you can’t just use the == operator, you need a function like strcmp() to test for equality.

The equality operator (==) would only compare the values of the two character pointers and not the contents of the respective memory locations.

e.g via Serial.println(data)

Many thanks, I’ll have a look at strcmp()

I’m probably being really dumb, but how do I use Serial.printIn ? Do I view the output in CLI?

You can view the output via CLI

particle serial monitor --follow

But you could use any other serial terminal program on your computer.

2 Likes

I figured out the JSON response template, webhooks uses the Mustache syntax, {{weather.0.main}} did the job