I'll include some Bluetooth terminology at the start of this log. I found these terms were the most helpful to know when implementing BLE.
GAP: Generic Access Profile, this profile controls connections and advertising in Bluetooth.
GATT: Generic Attribute Profile, this profile defines the way that two BLE devices transfer data back and forth using concepts called Services and Characteristics.
GATT Service: A GATT Service is a collection of characteristics that encapsulate the behavior of part of a device.
GATT Characteristic: A GATT Characteristic is a basic data element used to construct a GATT service. The characteristic contains a value as well as additional information and optional descriptors.
UUID: Universally unique identifier, each service is distinguished with a unique ID number.
To sum it up: GAP controls connections, and GATT is a way of specifying the transmission of data. The image below sums up the hierarchy of GATT very nicely:
Here are the links for the Bluetooth documentation for GATT Services and GATT Characteristics. I used this documentation to see if there were any services that were applicable to the simple data transmission that is needed for the Haptic Sleeve. I found that all of the services were very specific, like Blood Pressure or Battery Service, so I ended up using my own service through specifying an arbitrary UUID that is not in the official GATT services. I will show this later in the log.
Additional documentation for implementing BLE in Zerynth that was very helpful can be found here: ESP32 BLE Driver, Zerynth BLE Module.
Zerynth BLE Alerts example
When moving over to Zerynth, I began with testing the BLE Alerts example that can be found within the Zerynth examples. All I had to do was clone the example, upload the script, and the initial test worked! The content of example isn't of much importance, I was only testing for a connection to the ESP32.

In the console window on the right-hand side, you can see the Bluetooth connection to my phone, then I sent a value from my phone to enable notifications. In the screenshot below, you can see the Alert Notification Service, and I modified the Alert Notification Control Point characteristic.

Secure BLE with passcode
The example that I tested above was not secure because there was no 'bond' between the devices. You can see this below, the ESP32 is 'Connected' but 'Not Bonded'.

Bluetooth pairing is different from bonding. Pairing is creating a temporary encryption between two devices, but bonding is the creation of permanent security between devices. Bonding is completed through the exchange of long-term keys.
Since the Haptic Sleeve project only involves sending non-critical information over the BLE connection, bonding is not necessary, however having a secure connection is probably a nice feature to implement. So, I tested the BLE Alerts Secure example within Zerynth. In the screenshot below, you can see the ESP32 connecting to my phone then printing out a passcode to be entered. Success!

In my next log, I'll be detailing my process for finding a GATT service that will best fit this project.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.