Publish and privacy inside organisations

I’ve been playing a bit with the publish and particle organisation part and designing our communications inside our device fleet.

Basically I’m trying to publish from server an event like “devicename-deviceid-timerdata” so I could then add subscription to each device to listen to “devicename-deviceid-” and easily relay all kinds of info`/settings back to the device. However it seems that if I publish from server it gets assigned coreid of 001 and name “cloud”.

This means that I can’t only listen to “my devices” from the device end but rather have to listen 001 which is public I assume. Also if I make the event private the device can’t see it. So it seems there’s no way to privately send data from cloud to the device via publish? I hope I’m mistaken?

I’m happy with the devices not seeing each others published data but I’d need some way to publish events from our server which can be seen only by our devices. Any ideas?

@tuxie, you can actually do that.

For private events, you need to subscribe with the MY_DEVICES flag

See the example here - https://docs.particle.io/reference/firmware/electron/#particle-subscribe-

Also, for using non :particle: devices to publish, i think the deviceID/name comes out to be cloud.

Using CLI, there is --private flag that publishes a private event that your devices listening only to MY_DEVICES can receive.

It will be something like: particle publish myData someDataValue --private

I’m not sure how you are publishing but if you are using some javascript, the form looks something like this:

https://github.com/spark/particle-cli/blob/master/lib/ApiClient.js#L729

1 Like

My devices publish using the PRIVATE flag. I subscribe to the events using the cloud API using the code running on one of my servers.

GET /v1/devices/events/:eventPrefix

https://docs.particle.io/reference/api/

My code is written in Java (Apache Tomcat), but that’s not necessary; any language that can parse Server Sent Events (SSE) can be used. The stream of data that comes back from the Particle server continuously and basically instantaneously includes a block of JSON data when an event is published. It looks like this (from the docs):

{"data":"25.34","ttl":"60","published_at":"2015-07-18T00:12:18.174Z","coreid":"0123456789abcdef01234567"}

The important thing is that it includes the coreid, which is the device ID of the device that sent it, so you don’t even need to put it in the event name or data. It should all be completely private and sounds like what you need.

Ahh thanks… Actually the catch was that with using:

Particle.subscribe("remoNave", dataReceiver, MY_DEVICES);

you have to use following in the CLI when testing:

particle publish remoNave testinggg --private

And when not using MY_DEVICES you have to drop the --private… Mix and match didn’t work. Thanks! It thought they could be mixed as needed but apparently nope…

1 Like