All Projects → manolofdez → AsyncBluetooth

manolofdez / AsyncBluetooth

Licence: MIT License
A small library that adds concurrency to CoreBluetooth APIs.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to AsyncBluetooth

coBlue
Use Bluetooth Low Energy for remote commands, file transfer, Based on bluez Bluetooth protocol stack (BLE Terminal)
Stars: ✭ 41 (+46.43%)
Mutual labels:  bluetooth, corebluetooth
CombineCoreBluetooth
A wrapper API for CoreBluetooth using Combine Publishers
Stars: ✭ 50 (+78.57%)
Mutual labels:  bluetooth, corebluetooth
SwiftyTeeth
A simple, lightweight library intended to take away some of the cruft and tediousness of using CoreBluetooth
Stars: ✭ 21 (-25%)
Mutual labels:  bluetooth, corebluetooth
GATT
Bluetooth Generic Attribute Profile (GATT) for Swift (Supports Linux)
Stars: ✭ 48 (+71.43%)
Mutual labels:  bluetooth, corebluetooth
Servus
Ad-hoc peer-to-peer iOS library
Stars: ✭ 27 (-3.57%)
Mutual labels:  bluetooth
nativeble
A fully-fledged cross-platform BLE library for desktop.
Stars: ✭ 15 (-46.43%)
Mutual labels:  bluetooth
bluetooth
Android Bluetooth examples
Stars: ✭ 80 (+185.71%)
Mutual labels:  bluetooth
ble-heart-rate-demo
Web bluetooth heart rate monitor
Stars: ✭ 24 (-14.29%)
Mutual labels:  bluetooth
soma-ctrl
Node util for controlling SOMA smart shade via MQTT or HTTP
Stars: ✭ 19 (-32.14%)
Mutual labels:  bluetooth
bluetooth-gatt-parser
Bluetooth GATT service and characteristic parser
Stars: ✭ 61 (+117.86%)
Mutual labels:  bluetooth
seeed-ambd-firmware
This RTL8720DN firmware export a RPC server interface through hardware SPI/UART port to MCU.
Stars: ✭ 20 (-28.57%)
Mutual labels:  bluetooth
bluez-rs
Control Bluetooth on Linux.
Stars: ✭ 36 (+28.57%)
Mutual labels:  bluetooth
Bluetooth-Unlock
Simple script to unlock your Linux based Computer using a Bluetooth device when nearby
Stars: ✭ 37 (+32.14%)
Mutual labels:  bluetooth
MobilECG-II
Open source ECG holter
Stars: ✭ 375 (+1239.29%)
Mutual labels:  bluetooth
android-ble-made-easy
An Android Library for handling Bluetooth Low Energy on Android Easy
Stars: ✭ 34 (+21.43%)
Mutual labels:  bluetooth
wx-ant-ble
微信、支付宝小程序BLE蓝牙SDK
Stars: ✭ 75 (+167.86%)
Mutual labels:  bluetooth
codec2 talkie
Turn your Android phone into Codec2 Walkie-Talkie (Bluetooth/USB/TCPIP KISS modem client for DV digital voice communication)
Stars: ✭ 65 (+132.14%)
Mutual labels:  bluetooth
cuble.js
This project is now part of `cubing.js`: https://github.com/cubing/cubing.js/tree/master/src/bluetooth
Stars: ✭ 20 (-28.57%)
Mutual labels:  bluetooth
bluetooth-manager
Java Bluetooth Manager. A library/framework for managing bluetooth adapters, bluetooth devices, GATT services and characteristics
Stars: ✭ 75 (+167.86%)
Mutual labels:  bluetooth
ayanda
Android Library to discover nearby devices Offline
Stars: ✭ 38 (+35.71%)
Mutual labels:  bluetooth

AsyncBluetooth

A small library that adds concurrency to CoreBluetooth APIs.

Features

  • Async/Await APIs
  • Queueing of commands
  • Data conversion to common types
  • Thread safety
  • Convenience APIs for reading/writing without needing to explicitly discover characteristics.
  • Convenience API for waiting until Bluetooth is ready.

Usage

Scanning for a peripheral

Start scanning by calling the central manager's scanForPeripherals function. It returns an AsyncStream you can use to iterate over the discovered peripherals. Once you're satisfied with your scan, you can break from the loop and stop scanning.

let centralManager = CentralManager()

try await centralManager.waitUntilReady()

var scanDataStream = try await centralManager.scanForPeripherals(withServices: nil)
for await scanData in scanDataStream {
    // Check scan data...
}

await centralManager.stopScan()

Connecting to a peripheral

Once you have your peripheral, you can use the central manager to connect to it. Note you must hold a reference to the Peripheral while it's connected.

try await centralManager.connect(peripheral, options: nil)

Read value from characteristic

You can use convenience functions for reading and writing to characteristics. They will find the characteristic by using a UUID, and parse the data into the appropriate type.

let value: String? = try await peripheral.readValue(
    forCharacteristicWithUUID: UUID(uuidString: "")!,
    ofServiceWithUUID: UUID(uuidString: "")!
)

Examples

You can find practical, tasty recipes for how to use AsyncBluetooth in the AsyncBluetooth Cookbok.

Installation

Swift Package Manager

This library can be installed using the Swift Package Manager by adding it to your Package Dependencies.

Requirements

  • iOS 14.0+
  • MacOS 11.0+
  • Swift 5
  • Xcoce 13.2.1+

License

Licensed under MIT license.

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].