Search code examples
iosswiftcore-bluetoothobd-ii

Carista OBD || device communications with iOS Device


I have just starting communicate with Carista device. I got all services and characteristics. But when I write command "ATZ" then it will give answer as "ATZ".

My actual result which I expect from device is "ATZELM327 v1.5"

Here I have attached my code review it.

func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
    guard let characteristics = service.characteristics else { return }
    for characteristic in characteristics {
        print(characteristic)
        caristaPeripheral.setNotifyValue(true, for: characteristic)
        let ATZCommand = "ATZ"
        let ATZBytes = ATZCommand.data(using: .utf8)
        caristaPeripheral.writeValue(ATZBytes!, for: characteristic, type: .withResponse)
    }
}


func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {

    let string = String(data: characteristic.value!, encoding: .utf8)

    print("CBCharacteristic : \(characteristic.uuid) ====> \(string ?? "none")")

}

Please guide me.


Solution

  • I have found solutions and it's below. When we write any command in Carista device at this time we need to append "\r\n". So as per above question we need to replace let ATZCommand = "ATZ" to let ATZCommand = "ATZ\r\n".

    Now I got accurate response from Carista device as per exception.

    Thanks....:)