{"id":13961678,"url":"https://github.com/FitnessKit/BluetoothMessageProtocol","last_synced_at":"2025-07-21T06:31:44.326Z","repository":{"id":47286614,"uuid":"100875392","full_name":"FitnessKit/BluetoothMessageProtocol","owner":"FitnessKit","description":"Swift Implementation of Bluetooth Message Protocols.  Encode and Decode BLE Characteristics","archived":false,"fork":false,"pushed_at":"2022-03-12T15:35:02.000Z","size":302692,"stargazers_count":45,"open_issues_count":0,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-18T05:07:08.379Z","etag":null,"topics":["ble","blemesh","bluetooth","characteristics","decode","encoder","homekit-accessory-protocol","spm","swift","swift-package-manager"],"latest_commit_sha":null,"homepage":"https://fitnesskit.github.io/BluetoothMessageProtocol/","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/FitnessKit.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-08-20T16:50:29.000Z","updated_at":"2025-04-17T06:38:44.000Z","dependencies_parsed_at":"2022-09-10T11:01:44.882Z","dependency_job_id":null,"html_url":"https://github.com/FitnessKit/BluetoothMessageProtocol","commit_stats":null,"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"purl":"pkg:github/FitnessKit/BluetoothMessageProtocol","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FitnessKit%2FBluetoothMessageProtocol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FitnessKit%2FBluetoothMessageProtocol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FitnessKit%2FBluetoothMessageProtocol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FitnessKit%2FBluetoothMessageProtocol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FitnessKit","download_url":"https://codeload.github.com/FitnessKit/BluetoothMessageProtocol/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FitnessKit%2FBluetoothMessageProtocol/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266253575,"owners_count":23900052,"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":["ble","blemesh","bluetooth","characteristics","decode","encoder","homekit-accessory-protocol","spm","swift","swift-package-manager"],"created_at":"2024-08-08T17:01:21.039Z","updated_at":"2025-07-21T06:31:39.309Z","avatar_url":"https://github.com/FitnessKit.png","language":"Swift","readme":"# BluetoothMessageProtocol\n\n[![Swift5.2](https://img.shields.io/badge/swift5.2-compatible-4BC51D.svg?style=flat)](https://developer.apple.com/swift)\n[![Version](https://img.shields.io/cocoapods/v/BluetoothMessageProtocol.svg?style=flat)](http://cocoapods.org/pods/BluetoothMessageProtocol)\n[![License](https://img.shields.io/cocoapods/l/BluetoothMessageProtocol.svg?style=flat)](http://cocoapods.org/pods/BluetoothMessageProtocol)\n[![Platform](https://img.shields.io/cocoapods/p/BluetoothMessageProtocol.svg?style=flat)](http://cocoapods.org/pods/BluetoothMessageProtocol)\n[![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=https://github.com/fitnesskit/bluetoothmessageprotocol)](http://clayallsopp.github.io/readme-score?url=https://github.com/fitnesskit/bluetoothmessageprotocol)\n[![codebeat badge](https://codebeat.co/badges/e24e0c9d-0ec1-42fb-8384-30f7587559c0)](https://codebeat.co/projects/github-com-fitnesskit-bluetoothmessageprotocol-master)\n[Docs](https://fitnesskit.github.io/BluetoothMessageProtocol/)\n\nThis is not a BLE Manager for your phone.  There are plenty of those out there.  BluetoothMessageProtocol provides functions for encoding and decoding Bluetooth Characteristic data.\n\n\n## Installation\n\nBluetoothMessageProtocol is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile:\n\n```ruby\npod 'BluetoothMessageProtocol'\n```\n\nSwift Package Manager:\n```swift\ndependencies: [\n    .package(url: \"https://github.com/FitnessKit/BluetoothMessageProtocol\", from: \"2.0.1\")\n]\n```\n\n## How to Use\n\n### Services\n\nThe Service class helps to describe a BLE Service.   There is no assumption to which Characteristics the Service contains.\n\nExample Using CoreBluetooth:\n\n```swift\n\ncentralManager.scanForPeripherals(withServices: [CBUUID(string: ServiceHeartRate.uuidString),],\n                                       options: [CBCentralManagerScanOptionAllowDuplicatesKey : true])\n\n```\n\n#### Supported Services\n\n* BLE SIG Services\n* Home Kit Accessory Protocol (HAP)\n* BLE Mesh\n\n\n### Characteristic\n\nEach Bluetooth Characteristic has an encode and decode method.  When you receive the data from a sensor you call the static decode method to turn the data into a Characteristic Object as seen below in the example:\n\n```swift\nfunc peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {\n\n    if let sensorData = characteristic.value {\n        if characteristic.uuid.uuidString == CharacteristicHeartRateMeasurement.uuidString {\n            doDecodeHRMess(sensorData: sensorData)\n        }\n\n        if characteristic.uuid.uuidString == CharacteristicBodySensorLocation.uuidString {\n            doDecodeBody(sensorData: sensorData)\n        }\n    }\n}\n\nfunc doDecodeHRMess(sensorData: Data) {\n\n    let hrData: Result\u003cCharacteristicHeartRateMeasurement, BluetoothDecodeError\u003e = CharacteristicHeartRateMeasurement.decode(with: sensorData)\n\n    switch hrData {\n    case .success(let char):\n        print(\"HR: \\(char.heartRate)\")\n\n    case .failure(let error):\n        print(error)\n    }\n\n    /// Or you can stil use the doCatch\n    do {\n        let hrData = try CharacteristicHeartRateMeasurement.decode(with: sensorData).get()\n\n        print(\"HR: \\(hrData.heartRate)\")\n\n    } catch  {\n        print(error)\n    }\n}\n\nfunc doDecodeBody(sensorData: Data) {\n\n    let sensor: Result\u003cCharacteristicBodySensorLocation, BluetoothDecodeError\u003e = CharacteristicBodySensorLocation.decode(with: sensorData)\n\n    switch sensor {\n    case .success(let char):\n        print(\"Location: \\(char.sensorLocation.stringValue)\")\n\n    case .failure(let error):\n        print(error)\n    }\n\n    /// Or you can stil use the doCatch\n    do {\n        let sensor = try CharacteristicBodySensorLocation.decode(with: sensorData).get()\n\n        print(\"Location: \\(sensor.sensorLocation.stringValue)\")\n\n    } catch  {\n        print(error)\n    }\n}\n```\n\n### Manufacturer Specific Data\n\nManufacturer Specific data contains a Company Assigned Number and specific data defined by the Manufacturer.  \n\nExample using Apple iBeacon:\n\n```swift\nfunc centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {\n\n    if let advertData = advertisementData[CBAdvertisementDataManufacturerDataKey] as? Data {\n\n        switch ManufacturerDataAppleiBeacon.decode(with: advertData) {\n        case .success(let beacon):\n            print(beacon.proximityUUID.uuidString)\n\n        case .failure(let error):\n            print(error)\n\n        }\n\n        /// Or you can stil use the doCatch\n        if let beacon = try? ManufacturerDataAppleiBeacon.decode(with: advertData).get() {\n            print(beacon.proximityUUID.uuidString)\n        }\n    }\n}\n```\n\n#### Manufacturer Specific Data\n\n* Apple iBeacon\n* AltBeacon\n* HomeKit\n* HomeKit Encrypted Notification Advertisement\n* Polar Heart Rate\n\n\n## Author\n\nThis package is developed and maintained by Kevin A. Hoogheem\n\n## License\n\nBluetoothMessageProtocol is available under the [MIT license](http://opensource.org/licenses/MIT)\n","funding_links":[],"categories":["Swift"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFitnessKit%2FBluetoothMessageProtocol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFitnessKit%2FBluetoothMessageProtocol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFitnessKit%2FBluetoothMessageProtocol/lists"}