What is the best practice to subscribe to a webhook response that was trigger by a specific device?
Here is the scenario:
I have Photon A and Photon B, both calling the same get_weather webhook.
Each Photon provides its location to the webhook in order to get the local temperature.
What is the best way to have Photon A only react to webhook responses that where trigger by itself (same for Photon B)?
One way would be to encode the Photon ID in the webhook response, have each Photon subscribe and parse all the webhook responses, and do some action only when the ID is their own. This solution seems inefficient though. Is there a better way?
Baaed on the documentation available at http://docs.particle.io/core/webhooks/, you may have to provide one webhook for each of the location from where you want to get the location. As given in the documentation, you may have to register two webhooks.
@TheVelozGroup, thanks for the idea. It would definitely work, but it would become very hard to manage once you have many products. Imagine, if you have 1,000 product out there, you would need 1,000 Webhooks. All of them being exactly the same.
@kennethlimcp, the deviceID function described in the documentation (if Iām understanding it correctly) could enable the Webhook to respond only to PhotonA and it would ignore request from PhotonB.
But what I want to do is for the same Webhook to respond to PhotonA when PhotonA publishes the event, and to PhotonB when PhotonB publishes the event. @Dave, is there a way to do this?
So, now we have a webhook that anyone or any of your products can share, but we donāt want every single device to hear every single weather response for everyone else, we only want to hear messages relevant to usā¦
So far, the easiest way to do that is change the client subscription based on the published event name, but that doesnāt work well here. Soā¦ Hmmmmmā¦
We already have the concept of a response templateā¦ what if we had a āresponseTopicā setting, so you could key in the same way? In this case, we might add this to the hook:
Imagine you have 600 devices running in Shenzhen, each one of them program to ping the webhook every 10 minutes and then update the LCD. If we set the responseTopic by location, in the worst case scenario, each device in Shenzen would be updating the LCD every 1 second (10min / 600) instead of every 10 min.
This is a bit of a late response, but I did modify webhooks to allow setting the deviceid to "{{SPARK_CORE_ID}}", so I think this should be supported now.
Hey @Dave, Iāve read through the documentation but I am still unclear as to what I need to do in order to get the response when I pass deviceID.
What Iām trying to do is:
Make a webhook call with a specific device
My server performs an action and sends a response
Only the device that sent the request handles the response
Hereās my webhook:
{
"event": "init",
"url": "https://foo.com/api/devices/particle/{{SPARK_CORE_ID}}/id",
"requestType": "GET",
"mydevices": true,
"deviceid": "{{SPARK_CORE_ID}}", // Added this because I read something about it in the Docs...???
"coreid": "{{SPARK_CORE_ID}}"
}
If I replace System.deviceID() with MY_DEVICES then the callback worksā¦ I have read through the docs and forum posts but I canāt find what Iām missing.
You can deploy this firmware to all your Photons. Only when the hook is responding to that specific Photonās call, that deviceās locationHandler will be call.