{"id":13961679,"url":"https://github.com/codeinversion/sensors-swift","last_synced_at":"2025-07-14T22:37:45.461Z","repository":{"id":46820493,"uuid":"54212981","full_name":"codeinversion/sensors-swift","owner":"codeinversion","description":"Bluetooth LE Sensor Manager for iOS and macOS","archived":false,"fork":false,"pushed_at":"2023-12-18T14:30:24.000Z","size":326,"stargazers_count":55,"open_issues_count":3,"forks_count":39,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-05T03:18:00.461Z","etag":null,"topics":["ble","bluetooth-le","bluetooth-low-energy","cocoapod","ios","macos","sensors","swift","swift-3","swift3"],"latest_commit_sha":null,"homepage":"","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/codeinversion.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":"2016-03-18T15:44:17.000Z","updated_at":"2025-01-30T12:15:30.000Z","dependencies_parsed_at":"2022-09-03T19:01:00.457Z","dependency_job_id":null,"html_url":"https://github.com/codeinversion/sensors-swift","commit_stats":null,"previous_names":["kinetic-fit/sensors-swift"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeinversion%2Fsensors-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeinversion%2Fsensors-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeinversion%2Fsensors-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeinversion%2Fsensors-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeinversion","download_url":"https://codeload.github.com/codeinversion/sensors-swift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280357,"owners_count":20912986,"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","bluetooth-le","bluetooth-low-energy","cocoapod","ios","macos","sensors","swift","swift-3","swift3"],"created_at":"2024-08-08T17:01:21.090Z","updated_at":"2025-04-09T23:24:14.035Z","avatar_url":"https://github.com/codeinversion.png","language":"Swift","readme":"# Swifty Sensors\n![iOS](https://img.shields.io/badge/iOS-8.2%2B-blue.svg)\n![macOS](https://img.shields.io/badge/macOS-10.11%2B-blue.svg)\n![Swift 3.0](https://img.shields.io/badge/swift-3.0-orange.svg)\n![License](https://img.shields.io/badge/license-MIT-lightgrey.svg)\n[![CocoaPods](https://cocoapod-badges.herokuapp.com/v/SwiftySensors/badge.svg)](https://cocoapods.org/pods/SwiftySensors)\n\nBluetooth LE Sensor Manager for iOS and macOS.\n\n[Full API Documentation](http://cocoadocs.org/docsets/SwiftySensors/)\n\n## Installation\n### CocoaPods\n```\nuse_frameworks!\npod 'SwiftySensors'\n```\n### Manual\nCopy all of the swift files in the `Sources` directory into you project.\n\n### Swift Package Manager\nAdd this repo url to your dependencies list:\n```\ndependencies: [\n    .Package(url: \"https://github.com/kinetic-fit/sensors-swift\", Version(X, X, X))\n]\n```\n*Note: If you are using the [Swifty Sensors Kinetic Plugin](https://github.com/kinetic-fit/sensors-swift-kinetic), you cannot use the Swift Package Manager at this time due to no support for objective-c libraries.*\n\n## Usage\n\nSee the Example iOS App for a basic example of:\n- scanning for **sensors**\n- connecting to **sensors**\n- discovering **services**\n- discovering **characteristics**\n- reading values\n- **characteristic** notifications\n\nInitialization of a SensorManager is straightforward.\n\n1. Set the **services** you want to scan for\n2. Add additional **services** you want to discover on *sensor* (but not scan for in advertisement data)\n3. Set the **scan mode** of the manager\n\n```\n// Customize what services you want to scan for\nSensorManager.instance.setServicesToScanFor([\n    CyclingPowerService.self,\n    CyclingSpeedCadenceService.self,\n    HeartRateService.self\n])\n\n// Add additional services we want to have access to (but don't want to specifically scan for)\nSensorManager.instance.addServiceTypes([DeviceInformationService.self])\n\n// Set the scan mode (see documentation)\nSensorManager.instance.state = .aggressiveScan\n\n// Capture SwiftySensors log messages and print them to the console. You can inject your own logging system here if desired.\nSensorManager.logSensorMessage = { message in\n    print(message)\n}\n```\n\nSwiftySensors uses [Signals](https://github.com/artman/Signals) to make observation of the various events easy.\n```\n// Subscribe to Sensor Discovery Events\nSensorManager.instance.onSensorDiscovered.subscribe(on: self) { sensor in\n    // sensor has been discovered (but not connected to yet)\n}\n\n// Subscribe to value changes on a Characteristic\ncharacteristic.onValueUpdated.subscribe(on: self) { characteristic in\n    // characteristic.value was just updated\n}\n```\n\nAll Services and Characteristics are concrete classes to make working with Bluetooth LE sensors much easier.\n\nExample Heart Rate Sensor Hierarchy:\n```\nSensor\n    - HeartRateService\n        - Measurement\n        - BodySensorLocation\n    - DeviceInformationService\n        - SoftwareRevision\n        - ModelNumber\n        - SerialNumber\n        - ...\n```\n\nTo connect to a Sensor:\n```\nSensorManager.instance.connectToSensor(sensor)\n```\n\nSubscribing to value updates and getting the deserialized value of a Heart Rate Sensor:\n```\n// The sensor could be selected by a user, selected by a matching algorithm on the sensor's advertised services, etc.\nlet sensor = \u003c Heart Rate Sensor \u003e\n\n// The function service() on a sensor will try to find the appropriate return type requested\nguard let hrService: HeartRateService = sensor.service() else { return }\n\n// The function characteristic() on a service will try to find the appropriate return type requested\nguard let hrMeasurement: HeartRateService.Measurement = hrService.characteristic() else { return }\n// ... the HeartRateService class also defines the `measurement` property, which is equivalent to the above\n\nhrMeasurement.onValueUpdated.subscribe(on: self) { characteristic in\n    // The Measurement characteristic has a deserialized value of the sensor data\n    let heartRate = hrMeasurement.currentMeasurement.heartRate    \n}\n```\n\n## Current Concrete Services and Characteristics\n- [Cycling Power](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.cycling_power.xml)\n  - [Measurement](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.cycling_power_measurement.xml)\n  - [Feature](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.cycling_power_feature.xml)\n  - [Sensor Location](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.sensor_location.xml)\n  - [Control Point](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.cycling_power_control_point.xml)\n- [Cycling Speed and Cadence](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.cycling_speed_and_cadence.xml)\n  - [Measurement](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.csc_measurement.xml)\n  - [Feature](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.csc_feature.xml)\n  - [Sensor Location](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.sensor_location.xml)\n- [Heart Rate](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.heart_rate.xml)\n  - [Measurement](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.heart_rate_measurement.xml)\n  - [Body Sensor Location](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.body_sensor_location.xml)\n  - [Control Point](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=heart_rate_control_point.xml)\n- [Device Information](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.device_information.xml)\n  - [ManufacturerName](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.manufacturer_name_string.xml)\n  - [ModelNumber](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.model_number_string.xml)\n  - [SerialNumber](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.serial_number_string.xml)\n  - [HardwareRevision](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.hardware_revision_string.xml)\n  - [FirmwareRevision](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.firmware_revision_string.xml)\n  - [SoftwareRevision](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.software_revision_string.xml)\n  - [SystemID](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.software_revision_string.xml)\n\n### Extensions and 3rd Party Services\n- [Wahoo Trainer Characteristic Extension](https://github.com/kinetic-fit/sensors-swift-wahoo) for the Cycling Power Service\n- [Kinetic Sensors](https://github.com/kinetic-fit/sensors-swift-kinetic)\n\n## Injecting Types; Writing Services, Characteristics, Extensions\nAdding custom functionality specific to your needs is fairly straightforward.\n\n```\n// Customize the Sensor class that the manager instantiates for each sensor\nSensorManager.instance.SensorType = \u003c Custom Sensor Class : Extends Sensor \u003e\n```\n\nLook at HeartRateService for a simple example of writing your own Service class.\n\nTo add new Characteristic types to an existing Service that is not a part of the official spec, take a look at the [Wahoo Trainer Characteristic Extension](https://github.com/kinetic-fit/sensors-swift-wahoo).\n**This is NOT a normal solution adopted by BLE sensor manufaturers, but occassionally they break the rules.**\n\n## Serializers\nThe serialization / deserialization of characteristic data is isolated outside of the Characteristic classes and can be used alone. This can be useful if you already have a Sensor management stack and just need the logic to correctly deserialize various BLE messages.\n```\nuse_frameworks!\npod 'SwiftySensors/Serializers'\n```\n\n## Known bugs\nNone.\n\n## ToDos\nThere are many official BLE specs that need to be implemented.\n\n## Projects Using SwiftySensors\n- [Kinetic Fit](https://itunes.apple.com/us/app/kinetic-fit/id1023388296?mt=8)\n\nLet us know if you want your App listed here!\n\n\n[Full API Documentation](http://cocoadocs.org/docsets/SwiftySensors/)\n","funding_links":[],"categories":["Swift","iOS"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeinversion%2Fsensors-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeinversion%2Fsensors-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeinversion%2Fsensors-swift/lists"}