Skip to content

kevinbrewster/SwiftLinuxGATTServerExample

Repository files navigation

SwiftLinuxGATTServerExample

This is a bare bones 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 PureSwift BluetoothLinux library.

This example sets up a simple BLE peripheral with 2 services, each with a single characteristic.

For a more advanced example with nicer syntax, take a look at SwiftLinuxGATTServerExampleAdvanced

  • Device Information: an example of using a built-in GATT "Device Information" service (0x180A) with the built-in GATT "Manufacturer Name String" characteristic (0x2A29). Normally you'd have more characteristics for this service.

  • Example Service: a custom service with a single read/write characteristic. This shows how to handle write requests and how to update a characteristics value.

Note: I have no affiliation with the PureSwift project and this code may not be the recommended or canonical usage.

Installation for Raspberry Pi

  1. Install Raspbian or Ubuntu on Raspberry Pi
  2. Install Swift 5 on Raspberry Pi using the prebuilt binary
  3. Checkout the SwiftLinuxGATTServerExample project
  4. Navigate to project directory and run: sudo /home/pi/usr/bin/swift run

Testing

I'm using BlueSee BLE Debugger to test the BLE connection and verify that read/write works on the example customer characteristic.

Device Log

Read and Write

Dependencies

Helpful Links

BLE API Design

BLE Advertising

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages