I was working on a project that utilized 10 different webhooks at different times in the sketch. The photon documentation says you can register up to 20 webhooks with a single device, but the particle.subscribe( ) function says :
“NOTE: A device can register up to 4 event handlers. This means you can call Particle.subscribe() a maximum of 4 times; after that it will return false.”
Am I wrong to think I cannot get data from 10 separate webhooks in one sketch?
I can see the webhook data for all 10 in the console but when I try to print the data on an LCD screen I can’t seem to print more than 4 in one sketch. They all work and it doesn’t matter which 4 I choose as long as I don’t subscribe to more than 4.
Is that just the way it is? Is there a workaround or do I need to look at other ways or consolidating the webhook data before the photon makes the call.
As @bko said, prefix filtering is the way to use these subscriptions by design, not as a workaround.
Particle.subscribe("hook-response/", ...) will setup one subscription for all webhook responses and you can then distinguish which response it was in your code by looking at the even name (first parameter of the handler)
OK. I think there’s something I don’t understand here. I tried below. Which seemed to work until I started getting ESOCKETTIMEOUT in the console. Still something wrong?
Are you expecting to catch your own events or the respective webhook responses?
The hook-response/ filter will only catch the latter ones.
If you want to test the former, you need to prefix your event names with ... well ... a fix term like
And all these delays will also impact responsiveness of the cloud task as in these cases the cloud keeping only happens once per second - instead of aprox. 1000 times with non-blocking programming techniques.
Thank you. Let me try some variations based on your advice. I'm getting data from an API and I want different data from a different webhook each minute (thus the delays).
Just letting you know, thanks to your advice, I got my 10 webhooks working the way I want with just 3 subscriptions. Thanks for explaining the prefix filtering. You are awesome.