title: OBD2 BLE Communication - how to send AT commands and receive data
body: <p>I have a OBD2 dongle and need to get the speed of a vehicle through it (using BLE and iOS device). The documentation that came with the dongle didn't mention services and characteristics but with some debugging I discovered a few. Let's call them service 1, 2, 3. </p>
  
  <ol>
  <li>Service 1 has one characteristic with Read property and WriteWithoutResponse property</li>
  <li>Service 2 has one characteristic with Read property and Notify property</li>
  <li>Service 3 has two characteristics: Characteristic A with Read property and Notify property and Characteristic B with Write property and WriteWithoutResponse property</li>
  </ol>
  
  <p>How to know which characteristic/s I need to send AT commands and receive the corresponding data and then how to initiate this communication. I need to be able to get the speed in particular. Thank you in advance. </p>
  
  <p>I have tried the following but nothing happened:</p>
  
  <pre><code>func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
  
      for characteristic in service.characteristics! {
  
          if characteristic.properties.contains(.notify) {
              peripheral.setNotifyValue(true, for: characteristic)
          }
  
          if characteristic.properties.contains(.write) {
              let commandString = "010D\r"
              if let commandData = commandString.data(using: .utf8) {
                  peripheral.writeValue(commandData, for: characteristic, type: .withoutResponse)
                  peripheral.writeValue(commandData, for: characteristic, type: .withResponse)
              }
          }
  
      }
  }
  </code></pre>
  
  <p>And then expecting something in:</p>
  
  <pre><code>func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) {
  
      if let value = characteristic.value {
          let text = String(data: value, encoding: String.Encoding.utf8)
          self.onNotifyReceived(text)
      }
  
  } 
  </code></pre>