Skip to main content

Prerequisites

Before you begin, set up the device as described in Set up the device for Bluetooth Low Energy GATT functions.

Connect to a remote device

To connect to a remote device, run the following command from the bluetoothctl menu:
connect <bt_address>
Parameters <bt_address> is the Bluetooth address of the remote device.
To get the Bluetooth address of the remote device, run a Bluetooth Low Energy GATT scan.
Example To connect to a client with <bt_address> 6D:38:AF:C6:B5:62, run the following command:
connect 6D:38:AF:C6:B5:62

Add a primary service

To add a primary service to the GATT server, run the following command from the menu gatt menu:
register-service <UUID> [handle]
Example If the UUID of the service is FF01 and the handle is 30, run the following command:
register-service FF01 30
Sample output
[MyDeviceB:/service0001/char0008]# register-service FF01 30
[NEW] Primary Service (Handle 0x001e)
      /org/bluez/app/service0
      FF01
[/org/bluez/app/service0] Primary (yes/no): yes

Add a characteristic

To add a characteristic to a service of the server, run the following command from the menu gatt menu:
register-characteristic <UUID> <Flags=read,write,notify...> [handle]
Parameters <Flags> are the flag values of the characteristic. For values, see Flag values. Example The UUID of a service is FF02, the flags are read,write,notify, and the handle is 31. To add a characteristic, run the following command:
register-characteristic FF02 read,write,notify 31
Sample output
[MyDeviceB]# register-characteristic FF02 read,write,notify 31
[NEW] Characteristic (Handle 0x001f)
      /org/bluez/app/service0/chrc0
      FF02
<egister-characteristic FF02 read,write,notify 31[/org/bluez/app/service0/chrc0] Enter value: 20

Add a descriptor

To add a descriptor to a characteristic in the server, run the following command from the menu gatt menu:
register-descriptor <UUID> <Flags=read,write...> [handle]
Parameters <Flags> are the flag values of the descriptor. For values, see Flag values. Example The UUID of a service is FF03, the flags are read,write, and the handle is 33. To add a descriptor, run the following command:
register-descriptor FF03 read,write 33
Sample output
[MyDeviceB]# register-descriptor FF03 read,write 33
[NEW] Descriptor (Handle 0x0021)
   /org/bluez/app/service0/chrc0/desc0
   FF03
<egister-descriptor FF03 read,write 33[/org/bluez/app/service0/chrc0/desc0] Enter value: 21

Add an included service

Before you begin, add the intended services as primary services. To add an included service to another service, run the following command from the menu gatt menu:
register-includes <UUID> <UUID>
Example Consider two primary services with the UUID FF01 and 1112, respectively. To add the service 1112 as an included service to the service FF01, run the following command:
register-includes FF01 1112
Sample output
[MyDeviceB]# register-includes FF01 1112
[NEW] Primary Service (Handle 0x001e)
      /org/bluez/app/service0
      FF01
[NEW] Primary Included Service (Handle 0x0000)
      /org/bluez/app/service1
      1112
      Unknown

Register an application

To publish the services that are available or added to the server, run the following command from the menu gatt menu:
register-application [UUID]
Example The UUID of the service is FF01. To publish the services that are available or added to the server, run the following command:
register-application FF01
Sample output
[MyDeviceB]# register-application FF01
[CHG] Secondary Service (Handle 0x0015)
   /org/bluez/app/service2
   1112
   Unknown
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Primary Service (Handle 0x0016)
   /org/bluez/app/service1    
   FF01
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000ff01-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001112-0000-1000-8000-00805f9b34fb
Application registered
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000ff01-0000-1000-8000-00805f9b34fb
[CHG] Controller 22:22:9B:2C:79:1E UUIDs: 0000111e-0000-1000-8000-00805f9b34fb

Start an advertisement

To start a GATT advertisement, run the following command from the bluetoothctl menu:
advertise on
Sample output
[MyDeviceB]# advertise on
[CHG] Controller 22:22:9B:2C:79:1E SupportedInstances: 0x0f (15)
[CHG] Controller 22:22:9B:2C:79:1E ActiveInstances: 0x01 (1)
Advertising object registered
Tx Power: off
Name: off
Appearance: off
Discoverable: on

Disconnect a remote device

To disconnect a remote device, run the following command from the bluetoothctl menu:
disconnect <bt_address>
Parameters <bt_address> is the Bluetooth address of the remote device. Example To disconnect a client with <bt_address> 6D:38:AF:C6:B5:62, run the following command:
disconnect 6D:38:AF:C6:B5:62

Flag values

The value of <Flags> can be:
broadcastauthenticated-signed-writesencrypt-authenticated-readencrypt-authenticated-notify
readextended-propertiesencrypt-authenticated-writesecure-notify
writereliable-writesecure-readencrypt-indicate
write-without-responsewritable-auxiliariessecure-writeencrypt-authenticated-indicate
notifyencrypt-readauthorizesecure-indicate
indicateencrypt-writeencrypt-notify