Close

Selecting and implementing a GATT service

A project log for Haptic Sleeve

Sleeve worn on the arm to provide haptic feedback while performing handwriting exercises.

grant-stankaitisGrant Stankaitis 04/19/2020 at 20:480 Comments

In this log I will be documenting my process for searching through the BLE GATT Services.

I spent a lot of time cross-referencing the GATT services site with the GATT characteristics site to find any services and their characteristics that may be fitting for this project. This involved clicking through most of the services and reading the XML files that document these services.

I was looking for a service that was simple and had a characteristic that allowed me to easily/quickly write a simple string that would correspond to the motor and direction activation. I found that these default services weren't particularly fitting for what we needed, so I continued my search elsewhere.

I discovered that it is possible to implement serial communication over BLE as I read in this article. However, there is no default service for this, so it would involve creating this functionality through my own service. I have no idea how to write a BLE service, so I moved on from this option.

Nordic UART Service (NUS)

I then discovered the Nordic UART Service (NUS). The Nordic UART Service is a custom, simple GATT service with TX and RX characteristics. This service emulates a serial port over BLE. Perfect!

I want to implement this service, as it is fantastic for the functionality we need, but I am currently still unsure of how to implement it using Zerynth. I know that you can reference differnt BLE GATT services by passing in their respective UUIDs. However, from my research and testing, it seems that the BLE driver within Zerynth is only able to reference the UUIDs of the default BLE GATT services. So, I'm unable to access any custom, 3rd-party GATT services. I'm still looking into how to implement this, so I will update if there is any progress.

Using a custom GATT service

So, since I am unable to implement the Nordic UART Service, I randomly discovered that you can create your own service by specifying a random UUID that is not a UUID of the default BLE GATT services. Below is the code to illustrate what I am talking about.

# Add UART service
service = ble.Service(0x0001)

# Add TX Characteristic to service, add the GATT Characteristic to the Service
messageCh = ble.Characteristic(0x0002,ble.WRITE,20,"TX",ble.STRING)
service.add_characteristic(messageCh)

# Add the Service
ble.add_service(s)

In the line:

service = ble.Service(0x0001)

you can create a service using a UUID. Here, I entered in a random UUID, 0x0001.

Then, the line:

messageCh = ble.Characteristic(0x0002,ble.WRITE,20,"TX",ble.STRING)

 I create a characteristic with the UUID 0x0002, is writable (ble.WRITE), is labelled 'TX', and is of a string type (ble.STRING).

Using the nRF Connect app, I can write a string to the characteristic's value and see it update! This means that we can send the same strings as I tested before to activate the motors. See the screenshots below of this example working.

My service with UUID 0001, characteristic with UUID 0002 and the WRITE property enabled
Write the string "Test" to the characteristic value
Connected to nRF Connect app, the string "Test" is received and printed!

So, now that I have verified that I can send strings to the ESP32 over BLE, I will be working on transferring all of the code over to Zerynth.

Discussions