How to send RGB signal to BLE device using iPhone app?

We are working on an iOS application in which we need to transmit an RGB signal to a BLE device and based on the RGB code the LED of the device will light up. We are making a connection using the Bluetooth framework CBCentralManager

object CBPeripheral

in the iOS app.

We are setting the UUID of the characteristic and descriptor, but still we cannot send a signal to the BLE device. Here is the code we use to transfer RGB data in hexadecimal byte format.

- (void)centralManager:(CBCentralManager )central didConnectPeripheral:(CBPeripheral )peripheral
{
    NSLog(@"connect peripheral");

    unsigned char bytes[] = { 0x5, 0x1, 0x70, 0x70, 0x70, 0x70, 0x48, 0x49,0x48, 0x49, 0x48, 0x65, 0x48, 0x49, 0x48, 0x48};
    NSData *nsData = [[NSData alloc] initWithBytes:bytes length:sizeof(bytes)];

    CBMutableCharacteristic *myCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:@"00002a46-0000-1000-8000-00805f9b34fb"] properties:CBCharacteristicPropertyWriteWithoutResponse value:nil permissions:CBAttributePermissionsReadable];

    CBMutableDescriptor *yourDescriptor = [[CBMutableDescriptor alloc]initWithType:userDescriptionUUID value:@"00002902-0000-1000-8000-00805f9b34fb"];

    myCharacteristic.descriptors = @[yourDescriptor];

    [myCharacteristic setValue:nsData];


    [self.peripheral writeValue:nsData forCharacteristic:myCharacteristic type:CBCharacteristicWriteWithoutResponse];
    [self.peripheral setNotifyValue:YES forCharacteristic:myCharacteristic];
}

      

Are we doing it right? Is there a problem sending data or creating an object CBMutableCharacteristic

?

+1


source to share


1 answer


You can't just create a CBMutableCharacteristic - you have to discover the CBCharacteristic or get it from the peripheral characteristics property.

If you link to the documentation you will see

CBMutableCharacteristic objects represent the characteristics of a local peripheral service (represented by local peripherals by CBPeripheralManager objects)



and

CBC specific objects, in particular, represent the characteristics of the remote peripheral service (remote peripheral represented by CBPeripheral objects)

In a comment, you indicate that you cannot detect the services and characteristics of your device - in which case I suggest you examine your detection code or add it to your question.

0


source







All Articles