Syncing two photons together


#1

Hello,

I’m working on a project for work where there are two boxes, each with a button and a ring of LEDs controlled by a photon. One of the buttons is pushed to make an order and the other button is pushed to acknowledge the order. Whenever a button is pressed, the LEDs turn on or off (eventually there will be other states/animations to signify said states) and my goal is to have both rings of LEDs are in the same state.

I have a working prototype using .publish but my fear is that there is no guarantee that both LEDs are doing the same animation. Any idea how to go about this? My idea is as such:
Button press -> local LED lights up and .publish to say “order request” -> remote photon subscribes to events and sees request -> remote LED lights up and .publish to say “order receive” -> local photon subscribes to events and sees order is received.

Essentially there’s two publish events every time a button is pressed. Is that overkill?

Thanks


#2

That’s essentially how I would do it. There might be ways to get rid of the second publish but if you want your second device to validate the data and truly acknowledge receipt, then you need an acknowledgement generated by the second device. The publish and subscribe works well for that.

You weren’t very specific about how “in sync” those lights need to be. Do you just want to act on the pub/subs? If so, you’re done but know that there might be a bit of latency between the pub and sub.


#3

You weren’t very specific about how “in sync” those lights need to be. Do you just want to act on the pub/subs? If so, you’re done but know that there might be a bit of latency between the pub and sub.

In an ideal world they’d be in perfect sync but as long as they were less than 30s, or even 10s, then I think I’ll be happy. I figured pub/subs would work, but I was wanting to make sure there isn’t a “best practice” guideline that I should follow.


#4

As long as your network connection is good, then pub/sub is the easiest way to go. If you want this to work independently of your internet connection, then you could use 2 mesh devices and to do the Mesh.pub/sub… but the mesh stability is a bit buggy right now. Another alternative is to use TCP or UDP messages between the devices. TCP/UDP isn’t very plug-and-play though as the data would be un-encrypted and you would have to hard-code or discover the IP address of the other devices somehow. I’ve requested a new feature to do pub/sub between devices on the same subnet but that’s a pipe-dream at the moment.