Check out my first novel, midnight's simulacra!

Bluetooth LE: Difference between revisions

From dankwiki
Jump to navigation Jump to search
No edit summary
 
Line 2: Line 2:


==GATT==
==GATT==
The Generic Attribute Profile is the core BLE API. A server implements <i>services</i>, which are collections of one or more <i>characteristics</i>, and may have zero or more <i>secondary services</i>. A characteristic has a value, and optional <i>descriptors</i>. All three of these objects have UUIDs. Some UUIDs are assigned, and refer to standard objects. Others are vendor-defined. The UUIDs of a server's services, their characteristics, and their descriptors can be enumerated, but the client must give meaning to them (they are not self-describing).
The Generic Attribute Profile is the core BLE API. A server implements <i>services</i>, which are collections of one or more <i>characteristics</i>, and may have zero or more <i>secondary services</i>. A characteristic has a value, and optional <i>descriptors</i>. All three of these objects have UUIDs. Some UUIDs are assigned, and refer to standard objects. Others are vendor-defined. The UUIDs of a server's services, their characteristics, and their descriptors can be enumerated, but the client must give meaning to them (they are not self-describing). A characteristic can be read-only, write-only, or read-write, as defined by the server.
 
===<tt>bluetoothctl</tt>===
Discover local BLE devices' names and MAC addresses:
* <tt>scan le</tt>
Operating with GATT requires connecting, as specified using the server's MAC:
* <tt>connect MAC</tt>
Once connected, discover services and characteristics:
* <tt>gatt.list-attributes</tt>
Operating with a characteristic requires selecting it by UUID:
* <tt>gatt.select-attribute UUID</tt>
Read the selected characteristic:
* <tt>gatt.read</tt>
Write the selected characteristic:
* <tt>gatt.write DATA</tt>
DATA must be expressed as a series of bytes in the form <tt>0xHH</tt>, separated by spaces. This can be generated on the command line via e.g.:
* <tt>echo -n "here is some data" | xxd -p | sed -e 's/\(..\)/0x\1 /g'</tt>


[[CATEGORY: Networking]]
[[CATEGORY: Networking]]

Latest revision as of 03:24, 2 March 2025

Also known as BLE. Not to be confused with Bluetooth, which is completely different except for where it's the same.

GATT

The Generic Attribute Profile is the core BLE API. A server implements services, which are collections of one or more characteristics, and may have zero or more secondary services. A characteristic has a value, and optional descriptors. All three of these objects have UUIDs. Some UUIDs are assigned, and refer to standard objects. Others are vendor-defined. The UUIDs of a server's services, their characteristics, and their descriptors can be enumerated, but the client must give meaning to them (they are not self-describing). A characteristic can be read-only, write-only, or read-write, as defined by the server.

bluetoothctl

Discover local BLE devices' names and MAC addresses:

  • scan le

Operating with GATT requires connecting, as specified using the server's MAC:

  • connect MAC

Once connected, discover services and characteristics:

  • gatt.list-attributes

Operating with a characteristic requires selecting it by UUID:

  • gatt.select-attribute UUID

Read the selected characteristic:

  • gatt.read

Write the selected characteristic:

  • gatt.write DATA

DATA must be expressed as a series of bytes in the form 0xHH, separated by spaces. This can be generated on the command line via e.g.:

  • echo -n "here is some data" | xxd -p | sed -e 's/\(..\)/0x\1 /g'