Hello together,
my name is André. I never used something like this before but lets try:
I am trying to setup an BLE communication between Arduino and iPhone. To get started I used the following tutorial by Jared Wolff:
https://www.freecodecamp.org/news/ultimate-how-to-bluetooth-swift-with-hardware-in-20-minutes/
Everything is working fine beside of one thing. The connection to the Arduino works well, but the Data transfer does not work. I figured out that one if-condition is not satisfied and that’s why no data is sent to the Arduino. It is this part of the code ( if characteristic.properties.contains(.writeWithoutResponse) ) which is not satisfied and that why the function peripheral.writeValue can not be called.
private func writeLEDValueToChar( withCharacteristic characteristic: CBCharacteristic, withValue value: Data) {
// Check if it has the write property
if characteristic.properties.contains(.writeWithoutResponse) && peripheral != nil {
peripheral.writeValue(value, for: characteristic, type: .withoutResponse)
}
}
I had the idea to ignore the if-condition and just call the function peripheral.writeValue but then Xcode throws an error and reminds me that I am sending data without making sure the peripheral hast the property mentioned in the if condition. Xcode then sets the value I want to send to null so that again nothing is sent. The error message looks like the following:
[CoreBluetooth] WARNING: Characteristic <CBCharacteristic: 0×281964f00, UUID = 19B10011-E8F2-537E-4F6C-D104768A1214, properties = 0xA, value = (null), notifying = NO> does not specify the “Write Without Response” property - ignoring response-less write
Maybe someone know this problem or knows the solution for this. I would be very grateful for any help. Thank you so much.
Greetings from Germany
André