Running BLE GATT Server Example on Raspbian Stretch


The purpose of this post is to run an example code of Bluetooth Low Energy GATT server from BlueZ source code on Raspberry Pi.

Here are the contents of this post.

Contents
– Assumptions
– Steps
1. Download Example Code
2. Execute Example Code
3. Install Requisite
4. Start Advertising BLE
5. Verify
– Reference

 

Assumptions
Here are some assumptions before start. Please refer this in case it’s not ready.

 

Steps
1. Download Example Code
1-1. Download BlueZ 5.43.

1-2. Extract the file.

The GATT server example code “example-gatt-server” is in “test” directory.

 

2. Install Requisite
2-1. Update package list.

2-2. Install python package manager.

2-3. Install dbus.

 

3. Execute Example Code
3-1. Execute BLE GATT server example code.

3-2. Check the output. If everything is fine, it should be like this:

Now, the GATT server is running. Since the example code implements “Fake Battery service that emulates a draining battery”, it outputs “Battery Level drained” message on the console every 5 seconds.

 

4. Start Advertising BLE
The next step is to start advertising in order to be detected by other devices. To make the steps easier, I’ll use hciconfig command. If you want to use dbus interface instead of hciconfig, please refer this post to run BLE advertising example code (i.e. example-advertisement).

4-1. Open other terminal and type below to start advertising.

Type below in case you need to stop the advertisement,

 

5. Verify
To verify, you can use smartphone apps. The below image was captured with “BLE Scanner” on iPhone.

 

Reference
– example-gatt-server\test – bluez.git – Bluetooth protocol stack for Linux
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/example-gatt-server

 

 

Sponsor Link

Leave a Reply

Your email address will not be published. Required fields are marked *