This is a simple example of how to create a Bluetooth 4.0 (BLE) peripheral (aka GATT server) on Linux (e.g. on a Raspberry Pi) using Swift and the SwiftLinuxBLE wrapper for the PureSwift BluetoothLinux library.
This example sets up a single BLE peripheral with a single service.
For a bare bones example without the SwiftLinuxBLE wrapper, take a look at SwiftLinuxGATTServerExample
- Install Raspbian or Ubuntu on Raspberry Pi
- Install Swift 5 on Raspberry Pi using the prebuilt binary
- Checkout the SwiftLinuxGATTServerExampleAdvanced project
- Navigate to project directory and run:
sudo /home/pi/usr/bin/swift run
- On mac: BlueSee BLE Debugger
- On iPhone: nRF Connect
The nRF Connect app is nice because you can subscribe to notifications
- PureSwift/BluetoothLinux - Pure Swift Linux Bluetooth Stack
- PureSwift/GATT - Bluetooth Generic Attribute Profile (GATT) for Swift
- SwiftLinuxBLE - Convenience wrapper for above