Adafruit Feather 32u4 Bluefruit LE: BLE GAP: Difference between revisions
(Created page with "== BLE GAP == == Reference == Adafruit Learn BLE GAP https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le/ble-gap") |
|||
(14 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== BLE GAP == | == BLE GAP == | ||
GAP, which stands for the Generic Access Profile, governs advertising and connections with Bluetooth Low Energy devices. | |||
The following commands can be used to configure the GAP settings on the BLE module. | |||
You can use these commands to modify the advertising data (for ex. the device name that appears during the advertising process), to retrieve information about the connection that has been established between two devices, or the disconnect if you no longer wish to maintain a connection. | |||
== AT Commands == | |||
The Bluefruit LE modules use a [http://en.wikipedia.org/wiki/Hayes_command_set Hayes AT-style command set] to configure the device. | |||
The advantage of an AT style command set is that it's easy to use in machine to machine communication, while still being somewhat user friendly for humans. | |||
===Test Command Mode '=?'=== | |||
'Test' mode is used to check whether or not the specified command exists on the system or not. | |||
Certain firmware versions or configurations may or may not include a specific command, and you can determine if the command is present by taking the command name and appending '=?' to it, as shown below | |||
AT+BLESTARTADV=? | |||
===Write Command Mode '=xxx'=== | |||
'Write' mode is used to assign specific value(s) to the command, such as changing the radio's transmit power level using the command we used above. | |||
To write a value to the command, simple append an '=' sign to the command followed by any paramater(s) you wish to write (other than a lone '?' character which will be interpretted as tet mode): | |||
AT+BLEPOWERLEVEL=-8 | |||
===Execute Mode=== | |||
'Execute' mode will cause the specific command to 'run', if possible, and will be used when the command name is entered with no additional parameters. | |||
AT+FACTORYRESET | |||
===Read Command Mode '?'=== | |||
'Read' mode is used to read the current value of a command. | |||
Not every command supports read mode, but you generally use this to retrieve information like the current transmit power level for the radio by appending a '?' to the command, as shown below: | |||
AT+BLEPOWERLEVEL? | |||
== AT+GAPSETADVDATA == | |||
Sets the raw advertising data payload to the specified byte array (overriding the normal advertising data), following the guidelines in the [https://www.bluetooth.org/en-us/specification/adopted-specifications Bluetooth 4.0 or 4.1 Core Specification]. | |||
In particular, '''Core Specification Supplement (CSS) v4''' contains the details on common advertising data fields like 'Flags' (Part A, Section 1.3) and the various Service UUID lists (Part A, Section 1.1). A list of all possible GAP Data Types is available on the Bluetooth SIG's [https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile Generic Access Profile] page. | |||
The Advertising Data payload consists of [https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile Generic Access Profile] data that is inserted into the advertising packet in the following format: [U8:LEN] [U8:Data Type Value] [n:Value] | |||
For example, to insert the 'Flags' Data Type (Data Type Value 0x01), and set the value to 0x06/0b00000110 (BR/EDR Not Supported and LE General Discoverable Mode) we would use the following byte array: | |||
02-01-06 | |||
*0x02 indicates the number of bytes in the entry | |||
*0x01 is the [https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile 'Data Type Value'] and indicates that this is a ''''Flag'''' | |||
*0x06 (0b00000110) is the Flag value, and asserts the following fields (see Core Specification 4.0, Volume 3, Part C, 18.1): | |||
**'''LE General Discoverable Mode''' (i.e. anyone can discover this device) | |||
**'''BR/EDR Not Supported''' (i.e. this is a Bluetooth Low Energy only device) | |||
If we also want to include two 16-bit service UUIDs in the advertising data (so that listening devices know that we support these services) we could append the following data to the byte array: | |||
05-02-0D-18-0A-18 | |||
*0x05 indicates that the number of bytes in the entry (5) | |||
*0x02 is the [https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile 'Data Type Value'] and indicates that this is an ''''Incomplete List of 16-bit Service Class UUIDs'''' | |||
*0x0D 0x18 is the first 16-bit UUID (which translates to '''0x180D''', corresponding to the [https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.heart_rate.xml Heart Rate Service]). | |||
*0x0A 0x18 is another 16-bit UUID (which translates to '''0x180A''', corresponding to the [https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml Device Information Service]). | |||
The Example AT Command: | |||
AT+GAPSETADVDATA=02-01-06-05-02-0d-18-0a-18 | |||
The results of this command can be seen in the screenshot below, taken from a sniffer analyzing the advertising packets in Wireshark. The advertising data payload is higlighted in blue in the raw byte array at the bottom of the image, and the packet analysis is in the upper section: | |||
[[File:adafruit_screenshot_gap_adv.png]] | |||
== Reference == | == Reference == | ||
Adafruit Learn BLE GAP https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le/ble-gap | Adafruit Learn BLE GAP https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le/ble-gap | ||
Adafruit Learn AT Commands https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le/at-commands | |||
BLE Core Specification Supplement (CSS) V7 https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=421047 |
Latest revision as of 12:41, 15 December 2017
BLE GAP
GAP, which stands for the Generic Access Profile, governs advertising and connections with Bluetooth Low Energy devices.
The following commands can be used to configure the GAP settings on the BLE module.
You can use these commands to modify the advertising data (for ex. the device name that appears during the advertising process), to retrieve information about the connection that has been established between two devices, or the disconnect if you no longer wish to maintain a connection.
AT Commands
The Bluefruit LE modules use a Hayes AT-style command set to configure the device.
The advantage of an AT style command set is that it's easy to use in machine to machine communication, while still being somewhat user friendly for humans.
Test Command Mode '=?'
'Test' mode is used to check whether or not the specified command exists on the system or not.
Certain firmware versions or configurations may or may not include a specific command, and you can determine if the command is present by taking the command name and appending '=?' to it, as shown below
AT+BLESTARTADV=?
Write Command Mode '=xxx'
'Write' mode is used to assign specific value(s) to the command, such as changing the radio's transmit power level using the command we used above.
To write a value to the command, simple append an '=' sign to the command followed by any paramater(s) you wish to write (other than a lone '?' character which will be interpretted as tet mode):
AT+BLEPOWERLEVEL=-8
Execute Mode
'Execute' mode will cause the specific command to 'run', if possible, and will be used when the command name is entered with no additional parameters.
AT+FACTORYRESET
Read Command Mode '?'
'Read' mode is used to read the current value of a command.
Not every command supports read mode, but you generally use this to retrieve information like the current transmit power level for the radio by appending a '?' to the command, as shown below:
AT+BLEPOWERLEVEL?
AT+GAPSETADVDATA
Sets the raw advertising data payload to the specified byte array (overriding the normal advertising data), following the guidelines in the Bluetooth 4.0 or 4.1 Core Specification.
In particular, Core Specification Supplement (CSS) v4 contains the details on common advertising data fields like 'Flags' (Part A, Section 1.3) and the various Service UUID lists (Part A, Section 1.1). A list of all possible GAP Data Types is available on the Bluetooth SIG's Generic Access Profile page.
The Advertising Data payload consists of Generic Access Profile data that is inserted into the advertising packet in the following format: [U8:LEN] [U8:Data Type Value] [n:Value]
For example, to insert the 'Flags' Data Type (Data Type Value 0x01), and set the value to 0x06/0b00000110 (BR/EDR Not Supported and LE General Discoverable Mode) we would use the following byte array:
02-01-06
- 0x02 indicates the number of bytes in the entry
- 0x01 is the 'Data Type Value' and indicates that this is a 'Flag'
- 0x06 (0b00000110) is the Flag value, and asserts the following fields (see Core Specification 4.0, Volume 3, Part C, 18.1):
- LE General Discoverable Mode (i.e. anyone can discover this device)
- BR/EDR Not Supported (i.e. this is a Bluetooth Low Energy only device)
If we also want to include two 16-bit service UUIDs in the advertising data (so that listening devices know that we support these services) we could append the following data to the byte array:
05-02-0D-18-0A-18
- 0x05 indicates that the number of bytes in the entry (5)
- 0x02 is the 'Data Type Value' and indicates that this is an 'Incomplete List of 16-bit Service Class UUIDs'
- 0x0D 0x18 is the first 16-bit UUID (which translates to 0x180D, corresponding to the Heart Rate Service).
- 0x0A 0x18 is another 16-bit UUID (which translates to 0x180A, corresponding to the Device Information Service).
The Example AT Command:
AT+GAPSETADVDATA=02-01-06-05-02-0d-18-0a-18
The results of this command can be seen in the screenshot below, taken from a sniffer analyzing the advertising packets in Wireshark. The advertising data payload is higlighted in blue in the raw byte array at the bottom of the image, and the packet analysis is in the upper section:
Reference
Adafruit Learn BLE GAP https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le/ble-gap
Adafruit Learn AT Commands https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le/at-commands
BLE Core Specification Supplement (CSS) V7 https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=421047