Multiple Photon InterConnectivity Project - Help Please!

Hi all. I am relatively new to IoT devices and programming but I thought I’d dive head long into a project I’d actually want to get running to learn how to do it. Crazy, I know.

Here is my idea that I have very little idea how to get running.

I want to make a gift for my siblings. These gifts would be an LED connected to a Photon, powered by a wall plug, connected to their various networks, and these lights would all be interconnected. When sibling A activates his light (saying “Hi”), it would turn blue. Then, in response to sibling A activating his light, siblings B, C, and D etc. would have their respective lights activate blue as well in whatever location and network they are located. In response, sibling B could activate their light saying “hi” in return and thus push their selected color onto the other lights, possibly with some pulsating because it was a response to sibling A first saying “hi”.

To start with, I already have two photons, two neopixel rings, and the power supplies for hardware. I have them both wired up and I have loaded simple projects that I have found online to make sure my neopixels are working and wired correctly. Both photons connect to the internet just fine.

Where I am now having problems is how to I tell the photons to look for the “Hi” that another lights are sending? I’m assuming I’d have to program in a publish command and use the cloud to manage sending and receiving the publish commands? Would I also need to add a subscribe function? How then could I set up a return “hi” to the other units? I’ve already spent the better part of a couple days to no avail and am back to the drawing board as it were on my coding. Any info/advice/sarcastic comments are greatly appreciated and welcomed.

I’m sure I’ll have many more questions arise but I feel like this is a good start.

Thanks and I look forward to your help.
Micah

1 Like

Publish and subscribe is the way to go.
Photon A publishes “Hi A”, to which Photon B subscribes. In turn, Photon B can publish “hi B”, to which Photon A subscribes.

So you’d end up with publish/subscribe pairs on the relevant devices.
There’s an example in the docs: https://docs.particle.io/guide/getting-started/examples/photon/#the-buddy-system-publish-and-subscribe

Thanks for your reply @Moors7. So using this example, would I need to set up a pub/sub list for each photon?

I.E. A publishes “Hi” and B, C, D, E, etc. would all be subscribed to it. Then B pubs “Hi” and A, C, D, E… are sub’ed to that pub, etc?

Yes, that’s the general idea. You can use the same event name for each of your devices in the Particle.publish(), and only change the data – the data argument could contain the name of the sibling that sent it, for instance. This way, each device only needs one Particle.subscribe, to that common event name.

2 Likes

To further expand on that, not even the full event name needs to be exactly subscribed to, but only the starting part (prefix) of it.
So Particle.subscribe("Hi", hiHandler, MY_DEVICES) would fire for Particle.publish("Hi A!", data, PRIVATE) and for Hi B! just the same as for Himalayas.

So, as another tip is not to use a nondescript event name like Hi but something more creative :wink:

2 Likes