Webhooks - Need help!

Hi there,

I am trying to understand webhooks but I am having some major brain malfunctions and cant seem to wrap my head around this.

I have a PHP script - www.mywebsite.com/post.php
This looks for two fields; ID and INPUT, and extracts the data following these identifiers.

e.g. - …ID=…&input=…

I want to send the contents of the device variables ID and INPUT from my Electron, to the PHP script via the use of a webhook.

Can someone please point me in the right direction? I don’t have a clue how to publish this, and have the webhook send it correctly.

Any help will be greatly appreciated.

Kind regards,

Chris

You are probably looking to send a query string like:

https://mysecurewebsite.com/?ID=10&input=100

Or are you running a form?

Thanks for the reply,

No I am not using a form.

How do I send it as a string query? When I tried (using the requestb.in that was recommended by Particle) it showed me a load of information such as; “alert=postrequest&data=…&timestamp=&api=…” and all my data was muddled with %27%amp% and so on and my post.php could not extract the required fields.

For reference, this is what the simulated HTTP request code looks like;

POST /post.php HTTP/1.1
Host: mywebsite.com
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache

ID=TX10&input=1494488720%2C5%2C70.9375%2C3.95875%2C100%3B1494489620%2C2%2C70.9375%2C3.95625%2C100%3B1494490520%2C8%2C70.609375%2C3.95375%2C100

You will need to set noDefaults to true to remove the extra information:

https://docs.particle.io/reference/webhooks/#nodefaults

The curl command i used is:

curl -G -X POST -d "IP=100" -d "input=10" https://requestb.in/s4vij9s4

The Particle.publish() using the CLI looks like this:

particle publish testEvent "{\"ip\":\"100\",\"input\":\"200\"}"

Doing it in firmware looks something like:

		char buf[256];
		int val1 = 100;
		int val2 = 200;
		snprintf(buf, sizeof(buf), "{\"ip\":%lu,\"input\":%lu\"}", val1, val2);
		Particle.publish(PUBLISH_EVENT_NAME, buf, PRIVATE);

You can see the output here: https://requestb.in/s4vij9s4?inspect

My webhook is something like:

Hi,

Apologies for the late reply.

Thank you so much. That worked perfectly!
With the char buf, I assume there is a limit to how much can be published at once?

it is somewhere in the docs

:smirk:

1 Like