Curl API - Publish Event to Device

Hi, is there anyway to call Event to a device of my choice?

I can publish event to Global Events using this curl command:

curl https://api.particle.io/v1/devices/events -d name=temperature -d data=some_data -d private=true -d ttl=60 -d access_token=XXXX

What about a device? Can it be done? I’ve tried this curl but it doesn’t work

curl https://api.particle.io/v1/devices/<device_ID>/events -d name=temperature -d data=some_data -d private=true -d ttl=60 -d access_token=XXXX

Thank you :stuck_out_tongue:

There is no way to send an event to a single device, hence you neednot (mustnot) add device_ID

You only have PUBLIC/ALL_DEVICES or PRIVATE/MY_DEVICES for Particle.publish()/Particle.subscribe().

In the early Spark Core days a per device even was “intended” but it never got implemented and then ditched entirely.

If you only want one of your devices to react to an event you need to go for a unique event name prefix (e.g. device name or device ID) in your Particle.subscribe() call.

That would be a nice feature, I use it to test Integrations but in order to work I have to choose “Any Device”. It saves me time from uploading code to a device and using Particle.publish

Than you :stuck_out_tongue:

This is a fair point.

Particle provides the capability to limit the source of a triggering even to a particular device but the response would be sent to all your devices spamming all the ones that cannot be the source after all.

Theoretically you could have multiple integrations listening to the same event but filtered via the source device, so you would logically also want the response to only be delivered to the source of the original - actually triggering - event.

Hmm, this may be something for @rickkas7 or @marekparticle to comment on.

On device you can register the event handler with System.deviceID() as a prefix. Then you can publish to that device (and only that device!) by including it in the start of your events.

1 Like

That’s what I suggested above, but how about this

Sure, there ara “workarounds” like having a webhook listen for e.g. "deviceEvent_" where the device sends an event with "deviceEvent_" + System.deviceID() and subscribes to "hook-response/deviceEvent_" + System.deviceID() but where is then the use of the webhook filter field for a specific device?
The same would then be achievable (and less confusing) when the webhook was already listening for the fully qualified event (with the option to drop the per device filter entirely as ANY would be the one-fits-all solution), wouldn’t it?