/OBD2_BLE

Primary LanguageSwiftMIT LicenseMIT

OBD2_BLE

CI Status Version License Platform

OBD2_BLE is a Swift framework for interfacing with OBD-II devices using iOS Bluetooth Low Energy capabilities.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

OBD2_BLE is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "OBD2_BLE"

Usage

Initialization

import OBD2_BLE

...

let obd2 = OBD2_BLE.sharedInstance

OBD2_BLE is implemented as a Singleton class.

iOS BLE Background Processing

override func viewDidLoad() {
    super.viewDidLoad()
	
    OBD2_BLE.setup(restoreId: "myAppID.Bluetooth.RestoreID")
    let obd2 = OBD2_BLE.sharedInstance
}

Properties

iOS CoreBluetooth Objects
var centralManager: CBCentralManager!
var obd2: CBPeripheral?
var dataCharacteristic:CBCharacteristic?
obdCommands Dictionary
var obdCommands:[String: String]! = [
    "speed": "010D",
    "rpm": "010C",
    "engineLoad": "0104",
    "coolantTemp": "0105",
    "vin": "0902"
]

OBD-II PIDs

configurationCommands Dictionary
var configurationCommands = [
    "ATE0", // Echo Off
    "ATH0", // Headers Off
    "ATS0", // printing of Spaces Off
    "ATL0", // Linefeeds Off
    "ATSP0" // Set Protocol to 0 (Auto)
]

ELM327 AT Commands

Configuration

  • createCommand(name: String, command: String)

  • clearConfigurationCommands()

  • setConfigurationCommands(commands: [String])

  • addConfigurationCommands(commands: [String])

  • configureOBD()

Requesting Data

  • getVin()

  • getSpeed()

  • sendCommandNamed(name: String)

  • getVehicleInfo(vinNumber: String, completion: @escaping (_ vehicleInfo: [String: Any]) -> ())

Author

Nick Nordale, nicknordale@gmail.com

License

OBD2_BLE is available under the MIT license. See the LICENSE file for more info.