All Projects → e-sites → Bluetonium

e-sites / Bluetonium

Licence: mit
Bluetooth mapping in Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Bluetonium

Bluetoothkit
Easily communicate between iOS/OSX devices using BLE
Stars: ✭ 2,027 (+1174.84%)
Mutual labels:  bluetooth-low-energy, bluetooth, cocoapods, carthage
Multipeer
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices
Stars: ✭ 170 (+6.92%)
Mutual labels:  bluetooth, cocoapods, carthage
Bluecap
iOS Bluetooth LE framework
Stars: ✭ 669 (+320.75%)
Mutual labels:  bluetooth-low-energy, cocoapods, carthage
Heapinspector For Ios
Find memory issues & leaks in your iOS app without instruments
Stars: ✭ 1,819 (+1044.03%)
Mutual labels:  cocoapods, carthage
Donut
Donut is a library for arranging views circularly like a donut.
Stars: ✭ 141 (-11.32%)
Mutual labels:  cocoapods, carthage
Color
Color utilities for macOS, iOS, tvOS, and watchOS
Stars: ✭ 145 (-8.81%)
Mutual labels:  cocoapods, carthage
Ble.net
Cross-platform Bluetooth Low Energy (BLE) library for Android, iOS, and UWP
Stars: ✭ 137 (-13.84%)
Mutual labels:  bluetooth-low-energy, bluetooth
Sdl ios
Get your app connected to the 🚙, make your users feel like a 🌟
Stars: ✭ 147 (-7.55%)
Mutual labels:  cocoapods, carthage
Eureka
Elegant iOS form builder in Swift
Stars: ✭ 11,345 (+7035.22%)
Mutual labels:  cocoapods, carthage
Apesuperhud
A simple way to display a HUD with a message or progress information in your application.
Stars: ✭ 156 (-1.89%)
Mutual labels:  cocoapods, carthage
Underlinetextfield
Simple UITextfield Subclass with state
Stars: ✭ 156 (-1.89%)
Mutual labels:  cocoapods, carthage
Pipkit
Picture in Picture for iOS
Stars: ✭ 140 (-11.95%)
Mutual labels:  cocoapods, carthage
Ducttape
📦 KeyPath dynamicMemberLookup based syntax sugar for Swift.
Stars: ✭ 138 (-13.21%)
Mutual labels:  cocoapods, carthage
Sffocusviewlayout
UICollectionViewLayout with focused content
Stars: ✭ 1,760 (+1006.92%)
Mutual labels:  cocoapods, carthage
Closures
Swifty closures for UIKit and Foundation
Stars: ✭ 1,720 (+981.76%)
Mutual labels:  cocoapods, carthage
Auth0.swift
Swift toolkit for Auth0 API
Stars: ✭ 146 (-8.18%)
Mutual labels:  cocoapods, carthage
Node Ble
Bluetooth Low Energy (BLE) library written with pure Node.js (no bindings) - baked by Bluez via DBus
Stars: ✭ 159 (+0%)
Mutual labels:  bluetooth-low-energy, bluetooth
Cdmarkdownkit
An extensive Swift framework providing simple and customizable markdown parsing.
Stars: ✭ 158 (-0.63%)
Mutual labels:  cocoapods, carthage
Easyble
Android BLE framework
Stars: ✭ 155 (-2.52%)
Mutual labels:  bluetooth-low-energy, bluetooth
Contentful.swift
A delightful Swift interface to Contentful's content delivery API.
Stars: ✭ 132 (-16.98%)
Mutual labels:  cocoapods, carthage

Bluetonium: Bluetooth library in Swift

Bluetonium is part of the E-sites iOS Suite.


Bluetonium is a Swift Library that makes it easy to communicate with Bluetooth devices.

forthebadge forthebadge forthebadge

Build Status CocoaPods Compatible codecov Carthage compatible Platform Quality

Features

  • [x] 🎲 Services and characteristics mapping
  • [x] 👓 Default data transformers
  • [x] 🔧 Reading & writing to peripherals
  • [x] 🌔 Background mode
  • [x] 📻 Scanning and connecting to peripherals
  • [x] 🦅 Swift 3 & 4

Requirements

  • iOS 8.0+
  • Xcode 7.2+

Installation

CocoaPods

Add the following to your Podfile:

pod 'Bluetonium'

Make sure that you are integrating your dependencies using frameworks: add use_frameworks! to your Podfile. Then run pod install.

Carthage

Add the following to your Cartfile:

github "e-sites/Bluetonium"

Run carthage update and follow the steps as described in Carthage's README.

Usage

Get devices

The Manager will handle searching for devices and connecting to them.

import Bluetonium

let manager = Manager()
manager.delegate = self
manager.startScanForDevices()

If a device is found you will get notified by the func manager(_ manager: Manager, didFindDevice device: Device) delegate call. You can also get all found devices in the foundDevices array of your manager.

Connect to a device

Connecting to a device is simple.

manager.connect(with: device)

The device is a device form the foundDevices array.

Create and register a ServiceModel

A ServiceModel subclass will represents a Service, all the properties represent the Characteristics.

This example represents the Battery Service

class BatteryServiceModel: ServiceModel {
	enum Characteristic : String {
		case batteryLevel = "2A19"
	}

	var batteryLevel: UInt8 = 0
	
	override var serviceUUID:String {
		return "180F"
	}
	
	override func mapping(_ map: Map) {
		batteryLevel <- map[Characteristic.batteryLevel.rawValue]
	}
	
}

Register a ServiceModel subclass. Make sure you do this before the device is actually connected.

let batteryServiceModel = BatteryServiceModel()

func manager(_ manager: Manager, willConnectToDevice device: Device) {
	device.register(serviceModel: batteryServiceModel)
}

ServiceModel subclass

A ServiceModel subclass will represents a Service, all the properties represent the Characteristics. Interacting with the peripheral is only possible once the characteristic did became available through the func characteristicBecameAvailable(withUUID UUID: String) function.
Or when the serviceReady boolean is set to true.

It's recommended to create a struct containing static properties of the UUID's along with your ServiceModel this way your app doesn't have to hardcode the UUID in different places and prevents errors. (See example: HeartRateServiceModel in project)

Reading

batteryServiceModel.readValue(withUUID: "2A19")

// Or with completion
batteryServiceModel.readValue(withUUID: "2A19") { value in
	print(value)
}

Writing

batteryServiceModel.batteryLevel = 10
batteryServiceModel.writeValue(withUUID: "2A19")

Custom DataTransformers

It is possible that your characteristic has a custom data format or has a data format not yet supported. Then you can create your own custom DataTransformer for that property.

The custom DataTransformer needs to conform to the DataTransformer protocol which has two functions.

class HeartRateDataTransformer: DataTransformer {
    
    func transform(dataToValue data: Data?) -> MapValue {
    	// Used when reading from the characteristic.
    	// Transform Data to your property MapValue.
    }
    
    func transform(valueToData value: MapValue?) -> Data {
    	// Used when writing to the characteristic.
    	// Transform your property MapValue to Data.
    }
    
}

To register your custom DataTransform you can add it to the mapping function:

func mapping(_ map: Map) {
	heartRate <- (map["2A37"], HeartRateDataTransformer())
}

Set notifications for a characteristic

The ServiceModel has a function that will let you register for value changes on the peripheral. When you return true for one of you characteristics it will automatically update the property.

func registerNotifyForCharacteristic(withUUID UUID: String) -> Bool

Contributions

Feedback is appreciated and pull requests are always welcome. Let's make this list longer!

License

Bluetonium is released under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].