I've been creating an app using XCode and Swift to connect to a bluetooth device (that has a LED colour strip connected to it) and I have written a piece of code that will make it change colour.
Using a bluetooth sniffer, I know that I need to send the value of '52130056FF000000AA' which would make it change to red, in this example. Here's a snippet of the code I have already. Characteristicx is defined before this code.
let data: NSData = "52130056FF000000AA".dataUsingEncoding(NSUTF8StringEncoding)!
peripheral.writeValue(data, forCharacteristic: characteristicx, type: CBCharacteristicWriteType.WithoutResponse)
If you don't insist on using a hex string then the easiest solution would be to create the data from an array with hex integer values:
let bytes : [UInt8] = [ 0x52, 0x13, 0x00, 0x56, 0xFF, 0x00, 0x00, 0x00, 0xAA ] let data = NSData(bytes: bytes, length: bytes.count)