Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bluetooth Low Energy: Use BlueZ stack as a peripheral (with custom services and characteristics)

I am trying to use the BlueZ stack on a Linux machine to create a GATT server with custom services and characteristics. The final goal is to use any central device (e.g. iOS or Android device) to connect to the GATT server, discover the services and characteristics, and manipulate the data in the characteristics.

Example:

  • Peripheral with 1 service which contains 3 characteristics.
  • Service uuid = 0xFFFF
  • Char 1 uuid = 0xAAAA, properties = readable
  • Char 2 uuid = 0xBBBB, properties = readable & writable
  • Char 3 uuid = 0xCCCC, properties = notifiable

From the central device, I should see the the peripheral device, connect to it and discover one service (0xFFFF) which has three characteristics (0xAAAA, 0xBBBB, 0xCCCC). I should then be able to read the value of 0xAAAA, read and write to the value of 0xBBBB, and enable notifications on 0xCCCC.

Please note that I am aware that a similar question exists, but it only explains how to use the peripheral as an advertiser. Another solved question explains how to create a GATT server, but does not explain how to play with the properties of the characteristics (e.g. readable, notifiable, etc.), or maybe I'm missing something.

Thank you in advance.

like image 370
Youssif Saeed Avatar asked Jan 29 '14 10:01

Youssif Saeed


People also ask

What is BLE services and Characteristics?

A BLE profile serves as an application layer for specific and already defined use cases. Generally speaking, a BLE profile is a standard collection of services for a specific use case.

What is Bluetooth low energy technology?

Bluetooth Low Energy is a power-conserving variant of Bluetooth personal area network (PAN) technology, designed for use by Internet-connected machines and appliances. Also marketed as Bluetooth Smart, Bluetooth LE was introduced in the Bluetooth 4.0 specification as an alternative to Bluetooth Classic.

Does BlueZ support BLE?

What is BlueZ? BlueZ is the Bluetooth stack for Linux. It handles both Bluetooth BR/EDR as well as BLE.


1 Answers

Another solution now exists with Bluetoothctl command line tool. More details of this can be found here:-

BlueZ: How to set up a GATT server from the command line

I'm not sure when Bluetoothctl was introduced, but it's relatively recent at the time of this writing and therefore it didn't exist in previous versions of BlueZ. I'm using BlueZ v5.50 and this the version that I tested it with.

like image 58
Youssif Saeed Avatar answered Oct 04 '22 18:10

Youssif Saeed