Swiftpack.co - PureSwift/GATT as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by PureSwift.
PureSwift/GATT 3.0.5
Bluetooth Generic Attribute Profile (GATT) for Swift (Supports Linux)
⭐️ 53
🕓 2 weeks ago
iOS macOS watchOS tvOS linux android
.package(url: "https://github.com/PureSwift/GATT.git", from: "3.0.5")

GATT

Swift Platform Release License

Bluetooth Generic Attribute Profile (GATT) for Swift

Usage

Peripheral

import Bluetooth
#if canImport(Darwin)
import DarwinGATT
#elseif os(Linux)
import BluetoothLinux
#endif

#if os(Linux)
typealias LinuxPeripheral = GATTPeripheral<BluetoothLinux.HostController, BluetoothLinux.L2CAPSocket>
guard let hostController = await HostController.default else {
    fatalError("No Bluetooth hardware connected")
}
let serverOptions = GATTPeripheralOptions(
    maximumTransmissionUnit: .max,
    maximumPreparedWrites: 1000
)
let peripheral = LinuxPeripheral(
    hostController: hostController,
    options: serverOptions,
    socket: BluetoothLinux.L2CAPSocket.self
)
#elseif canImport(Darwin)
let peripheral = DarwinPeripheral()
#else
#error("Unsupported platform")
#endif

// start advertising
try await peripheral.start()

Central

import Bluetooth
#if canImport(Darwin)
import DarwinGATT
#elseif os(Linux)
import BluetoothLinux
#endif

#if os(Linux)
typealias LinuxCentral = GATTCentral<BluetoothLinux.HostController, BluetoothLinux.L2CAPSocket>
let hostController = await HostController.default
let central = LinuxCentral(
    hostController: hostController,
    socket: BluetoothLinux.L2CAPSocket.self
)
#elseif canImport(Darwin)
let central = DarwinCentral()
#else
#error("Unsupported platform")
#endif

// start scanning
let stream = try await central.scan(filterDuplicates: true)
for try await scanData in stream {
    print(scanData)
    stream.stop()
}

Documentation

Read the documentation here. Documentation can be generated with DocC.

See Also

  • Bluetooth - Pure Swift Bluetooth Definitions
  • BluetoothLinux - Pure Swift Linux Bluetooth Stack
  • Netlink - Swift library for communicating with Linux Kernel Netlink subsystem (Linux Only)

License

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

GitHub

link
Stars: 53
Last commit: 5 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Dependencies

Release Notes

v3.0.5
2 weeks ago
  • Add VS Code container
  • Add WASM support

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics