Pure Swift Bluetooth Stack for Linux
Does not require BlueZ, communicates directly with the Linux kernel and Bluetooth controller.
import Bluetooth
import BluetoothLinux
guard let adapter = try? Adapter()
else { Error("No Bluetooth adapters found") }
print("Found Bluetooth adapter with device ID: \(adapter.identifier)")
let iBeaconUUID = Foundation.UUID(rawValue: "E2C56DB5-DFFB-48D2-B060-D0F5A71096E0")!
do { try adapter.enableBeacon(uuid: iBeaconUUID, major: 1, minor: 1, rssi: -29) }
catch { print("Error enabling iBeacon: \(error)") }
import PackageDescription
let package = Package(
dependencies: [
.Package(url: "https://github.com/PureSwift/BluetoothLinux.git", majorVersion: 2)
]
)
Documentation can be generated with Jazzy.
swift package generate-xcodeproj
jazzy
Read the documentation here. For more information, see the gh-pages branch.
I recommend LightBlue Explorer and Locate Beacon to verify the iBeacon is advertising. The iBeacon test case is already configured to use a UUID that is preinstalled in the Locate Beacon app.
Do not test in Parallels or VMware with the built in Bluetooth adapter found in Macs. You can, however, use VMWare or Parallels, with a Linux compatible Bluetooth LE USB adapter plugged in. VirtualBox will work with the builtin adapter on Macs.
For best results, test with Swift 3.0.2 on an ARM board running Linux (e.g. BeagleBoneBlack, Raspberry Pi, Orange Pi, etc) and a Linux comaptible Bluetooth dongle (e.g. CSR8510 A10).
- Bluetooth - Pure Swift Bluetooth Definitions.
- GATT - Bluetooth Generic Attribute Profile (GATT) for Swift
- SwiftFoundation - Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library.
- Cacao - Pure Swift Cross-platform UIKit
- Silica - Pure Swift CoreGraphics (Quartz2D) implementation
- Predicate - Pure Swift Predicate implementation
BluetoothLinux is released under the MIT license. See LICENSE for details.