I have a working BLE app that reads data from a scanner and am sending configuration to the scanner before reading begins. I use the following code to send a string to the scanner.
let configItem = "BD1"
let data = configItem?.data(using: String.Encoding.ascii)
peripheral.writeValue(data!, for: characteristic, type: .withResponse)
I print the characteristic name and value in the call back
func peripheral(_:didWriteValueFor:CBCharacteristic:Error?)
{
let value = String(data: characteristic.value!, encoding: .ascii)!
print("Wrote characteristic value: " + value + "; for characterisitc: " + characteristic.uuid.description)
}
The printed value is not the configuration data I wrote but some old scanner read data. Surprisingly the same old read data is even there after the app is closed.
So is the characteristic sent in the call back valid and does it contain the data that was written?