0

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?

1 Answer 1

0

This turns out to be a device specific "feature". The scanner doesn't return a response to a characteristic write but I still get a call back so the data is just stale. And testing shows the configuration strings never got to the scanner. Solution for this case is to send data ".withoutResponse".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.