Allan,
You could first scan and list the peripherals without the additional user interface.
After scanning for 5 seconds or so, connect to each one to retrieve additional info, and update the user interface.
This way, the user interface does not feel empty and one can see that something is happening (like a web browser -
it doesn't wait until all images are loaded to display a web page).
Because I don't know the exact use case, I cannot recommend a specific behavior here.
It all depends on the user experience that you want to deliver.
Advertising data is limited. A 32-byte object cannot be put there currently. Note that when using the CBPeripheralManager,
you can actually put more data in an advertising packet than is actually defined in the Bluetooth Core Spec.
However, this data can only be read by other iOS devices.
Etan
Hi Etan,
> A solution for your problem would be to first build a list of devices to connect, then stop scanning and then connecting to all peripherals.
So, for a Central that might want to connect to multiple Peripherals, would you advise scanning for some period of time, stop scanning, and then update the user interface with the list of discovered Peripherals?
Currently, I'm connecting as I'm scanning. Indeed, I'm scanning/connecting while this particular user interface is showing, so that I can dynamically add newly discovered Peripherals to my UI…and I need to connect to them when found, so that I can query
them for some information to show in the UI.
The advertising data itself does not allow enough room for meaningful data for my UI…this is why I was connecting whenever I found a new peripheral…that is, in order to be able to read a characteristic so that my UI can show something meaningful about
the peripheral.
But perhaps this isn't a good approach.
Maybe, then, I should scan for 5 seconds or so, building a list of CBPeripherals, then connect to each one to query for additional info, and to allow the user to interact with each one (via a writeable characteristic and notifications/indications).
Thoughts?
Also, is the custom data in the advertising packet really limited to something like 28 bytes or so? I have a 32-byte object that I would love to expose in the advertising packet.
-Allan
Allan,
Advertising does normally stop when a connection request is received. Not sure about iOS, but there is no way to stop advertising with the API currently. Have to check that with a sniffer.
When you program the central side, connecting becomes very slow while scanning. A solution for your problem would be to first build a list of devices to connect, then stop scanning and then connecting to all peripherals.
Etan
On 16.01.2013, at 17:46, "Allan Young" < email@hidden> wrote:
Etan,
Regarding your comment:
> Also don't forget to stop scanning and advertising as soon as you establish a connection.
…is it really necessary to stop scanning and advertising when the connection is established?
From the peripheral side, what if multiple centrals want access to my data?
And from the central side, what if I want to get data from a number of peripherals advertising the same service/characteristics? To use a medical/sports example, should I be able to monitor the heart rates reported by a number of different peripherals?
Is this not possible?
Thanks.
-Allan
Hi Joakim,
Bug number: 12963322
On 16 Jan 2013, at 03:06, Joakim Linde < email@hidden> wrote:
Hi Darren,
What's the bug report number for this?
Thanks,
Joakim
On Jan 11, 2013, at 8:23 AM, Darren Jones < email@hidden> wrote:
Thanks Etan,
I have actually filed a bug report for the backgrounding of bluetooth-central stopping.
I hope they fix it soon as there's so much more potential for apps when continuous background scanning is available.
On 11 Jan 2013, at 16:21, Etan Kissling < email@hidden> wrote:
Darren,
OK. If you want to enable background scanning and advertising, just add the bluetooth-central and bluetooth-peripheral keys
to the UIBackgroundModes array in your Info.plist.
bluetooth-central
|
The app uses the CoreBluetooth framework to communicate with a Bluetooth accessory while in the background.
This value is supported in iOS 5.0 and later.
|
bluetooth-peripheral
|
The app uses the CoreBluetooth framework to communicate in peripheral mode with a Bluetooth accessory.
This value is supported in iOS 6.0 and later.
|
You will then receive the callbacks for around 45-60 minutes of background mode. After this, a bug
prevents to receive more callbacks, as the connection is terminated as soon as your app is purged
from the memory. After relaunching the app, scanning should resume to function properly.
Etan
wrote:
Thank you. I want to use non pairing so CoreBluetooth is the way.
I'm glad it's possible. I wasn't sure if background scanning and advertising would be allowed.
On 11 Jan 2013, at 16:02, Etan Kissling <email@hidden> wrote:
Darren,
If you want to perform iPhone to iPhone communication only, I suggest using GameKit for it.
You will have an increased throughput, as classic Bluetooth is used as a transport, and don't have
to worry about specifying who is master and who is slave.
If you want to stay with CoreBluetooth: at least from the Bluetooth Core Specification, a device is
allowed to scan and advertise at the same time. I have not yet tried it under iOS, but can tell for your
background requirement that scanning times are pretty slow while backgrounded (around 55x
advertisement interval). Also don't forget to stop scanning and advertising as soon as you establish
a connection.
Etan
On 10.01.2013, at 23:59, Darren Jones <email@hidden> wrote:
Is it possible to use CBCentral scanning and CBPeripheral advertising at the same time? (Also in the background)
If I wanted 2 random iPhones to communicate and both where set to Central or both to Peripheral they wouldn't see each other. I'd like to remove that they would both have to know which method to activate.
Is that possible?
Thanks
Sent from my iPhone 5
|