How to write data to multiple Bluetooth LE slaves simultaneously on CoreBluetooth?

試著忘記壹切 提交于 2019-12-10 12:15:26

问题


I am new to this. I am trying to work on an iOS application where i can to exchange data to multiple Bluetooth LE slaves.

I am able to connect and read from the multiple slaves. But the problem is i can only write (sound buzzer) to only one of them (the latest slave to be connected).

I am using the code provided in http://processors.wiki.ti.com/index.php/Category:IPhone4SBLEDemo

How is it possible to sound buzzer for all connected devices?

ViewController.m

- (IBAction)TIBLEUISoundBuzzerButton:(id)sender {
[t soundBuzzer:0x02 p:[t activePeripheral]]; //Sound buzzer with 0x02 as data value

Keyfob.m

-(void) soundBuzzer:(Byte)buzVal p:(CBPeripheral *)p {
NSData *d = [[NSData alloc] initWithBytes:&buzVal length:TI_KEYFOB_PROXIMITY_ALERT_WRITE_LEN];
[self writeValue:TI_KEYFOB_PROXIMITY_ALERT_UUID characteristicUUID:TI_KEYFOB_PROXIMITY_ALERT_PROPERTY_UUID p:p data:d];}

回答1:


I have found the answer to my own question. By making use of didRetrieveConnectedPeripherals, i can write data to all connected devices simultaneously. Hopefully this can help whoever is looking for the same answer. Thank you!

-(void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeripherals:(NSArray *)peripherals {

for(CBPeripheral *peripheral in peripherals) {//(soundbuzzer) }}


来源:https://stackoverflow.com/questions/14652179/how-to-write-data-to-multiple-bluetooth-le-slaves-simultaneously-on-corebluetoot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!