All Projects → RobotPajamas → SwiftyTeeth

RobotPajamas / SwiftyTeeth

Licence: Apache-2.0 license
A simple, lightweight library intended to take away some of the cruft and tediousness of using CoreBluetooth

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to SwiftyTeeth

GATT
Bluetooth Generic Attribute Profile (GATT) for Swift (Supports Linux)
Stars: ✭ 48 (+128.57%)
Mutual labels:  bluetooth, bluetooth-low-energy, corebluetooth
Bluetooth
Cross-platform Bluetooth API for Go and TinyGo.
Stars: ✭ 246 (+1071.43%)
Mutual labels:  bluetooth, bluetooth-low-energy
Gatt Python
Bluetooth GATT SDK for Python
Stars: ✭ 233 (+1009.52%)
Mutual labels:  bluetooth, bluetooth-low-energy
BLE
No description or website provided.
Stars: ✭ 25 (+19.05%)
Mutual labels:  bluetooth, bluetooth-low-energy
Radareeye
A tool made for specially scanning nearby devices[BLE, Bluetooth & Wifi] and execute our given command on our system when the target device comes in-between range.
Stars: ✭ 218 (+938.1%)
Mutual labels:  bluetooth, bluetooth-low-energy
Python Bluezero
A simple Python interface to Bluez
Stars: ✭ 222 (+957.14%)
Mutual labels:  bluetooth, bluetooth-low-energy
py-bluetooth-utils
Python module containing bluetooth utility functions, in particular for easy BLE scanning and advertising
Stars: ✭ 60 (+185.71%)
Mutual labels:  bluetooth, bluetooth-low-energy
H Ble
Android Ble类库,基于回调,暴露搜索、连接、发送、接收、断开连接等接口,无需关心细节操作即可进行Ble通信。
Stars: ✭ 171 (+714.29%)
Mutual labels:  bluetooth, bluetooth-low-energy
ESP32 Thing Plus
ESP32 Thing-compatible board using the WROOM module and a QWIIC connector.
Stars: ✭ 18 (-14.29%)
Mutual labels:  bluetooth, bluetooth-low-energy
coBlue
Use Bluetooth Low Energy for remote commands, file transfer, Based on bluez Bluetooth protocol stack (BLE Terminal)
Stars: ✭ 41 (+95.24%)
Mutual labels:  bluetooth, corebluetooth
angular-web-bluetooth-starter
A Starter for the Angular Web Bluetooth module
Stars: ✭ 15 (-28.57%)
Mutual labels:  bluetooth, bluetooth-low-energy
Continuity
Apple Continuity Protocol Reverse Engineering and Dissector
Stars: ✭ 180 (+757.14%)
Mutual labels:  bluetooth, bluetooth-low-energy
Androidbluetoothlibrary
A Library for easy implementation of Serial Bluetooth Classic and Low Energy on Android. 💙
Stars: ✭ 171 (+714.29%)
Mutual labels:  bluetooth, bluetooth-low-energy
DroneJS
A Node.js based library for controlling a Parrot minidrone. This library also provides the feature to take pictures from the drone, download them all at a time and delete them whenever required.
Stars: ✭ 19 (-9.52%)
Mutual labels:  bluetooth, bluetooth-low-energy
Reactivebeacons
Android library scanning BLE beacons nearby with RxJava
Stars: ✭ 171 (+714.29%)
Mutual labels:  bluetooth, bluetooth-low-energy
bluetooth-terminal
ES6 class for serial communication with your own Bluetooth Low Energy (Smart) devices
Stars: ✭ 43 (+104.76%)
Mutual labels:  bluetooth, bluetooth-low-energy
ble-serial
"RFCOMM for BLE" a UART over Bluetooth low energy (4.0+) bridge for Linux, Mac and Windows
Stars: ✭ 134 (+538.1%)
Mutual labels:  bluetooth, bluetooth-low-energy
Airpodsbattery Monitor For Mac
Simple Widget to display your AirPods battery levels from the Mac Status bar
Stars: ✭ 165 (+685.71%)
Mutual labels:  bluetooth, bluetooth-low-energy
Bluetoothkit
Easily communicate between iOS/OSX devices using BLE
Stars: ✭ 2,027 (+9552.38%)
Mutual labels:  bluetooth, bluetooth-low-energy
ble
Bluetooth Low Energy for Linux / macOS
Stars: ✭ 264 (+1157.14%)
Mutual labels:  bluetooth, bluetooth-low-energy

SwiftyTeeth

What is SwiftyTeeth?

SwiftyTeeth is a simple, lightweight library intended to take away some of the cruft and tediousness of using iOS BLE. It replaces CoreBluetooth's protocols and delegates with a callback-based pattern, and handles much of the code overhead associated with handling connections, discovery, reads/writes, and notifications. It is a spiritually similar library to Android's Blueteeth.

Both libraries were originally inspired by the simplicity and ease-of-use of LGBluetooth.

High-Level

The motivation for this library was to provide an alternate (ideally - simpler) API than what iOS offers in CoreBluetooth to reduce complexity and code overhead. Another motivator was to provide an API that might make more sense 'practically' than CoreBluetooth's API, which exposes underlying implementation-specifics rather than abstracting them away.

For instance, with BLE devices, you connect to a peripheral, but in CoreBluetooth - you call connect on a manager singleton to connect to a peripheral, which makes sense for implementation-specifics (as there is only 1 Bluetooth radio which needs to manage all connections), but not semantically. In SwiftyTeeth, the 'Device' object has the connect method, the caller 'connects to a device', rather than the caller 'asks a singleton to connect to a device on it's behalf'.

Usage

Scan for BLE devices using SwiftyTeeth with a 1 second timeout:

SwiftyTeeth.shared.scan(for: 1) { devices in
        self.devices = devices
        self.tableView.reloadData()
    }

Alternatively, you could use the SwiftyTeethable protocol in an extension:

extension DeviceListViewController: SwiftyTeethable {
    func scanTapped() {
        swiftyTeeth.scan(for: 1) { devices in
            self.devices = devices
            self.tableView.reloadData()
        }
    }
}

Initiate a connection using a SwiftyTeeth.Device:

device?.connect(complete: { isConnected in
	print("Is device connected? \(isConnected == true)")
})

Discover Bluetooth services and characteristics:

self.device?.discoverServices(complete: { services, error in
    services.forEach({
        print("Discovering characteristics for service: \($0.uuid.uuidString)")
        self.device?.discoverCharacteristics(for: $0, complete: { service, characteristics, error in
            characteristics.forEach({
                print("App: Discovered characteristic: \($0.uuid.uuidString) in \(service.uuid.uuidString)")
            })
            
            if service == services.last {
                print("App: All services/characteristics discovered")
            }
        })
    })
})

Write to a connected SwiftyTeeth.Device:

let command = Data(bytes: [0x01])
device?.write(data: command, to: characteristic, in: service, complete: { error in
    print("Write with response successful? \(error == nil)")
})

Read from a connected SwiftyTeeth.Device:

device?.read(from: characteristic, in: service, complete: { data, error in
    print("Read value: \(data?.base64EncodedString())")
})

Subscribe to notifications from a connected SwiftyTeeth.Device:

device?.subscribe(to: characteristic, in: service, complete: { data, error in
    print("Subscribed value: \(data?.base64EncodedString())")
})

Check out the sample app in SwiftyTeeth Sample/ to see the API in action.

Future Directions

Better Error handling

Error handling in a BLE library is always tricky - but generally they should be fully asynchronous. In addition, having clear and concise error conditions, alongside seamless retries is crucial.

Queues

As mentioned in the Blueteeth post, Callback Hell (or rightward drift) sucks, but that hasn't yet been solved in this library. The current usage for chaining calls is still, unfortunately, callbacks in callbacks.

MacOS

CoreBluetooth is also available on MacOS, so once completed and compiled correctly - there is no reason that it couldn't be used directly on a Mac, rather than only from iOS devices.

SwiftyTeeth as a Peripheral

For the purposes of testing and debugging, being able to use a Mac as a demo-peripheral has immense value. CoreBluetooth supports central and peripheral modes of operation, so this would be a great (and useful) extension.

Reactive Everything!

Now that this library is released and progressively becoming more stable, the next step in the process is to create Reactive bindings (RxSwift bindings specifically). They will be created in a separate repo, so that there isn't a forced, heavy dependency on the Rx framework in any app that just wants to use SwiftyTeeth.

Requirements

  • iOS 10+
  • Swift 5+
  • XCode 10+

Download

CocoaPods

Currently, you can use the master or develop branches and git directly until the API has stabilized.

platform :ios, '9.0'
use_frameworks!

pod 'SwiftyTeeth', :git => 'https://github.com/RobotPajamas/SwiftyTeeth.git', :branch => 'master'

Carthage

Instructions coming soon.

Issues

Please report all bugs or feature requests to: https://github.com/RobotPajamas/SwiftyTeeth/issues

Swifty Community

Other iOS-centric Bluetooth libraries.

License

The Apache License (Apache)

Copyright (c) 2019 Robot Pajamas

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
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].