Hi guys
I want to send data to wunderground and I use your webhook service. The message arrives very good but instead of sending:
GET /weatherstation/updateweatherstation.php?IWATTWIL26&PASSWORD=xxxxxxx&dateutc=now&humidity=90
But it sends something like this:
Please help me!
How have you created your webhook?
Can you show the JSON file or a screenshot of https://console.particle.io/integrations ?
Also have a look at the webhook query docs
https://docs.particle.io/reference/webhooks/#query
You don’t want to pass the query as string. That’s what causes the special characters to be escaped.
You should rather click Advanced Settings and add your key value pairs in the query parameters list.
The values can be passed via a JSON string and accessed via {{key}}
The only thing I’ve not yet figured is how to get the IWATTWIL26
without getting a =
added automatically.
That’s impossible. I have to send it as one string.
Is there no other way?
“a JSON string” is one string
I don’t know how I should do this. So if I want to send this string: “IWATTWIL26&PASSWORD=xxxxxxx&dateutc=now&humidity=90” , what the JSON code would look like?
A starting point would be
char data[128];
char pwd[] = "xxxxxxxx";
int humidity = 90;
snprintf(data, sizeof(data)
,"{\"id\":\"%s\""
",\"pwd\":\"%s\""
",\"dt\":\"%s\""
",\"hum\":%d"
"}"
,"IWATTWIL26"
,pwd
,"now"
,humidity
);
And in your webhook you’d use {{id}}
, {{pwd}}
, {{dt}}
and {{hum}}
for your query values.
BTW, should your URL with the encoded query really look like this
/weatherstation/updateweatherstation.php?IWATTWIL26&PASSWORD=xxxxxxx&dateutc=now&humidity=90
or not rather
/weatherstation/updateweatherstation.php?ID=IWATTWIL26&PASSWORD=xxxxxxx&dateutc=now&humidity=90
1 Like
The ID should also be variable:
So would this be fine?
char data[128];
snprintf(data, sizeof(data)
,"{"id":"%s""
" "pwd":"%s""
" "dt":"%s""
" "hum":%d"
"}"
,"id"
,pwd
,"now"
,humidity
);
You had a literal for ID
and that’s the reason why I wrote the above exactly the way I wrote it and not any other way
The way you wrote it would just result in ...?ID=id&...
If you want to have a variable you need to use a variable in that statement and not another string literal.
char data[256];
char id[24] = "IWATTWIL26";
char pwd[] = "xxxxxxxx";
int humidity = 90;
snprintf(data, sizeof(data)
,"{\"id\":\"%s\""
",\"pwd\":\"%s\""
",\"dt\":\"%s\""
",\"hum\":%d"
"}"
,id
,pwd
,"now"
,humidity
);
1 Like
Thanks ;). And now can I just upload this code to my particle?
Nope, you need to embed this code in a proper project in the right way
And of course you need to set up your webhook the correct way too.
If I want to add this to JSON I get an error!
If you what?
And what error would that be?
Please could you help me? I’m unable to solve the problem. I dont know which code I have to upload to my Particle and how I have to adjust the Webhook
Try setting up your webhook like this
And use my code to set up the event and
Particle.publish("weather", data, PRIVATE);
Hi, when I use your code I get this:
There are not values in the GET string
Oops, I forgot the commas in the publish string
I’ve updated the code above