Click here to Skip to main content
15,879,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all, currently i'm working in BLE.
I have connected to the device. Read command and write command works fine.
What My question is...

Can I send the write command again and again after connected to the device.
Posted
Comments
Richard MacCutchan 25-Mar-15 4:16am    
What happens when you try?
SViki 25-Mar-15 5:48am    
I have a button to start bluetooth and following the BLE common Role task. It's connected and works fine with follows, now i tried again to send the write command again. But i don't know how to call the
- (void)peripheral:(CBPeripheral *)peripheral
didDiscoverCharacteristicsForService:(CBService *)service{
}
Richard MacCutchan 25-Mar-15 7:56am    
Did you check the documentation?
SViki 26-Mar-15 0:47am    
In documentation they have not mentioned anything like "you can send the write command again and again after connected to device"

1 solution

Ah finally i got the solution. Thanks for everyone who helped me. Here is the solution. Now i can call this write mtd anywhere & any number of times.

CBCharacteristic *Writechar = nil;
CBPeripheral *writePeri = nil;

-(void)peripheral:(CBPeripheral *)peripheral
didDiscoverCharacteristicsForService:(CBService *)service
error:(NSError *)error
{
    for (CBCharacteristic *characteristic in service.characteristics)
    {
            [peripheral readValueForCharacteristic:characteristic];
            [peripheral setNotifyValue:YES forCharacteristic:characteristic];
           if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"ABCD"]])
           {
                    Writechar = (CBCharacteristic*)characteristic.UUID;
                    writePeri = (CBPeripheral*)peripheral;
                    [writePeri readValueForCharacteristic:characteristic];
                    [writePeri setNotifyValue:YES forCharacteristic:characteristic];
           }
    }
}



- (void) write
{
for(CBService *service in writePeri.services)
    {
        for (CBCharacteristic *characteristic in service.characteristics) {
            [writePeri readValueForCharacteristic:characteristic];
            [writePeri setNotifyValue:YES forCharacteristic:characteristic];
            if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"ABCD"]]) 
            {
                     [writePeri writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
            }
         }
   }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900