Particle.publish vs Particle.function

I noticed in the documentation for Particle.function()
“Up to 15 cloud functions may be registered.”

I’m not sure exactly what qualifies as a particle.function.

In my application I will have many devices, each listening to their own pub/sub topic through the Google Cloud integration. The cloud must be able to push data to the device.

Is each of these “listener” functions considered a “particle.function” ?

Is this limit of 15 per device, or for the entire Particle cloud including all devices in my fleet? If the limit is 15 listening/subscriptions per device we are okay, but if it is global to the entire collection of devices I will need a different strategy.

I’m trying to understand the limits so I don’t run into a problem once I try to provision the 16th system.

Sort of a related question if anyone has an opinion -

In my back end I will have various processes that will occasionally send controls/queries to a given target device within my fleet. To conserve cellular data, I don’t want that event to be sent to every single device, only a specific device I target from the back end process. (Via a “location_id” or something).

To prevent every device receiving every message, I plan to set up a separate pub/sub topic for each device, then in the Particle console I plan to key each new hardware device to the newly created pub/sub (or possibly a pair of them, one for incoming and one for outgoing).

Will I run into problems once we have 50, 100, 500+ etc devices in the fleet, each configured with a unique key to their own topic?

Or is there a better strategy where all devices talk to a single pub/sub but somehow only certain messages are routed to certain units? I don’t think this is possible as every device would be listening to the same topic. I don’t think “PRIVATE” will work in this case either, if I understand this, as it would still match on all of my devices in the entire fleet.

Thank you.

Particle.function() and Particle.publish() are two different things.

A Particle function is literally that,

Particle.function(string argument)

These are limited to ~15 per device (primary due to memory constraints). They are unique to those devices. They will show up if you query the API, and they can be ‘called’ directly via the API. You’ll also find them in the Particle console on the device’s page.
1-to-1 communication. Think of it like a phone call with instructions.

Particle.publish is similar to Twitter. You’re basically shouting into the void to whomever might be listening. That last bit is crucial. Unless you’re listening for the specific things that are being broadcast, you won’t receive anything. No limits on the amounts of publishes, though there’s a rate limit.

Particle.subscribe is what you use to listen to those messages. There’s a limit of four distinct subscriptions you can have per device. Since it works with a pre-fix, you can listen to more things, and weed out what you don’t need later.

There is.
Use publish/subscribe when you want to talk to multiple things at once.
Use function calls when you want to target a specific device.

Hope that helps :slight_smile:

1 Like