BLE Multiple Device Communication with Time Slicing

I am trying to determine if it is possible for multiple mobile devices to periodically talk to a single peripheral device using BLE communication. I know that simultaneous connections are not allowed with BLE so the app would have to be time sliced, connect to the peripheral device, downloading the data, and then disconnect from the peripheral device. Once disconnected, the peripheral device would start advertising again and another mobile device could connect, download the data, and disconnect again. The peripheral device would be talking to multiple mobile devices, however only talking to them one at a time. Also, my application only needs to update the mobile device once a minute and the amount of data that gets transferred is minimal.


One of my concerns is since the peripheral device would constantly be advertising, the app would need the ability after a successful connection and data download, to put the Bluetooth to sleep and then wake up once a minute and try to connect again. Otherwise my fear is that the same mobile device could be connecting and disconnecting to the peripheral device not allowing other devices to connect. Will Apple allow the app to have control of the Bluetooth or allow the Bluetooth to sleep?

My other concern is trying to make the app automatically remember and connect to the peripheral device at will without any user notification, except for the first time. The goal is to make the app straightforward and seamless where the user would not always be prompted once a minute to connect to the peripheral device.


Thanks in advance,

- Josh

You can't control the device's Bluetooth services, or "Put Bluetooth to sleep" as you say.

But you can control your app any way you want.


Try setting a flag to indicate when was the last time you connected to the peripheral and ignore the advertisements from the peripheral for a duration of your choosing

Thanks for your response. I would just basically set a timer in the app for the duration that I want and when it expires, go ahead and try to look for the peripheral device again. Once connected and the data was retrieved, restart the timer.

Since I am programmatically in control of both the app on the mobile device and the master device, the other thought that I had was to make the multiple mobile devices the peripheral and the master device the central device. One concern with that is that the multiple mobile devices would constantly be advertising and something else could connect to them instead of the master device? Also, I was unsure if an app running in peripheral mode can initiate a disconnection or if that has to come from the master device as well? Looking through the forum and was unaware if there are any significant issues with running apps in peripheral mode versus central mode?


Making the master device a central role and the multiple mobile devices peripheral would mean that the master device would need to look at the advertisements, parse the data, to see which is a mobile device versus an activity tracker for example. Then the master device would initiate the connection, download the data, and disconnect. Then it would go onto the next mobile device and do the same. The master device would still have to perform the time-slicing, updating each mobile device once a minute. If there are over 50 peripheral devices, this might be problematic for the master device to keep track of everyone versus making the app the central role and the master device is the peripheral role. I am fairly new at BLE and not sure who should be the central and peripheral.


Thanks,

- Josh

Not exactly. You can't just set a timer and then start scanning when it expires. You need to consider that the user will press the home button or lock the phone.

In those cases, your timer will stop working.


What you need to do is keep scanning, and when you get the discovery callbacks, check the time to see if enough time has passed - if not, do nothing and keep checking the time. If you are actively scanning, even if your app is backgrounded, the system will activate your app when the BLE peripheral is advertising.

You should also look at CoreBluetooth state preservation/restoration in case your app gets terminated by the system while in the background. More info here: https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html#//apple_ref/doc/uid/TP40013257-CH7-SW5


I can't help you with your architecture decisions, but if it would help; another way of looking at the central/peripheral relationships in BLE is client/server.

The device which has the information is considered the server, and the cleints connect to it when they want to obtain that data. In the BLE world, the central is considered the client, and the peripheral is the server.


In the end, where you put the more control (and more code) depends on the capabilities of your hardware and on what side you prefer to do the most work.

BLE Multiple Device Communication with Time Slicing
 
 
Q