Trigger Synchronized events for multiple devices

Discussion in 'iOS Programming' started by IDMah, May 23, 2017.

  1. IDMah macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #1
    Hi All.

    I've got an idea (I know a dime a dozen) where I would need to very accurately synchronize 4-16 devices. Phones. So they trigger at exactly the same time.

    Anyone know of a framework for this?
    Something I can control over Wifi ? from a laptop?

    if not looking for ideas on how to do this. Accuracy is important.
    1/60th or less of second would be required.

    thanks!
    Ian
     
  2. Mascots, May 23, 2017
    Last edited: May 23, 2017

    Mascots macrumors 68000

    Mascots

    Joined:
    Sep 5, 2009
    #2
    Depends: If the app is open, then you can poll or observe a server to wait for events to be pushed down the line and respond to them instantaneously.

    If you're talking about notifications, then unless you know about the events at predetermined times and can schedule those with the system ahead, there is no full-proof method to trigger to an iPhone since there is no guarantee that the notifications delivered through APNS were even delivered at all. In my experience with APNS, I've never seen a push arrive without at least 1-3 seconds of latency.
     
  3. chown33 Moderator

    Staff Member

    Joined:
    Aug 9, 2009
    Location:
    bedlam
    #3
    Are the 4-16 devices in the same physical location? If so, how big is the location: room, hall, school, stadium, multiple rooms?

    Are the devices on the same wi-fi network? If so, a UDP or multicast packet would seem to be a good potential solution.

    What's the budget/cost for the customer? Can you tell them to buy a piece of equipment? What's the equipment cost?

    Is one of the 4-16 devices also the initiator of the trigger? Or is another device sending the trigger?

    How much precision? If one device is inherently faster than others, does the person with that device have an inherent advantage, even if it's only a few milliseconds?

    What's the failure mode? If a device misses a trigger event, what's the worst that happens? Does someone lose a point in a game, or do they lose 50$, or a body part?
     
  4. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #4
    My thought was to sync all the devices' clocks and trigger an event at time hh:mm:MS
    would that work?? Initiated by a laptop. Dedicated network from the laptop maybe???

    It's just the start and maybe the stop that is important.
    If sync is off or misses trigger then yes a body part would be lopped off.. Hahah!
     
  5. chown33 Moderator

    Staff Member

    Joined:
    Aug 9, 2009
    Location:
    bedlam
    #5
    You don't need to sync device clocks. All you need is to start everyone with the same countdown, and do so within your margin of error.

    Or you could send out a series of timestamped packets, which receivers listen for. Multicast would be good for that.

    There are many ways to structure this if UDP packets are the underlying communication mechanism. It depends on what you want the triggers and stops to actually accomplish.

    If this is for a game or contest of some kind, you'll also have to design things to prevent cheating.

    That's an extreme example, but developers sometimes don't pay attention to consequences.

    For example, someone I know made a combination of an app talking to a BLE device connected to a car. If the BLE device got a malformed message, the device would malfunction and the car would stop (motor would die). This is very bad when one is in traffic. It should have been obvious, but I had to convince him to make the device fail safely by adding failsafe circuitry, and to error-check / validate every message. The app + device didn't go anywhere in the market, but it would have been quite grim if the failure of app or device had led to a traffic accident.
     
  6. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
  7. dantastic macrumors 6502a

    dantastic

    Joined:
    Jan 21, 2011
    #7
    Have a look at websockets. All the devices can be made client devices that connect to a master node which can notify all clients at the same time. If all the devices are on the same network then the margin of error should be very small.
    This assumes that you are in a 'session' as such, that you run this for a while and then stop. You can't keep websockets just open day in and day out as long as the app is installed.
     
  8. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #8
    So great suggestion gang! thanks a lot.. Now I just have to get programming. Hahaha!
    Are most of these solutions Multiplatform? Android and iOS?
    Would want it to work on both with controller / master being a laptop of some sort.

    Any framework recommendations for multi-platform Multicast??
     
  9. AxoNeuron macrumors 65816

    AxoNeuron

    Joined:
    Apr 22, 2012
    Location:
    The Left Coast
    #9
    Unfortunately you cannot rely on iOS system time, since you cannot depend on that to always be accurate.

    There are frameworks that you can implement which use network time synchronization to get a far more accurate idea of the time. I would suggest using one of these NTP (network time protocol) client frameworks.

    https://github.com/instacart/TrueTime.swift

    This framework (TrueTime) also has an Android version as well.

    Then, you can use a backend server to tell all clients "fire the event at this precise UNIX time stamp" and the devices will then use that time stamp to schedule the event.

    Websockets is a good recommendation especially for devices on the same LAN. But I wouldn't depend on it completely.
     

Share This Page

8 May 23, 2017