{"id":18643545,"url":"https://github.com/lemberg/obd2-swift-lib","last_synced_at":"2025-07-05T04:08:07.326Z","repository":{"id":39617161,"uuid":"92273032","full_name":"lemberg/obd2-swift-lib","owner":"lemberg","description":"car onboard diagnostic swift library ","archived":false,"fork":false,"pushed_at":"2019-07-17T23:38:19.000Z","size":1015,"stargazers_count":154,"open_issues_count":11,"forks_count":40,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-06-28T12:58:22.178Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lemberg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-24T09:12:00.000Z","updated_at":"2025-06-10T10:56:40.000Z","dependencies_parsed_at":"2022-09-15T21:41:50.856Z","dependency_job_id":null,"html_url":"https://github.com/lemberg/obd2-swift-lib","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/lemberg/obd2-swift-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemberg%2Fobd2-swift-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemberg%2Fobd2-swift-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemberg%2Fobd2-swift-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemberg%2Fobd2-swift-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lemberg","download_url":"https://codeload.github.com/lemberg/obd2-swift-lib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemberg%2Fobd2-swift-lib/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263679416,"owners_count":23495047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T06:07:19.954Z","updated_at":"2025-07-05T04:08:07.289Z","avatar_url":"https://github.com/lemberg.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OBD2 Swift\n\n[![GitHub Release](https://img.shields.io/badge/release-none-red.svg)](https://github.com/lemberg/obd2-swift-lib)\n[![Swift Version](https://img.shields.io/badge/Swift-4.0%2B-orange.svg?style=flat)](https://github.com/lemberg/obd2-swift-lib) \n[![GitHub Platforms](https://img.shields.io/badge/platform-ios%20%7C%20macos%20-brightgreen.svg)](https://github.com/lemberg/obd2-swift-lib)\n[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://github.com/lemberg/obd2-swift-lib/blob/dev/LICENSE) \n[![By](https://img.shields.io/badge/By-Lemberg%20Solutions%20Limited-blue.svg?style=flat)](http://cocoapods.org/pods/PermissionsService)\n\nOn-board diagnostics swift library. \n\n* [Why do you need it?](https://github.com/lemberg/obd2-swift-lib#why-you-need-it)\n* [Requirements](https://github.com/lemberg/obd2-swift-lib#requirements)\n* [Features](https://github.com/lemberg/obd2-swift-lib#features)\n* [How To Use](https://github.com/lemberg/obd2-swift-lib#how-to-use)\n   * [Create connection](https://github.com/lemberg/obd2-swift-lib#where-to-start)\n   * [Getting metrics](https://github.com/lemberg/obd2-swift-lib#and-what-about-getting-metrics)\n   * [Observing](https://github.com/lemberg/obd2-swift-lib#ok-but-what-about-monitoring)\n* [Installation](https://github.com/lemberg/obd2-swift-lib#installation)\n   * [As Embedded Framework](https://github.com/lemberg/obd2-swift-lib#manually-as-embedded-framework)\n   * [CocoaPods](https://github.com/lemberg/obd2-swift-lib#cocoapods)\n* [Author](https://github.com/lemberg/obd2-swift-lib#author)\n* [License](https://github.com/lemberg/obd2-swift-lib#license)\n\n## Why do you need it?\n\n#### OBD2?.. What?\nOBD or On-board diagnostics is a vehicle's self-diagnostic and reporting capability. OBD systems give access to the status of the various vehicle subsystems. \nSimply saying, OBD-II is a sort of computer which monitors emissions, mileage, speed, and other useful data.\n \n\u003e More details you can get [here](https://en.wikipedia.org/wiki/On-board_diagnostics). \n\n#### Ok. And what about this?\n\nThis is a library which can communicate with vehicles using OBD-II adapters. It is providing you with an opportunity for real-time vehicles diagnostics with several lines of code and without being nervous. The library will help you to connect with adapter and handle it's behaviour, like reconnect when something went wrong. And! You don't need to parse bytes response returned from adapter by yourself because OBD2 Swift will do it for your project. \n\n## Requirements\n\n- iOS 9.0+\n- Swift 3.0+\n- Xcode 8.0+\n- Mac OS X 10.0+ \n\n## Features\n\n- [x] Supporting next Modes with almost all their PIDs:\n\nMode | Description\n-----| -----------\nMode 01(02) | Sensors / Freeze Frame\nMode 03 | Trouble Codes (DTC)\nMode 04 | Reset Trouble Codes\nMode 09 | Information\n \n- [x] Real-time connection with OBD-II\n- [x] OBD-II full described diagnostic sensors list\n- [x] Observer of connection and other metrics\n- [x] Several types of returning \u0026 requesting diagnostic response\n- [x] Logger, which can save your logs into a file and share it\n\n## How to use? \n\n#### Where to start? \n\nFirst of all, create an `OBD2` object for requesting vehicles metrics. \n\n```swift\n     let obd = OBD2()\n```\n\nCreate a connection between your application and adapter. \n\n\u003e :exclamation: Remember that **all callbacks return not in the main thread**.   \n\n ```swift\n      obd.connect { [weak self] (success, error) in\n              if let error = error {\n                  print(\"OBD connection failed with \\(error)\")\n\n              } else {\n                  //perform something\n              }\n        }\n```\nMethod `connect` would return you a response with an error if something went wrong and you can simply handle it, for example, show a message with reconnecting opportunity.  \n\nIf all goes okay, you have a connection! :sunglasses:\n\n\u003e Class `OBD2` contain another methods for work with connection like `pauseScan()`, `resumeScan()` and `stopScan()` as well.     \n\n#### And what about getting metrics?\n\nThere is a simple way to get data from vehicle subsystems - to use requests. You can send it using `request(_:)` method of `OBD2 ` object. Use `struct Command` for choosing what you want to request. \n\n```swift\n      obd.request(command: Command.Mode09.vin) { (descriptor) in\n            let respStr = descriptor?.VIN()\n            print(respStr ?? \"No value\")\n        }\n```\n\n#### What if I want to get another response? \n\nYou can use `request(_:)` method with `emun Custom: CommandType`. It helps you to send and get data in `digit` and `string` format. \n\n ```swift\n       obd.request(command: Command.Custom.digit(mode: 09, pid: 02)) { (descr) in\n            if let response = descr?.response {\n                print(response)\n            } \n        }\n```\n\n#### Ok, but what about monitoring? \n\nYou can still use requests for doing this. There is a method `request(repeat:)` wich will send a request to OBD repeatedly.  \n\n ```swift\n      obd.request(repeat: Command.Mode01.pid(number: 12))\n```\n\n#### Where is a response?! :scream: \n\nResponse from this method will be returned to `Observer`. Choose `Mode` type and create an `Observer` object.  \n\n```swift\n      let observer = Observer\u003cCommand.Mode01\u003e()\n```\n\nTell him to observe with specific PID number and enjoy responses. :]  \n\n```swift\n      observer.observe(command: .pid(number: 12)) { (descriptor) in\n          let respStr = descriptor?.shortDescription\n          print(\"Observer : \\(respStr)\")\n      }\n```\n\n\u003e :exclamation: To bring `Observer` alive you must register it in `ObserverQueue`. It is needed for returning diagnostics responses.  \n\u003e\n\u003e ```swift\n\u003e     ObserverQueue.shared.register(observer: observer)\n\u003e```\n\u003e Don't forget to do `unregister(_:)` when you don't need `Observer` anymore.  \n\n#### How to stop it?\n\n`OBD2` object has method `isRepeating(repeat:)` wich takes `Command` as a parameter. Using it you can check if the specific command is repeating now and stop it.\n\n```swift\n       if obd.isRepeating(repeat: Command.Mode01.pid(number: 12)) {\n           obd.stop(repeat: command)\n       } \n```\n\n#### Can I use observer for other requests?\n\nYep! Single request method can take `Bool` parameter `notifyObservers` wich is `true` by default. Using it you can manage which requests will return response not only in completion block but in observer block too. \n\n## Installation\n\n### Manually as Embedded Framework\n\n* Go to your project root git folder and clone OBD2 Swift as a git [submodule](https://git-scm.com/docs/git-submodule) by running the following command from the terminal.\n\n```swift\n$ git submodule add https://github.com/lemberg/obd2-swift-lib.git\n```\n\n* Open obd2-swift-lib folder which was created. In the OBD2-Swift folder, you will found OBD2Swift.xcodeproj. Drag it into the Project Navigator of your project.\n\n* Select your project in the Xcode Navigation and then select your application target from the sidebar. After this, select the \"General\" tab and click on the + button under the \"Embedded Binaries\" section.\n\n* Select OBD2 Swift.framework from dialogue and that's all!  :tada:\n\n\u003e Don't forget to do `import OBD2Swift` in classes where you want to use this framework\n\n### CocoaPods\n\nTo install it, simply add this line to your Podfile:\n\n```swift\n  pod \"OBD2-Swift\"\n```\n\n\u003e If you'll need, there is still a version written on **Swift 3** named `swift3`. \n\nNow you need to run `pod update` command from you project folder and that's it!\n\n## Author\n\n### [Lemberg Solutions](http://lemberg.co.uk) \n[![Logo](http://lemberg.co.uk/sites/all/themes/lemberg/images/logo.png)](https://github.com/lemberg) \n\n## License\n\nOBD2 Swift is available under the [MTI license](https://directory.fsf.org/wiki/License:MTI). See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemberg%2Fobd2-swift-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flemberg%2Fobd2-swift-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemberg%2Fobd2-swift-lib/lists"}