iosdeveloper
iosdeveloper

Reputation: 99

IOS:Write command values to corebluetooth peripheral device to get the response

Developing corebluetooth application and got sucked with few aspects like communication with the peripheral device .Iam getting confused to write commands to watch in order to retrieve information from it.please find my code below

  int sendcommand[6];
  sendcommand[0]=0x01;
  sendcommand[1]=6;
  sendcommand[2]=0x70;
  sendcommand[3]=0x00;
  sendcommand[4]=crcData[0];// value is -100
  sendcommand[5]=crcData[1];// value is -31

  NSMutableArray *arr=[[NSMutableArray  alloc]initWithCapacity:6];
  for (int i = 0; i < 6; i++) {
    NSNumber *number = [NSNumber numberWithFloat:sendcommand[i]];
    [arr addObject:number];
   }
   NSLog(@"mutable arr is %@",arr);

  NSString *error1;
   NSData *dataarr = [NSPropertyListSerialization dataFromPropertyList:arr    
   format:NSPropertyListBinaryFormat_v1_0 errorDescription:&error1];


CBMutableCharacteristic *testCharacteristic = [[CBMutableCharacteristic alloc]  
initWithType:characteristicUUID 
properties:CBCharacteristicPropertyRead|CBCharacteristicPropertyWrite value:dataarr 
 permissions:CBAttributePermissionsReadable|CBAttributePermissionsWriteable];
NSLog(@"Read or Write %@ ",testCharacteristic);

[peripheral writeValue:dataarr forCharacteristic:testCharacteristic 
type:CBCharacteristicWriteWithoutResponse];

My problem is to create a packer by using the above six commands and send the data to peripheral and in response to that it give some information back with updating values.am getting the console values as

  2014-12-19 19:26:51.068 Bluetooth_iph[1267:180180]    

   didUpdateNotificationStateForCharacteristic
   2014-12-19 19:26:51.069 Bluetooth_iph[1267:180180] characteristic.UUID : 8881
   2014-12-19 19:26:51.069 Bluetooth_iph[1267:180180] characteristic.value : (null)
   2014-12-19 19:26:51.069 Bluetooth_iph[1267:180180]    
    didUpdateNotificationStateForCharacteristic
    2014-12-19 19:26:51.070 Bluetooth_iph[1267:180180] characteristic.UUID : 8882
    2014-12-19 19:26:51.070 Bluetooth_iph[1267:180180] characteristic.value : (null)

please help me in creating the packets for the above commands get the response from the blue peripheral.

Upvotes: 0

Views: 971

Answers (1)

Aris
Aris

Reputation: 1559

You should not create CBCharacteristics manually. You should use the ones that the CBCentralManager returns in the method:

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error

you can access the characteristics from:

service.characteristics

Upvotes: 1

Related Questions