I'm confused by this because I believe I am writing to the correct LED Characteristic. The code looks like:
...
if characteristic.properties.contains(.write) {
if (characteristic.uuid.uuidString == "EF680301-9B35-4933-9B10-52FFA9740042") {
print("peripheral = \(peripheral)")
print("UUID \(characteristic.uuid)- properties contains .write")
print("write new settings to \(characteristic)")
writeCharacteristic( peripheral: peripheral, withCharacteristic: characteristic, withValue: Data([0x01]))
}
}
The writeCharacteristic code looks like:
func writeCharacteristic( peripheral: CBPeripheral, withCharacteristic characteristic: CBCharacteristic, withValue value: Data) {
print("writeCharacteristic, peripheral = \(peripheral)")
print("writeCharacteristic, characteristic = \(characteristic)")
peripheral.writeValue(value, for: characteristic, type: .withResponse)
}
When I run this, it reports:
peripheral = <CBPeripheral: 0x2803b4000, identifier = 1B95385C-92A1-EC75-476F-6C3AFBCB511A, name = Thingy, state = connected>
UUID EF680301-9B35-4933-9B10-52FFA9740042- properties contains .write
write new settings to <CBCharacteristic: 0x2816b4600, UUID = EF680301-9B35-4933-9B10-52FFA9740042, properties = 0xA, value = (null), notifying = NO>
writeCharacteristic, peripheral = <CBPeripheral: 0x2803b4000, identifier = 1B95385C-92A1-EC75-476F-6C3AFBCB511A, name = Thingy, state = connected>
writeCharacteristic, characteristic = <CBCharacteristic: 0x2816b4600, UUID = EF680301-9B35-4933-9B10-52FFA9740042, properties = 0xA, value = (null), notifying = NO>
When 'didWriteValueFor' is called, it reports:
Error for: <CBPeripheral: 0x2803b4000, identifier = 1B95385C-92A1-EC75-476F-6C3AFBCB511A, name = Thingy, state = connected>
characteristic: <CBCharacteristic: 0x2816b4600, UUID = EF680301-9B35-4933-9B10-52FFA9740042, properties = 0xA, value = {length = 5, bytes = 0x020214ac0d}, notifying = NO>
Error discovering services: Optional(Error Domain=CBATTErrorDomain Code=3 "Writing is not permitted." UserInfo={NSLocalizedDescription=Writing is not permitted.})
and the LED isn't updated (I am just trying to set it to a solid color, not breathing, writing 0x01) I assume I am doing something wrong regarding the characteristic I am using but can't figure it out, any assistance someone could provide would be very much appreciated!