Bluefruit-LE-Shield-BLE-GATT

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

GATT BLE

GATT est l'acronyme de "Generic ATTribute Profile" (profile d'attribut générique). GATT gouverne l'organisation et l'échange de données entre les périphériques connectés. Un périphérique (nommé "the peripheral" dans la nomenclature) agit comme un serveur GATT qui enregistre les données dans des enregistrements Attributs. Un second périphérique (nommé la "central") agit comme un client GATT, demandant les données au serveur lorsque cela est nécessaire.

Les commandes suivantes peuvent être utilisées pour créer des services et caractéristiques GATT personnalisés sur le BLEFriend. Ces services et caractéristiques sont utilisés pour enregistrer et échanger les données.

Attention: toutes les caractéristiques que vous aller définir seront sauvegardées dans la mémoire FLASH de configuration (non volatile) du périphérique. Ces caractéristiques seront réinitialisées à chaque démarrage du périphérique.

Limitations de GATT

Etant donné la mémoire SRAM et les ressources limitées du module, les commandes ont certaines limitations détaillées ci-dessous. Gardez ces limitations en mémoire lorsque vous créez des services et caractéristiques GATT personnalisés.

Ces valeurs sont applicable à partir du firmware firmware 0.7.0:

  • Nombre maximal de services: 10
  • Nombre maximal de caractéristiques: 30
  • Taille de la mémoire tampon Max pour chaque caractéristique: 32 octets
  • Nombre maximum de CCCDs: 16

Vous pouvez utiliser la commande de réinitialisation d'usine (AT+FACTORYRESET) si vous avez besoin d'effacer les valeurs d'une précédente configuration. Saisissez la commande avant de débuter une nouvelle configuration.

AT+GATTCLEAR

Efface tous les services et caractéristiques GATT personnalisés qui ont été définis sur le périphérique.

  • Codebase Revision: 0.3.0
  • Paramètres: Aucune
  • Réponse: Aucune
AT+GATTCLEAR
OK

AT+GATTADDSERVICE

Ajoute une nouvelle définition de service personnalisé sur le pérhiphérique.

  • Codebase Revision : 0.3.0
  • Paramètre : La commande accepte une série de paires "clé-valeur", paires séparés par des virgules. Ces paires sont utilisées pour définir les propriétés du service.
    Les paires clé-valeur suivantes peuvent être utilisés:
    • UUID : Le UUID 16-bits pour ce service. La valeur 16-bits doit être mentionnée au format hexadécimal (0x1234).
    • UUID128 : Le UUID 128-bits pour ce service. Les valeurs 128-bits doivent avoir le format suivant: 00-11-22-33-44-55-66-77-88-99-AA-BB-CC-DD-EE-FF
  • Réponse : La valeur d'index du service GATT personnalisé dans la table lookup. (Il est important de mémoriser cette valeur indexe pour pouvoir travailler avec le service.)
# Efface toutes les définitions antérieurs 
# de services/caractéristiques personnalisées
AT+GATTCLEAR
OK

# Ajoute le service "battery" (UUID = 0x180F, état de la 
# batterie) sur le périphérique
AT+GATTADDSERVICE=UUID=0x180F
1
OK
  
# Ajoute la caractéristique "battery measurement" 
# (UUID = 0x2A19, mesure de la batterie), notification activée
AT+GATTADDCHAR=UUID=0x2A19,PROPERTIES=0x10,MIN_LEN=1,VALUE=100
1
OK

AT+GATTADDCHAR

Adds a custom characteristic to the last service that was added to the peripheral (via AT+GATTADDSERVICE).

  • Codebase Revision : 0.3.0
  • Parameters : This command accepts a set of comma-separated key-value pairs that are used to define the characteristic properties. The following key-value pais can be used:
    • UUID : The 16-bit UUID to use for the characteristic (which will be insert in the 3rd and 4th bytes of the parent services 128-bit UUID). This value should be entered in hexadecimal format (ex. 'UUID=0x1234'). This value must be unique, and should not conflict with bytes 3+4 of the parent service's 128-bit UUID.
    • PROPERTIES : The 8-bit characteristic properties field, as defined by the Bluetooth SIG. The following values can be used:
      • 0x02 - Read
      • 0x04 - Write Without Response
      • 0x08 - Write
      • 0x10 - Notify
      • 0x20 - Indicate
    • MIN_LEN : The minimum size of the values for this characteristic (in bytes, min = 1, max = 20, default = 1)
    • MAX_LEN : The maximum size of the values for the characteristic (in bytes, min = 1, max = 20, default = 1)
    • VALUE : The initial value to assign to this characteristic (within the limits of 'MIN_LEN' and 'MAX_LEN'). Value can be an integer ("-100", "27"), a hexadecimal value ("0xABCD"), a byte array ("aa-bb-cc-dd") or a string ("GATT!").
    • >=0.7.0 - DATATYPE : This argument indicates the data type stored in the characteristic, and is used to help parse data properly. It can be one of the following values:
      • AUTO (0, default)
      • STRING (1)
      • BYTEARRAY (2)
      • INTEGER (3)
    • >=0.7.0 - DESCRIPTION: Adds the specified string as the characteristic description entry
    • >=0.7.0 - PRESENTATION: Adds the specified value as the characteristic presentation format entry
  • Response: The index value of the characteristic in the custom GATT characteristic lookup table. (It's important to keep track of these characteristic index values to work with the characteristic later.)
# Clear any previous custom services/characteristics
AT+GATTCLEAR
OK

# Add a battery service (UUID = 0x180F) to the peripheral
AT+GATTADDSERVICE=UUID=0x180F
1
OK
  
# Add a battery measurement characteristic (UUID = 0x2A19), notify enabled
AT+GATTADDCHAR=UUID=0x2A19,PROPERTIES=0x10,MIN_LEN=1,VALUE=100
1
OK
# Clear any previous custom services/characteristics
AT+GATTCLEAR
OK

# Add a custom service to the peripheral
AT+GATTADDSERVICE=UUID128=00-11-00-11-44-55-66-77-88-99-AA-BB-CC-DD-EE-FF
1
OK

# Add a custom characteristic to the above service (making sure that there
# is no conflict between the 16-bit UUID and bytes 3+4 of the 128-bit service UUID)
AT+GATTADDCHAR=UUID=0x0002,PROPERTIES=0x02,MIN_LEN=1,VALUE=100
1
OK

Version 0.6.6 of the Bluefruit LE firmware added the ability to use a new "UUID128" flag to add custom 128-bit UUIDs that aren't related to the parent service UUID (which is used when passing the 16-bit "UUID" flag).

To specify a 128-bit UUID for your customer characteristic, enter a value resembling the following syntax:

# Add a custom characteristic to the above service using a
# custom 128-bit UUID
AT+GATTADDCHAR=UUID128=00-11-22-33-44-55-66-77-88-99-AA-BB-CC-DD-EE-FF,PROPERTIES=0x02,MIN_LEN=1,VALUE=100
1
OK

Version 0.7.0 of the Bluefruit LE firmware added the new DESCRIPTION and PRESENTATION keywoards, corresponding the the GATT Characteristic User Description and the GATT Characteristic Presentation Format Descriptors.

The DESCRIPTION field is a string that contains a short text description of the characteristic. Some apps may not display this data, but it should be visible using something like the Master Control Panel application from Nordic on iOS and Android.

The PRESENTATION field contains a 7-byte payload that encapsulates the characteristic presentation format data. It requires a specific set of bytes and values to work properly. See the following link for details on how to format the payload: https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml

The following example shows how you might use both of these new fields:

AT+GATTADDCHAR=UUID=0x2A37, PROPERTIES=0x10, MIN_LEN=2, MAX_LEN=3, VALUE=00-40, 
               DESCRIPTION=HRM Measurement, PRESENTATION=17-00-AC-27-01-00-00

For the Characteristic Presentation Format we have:

  • Format = IEEE-11073 32-bit FLOAT (Decimal 23, Hex 0x17)
  • Exponent = 0/None
  • Unit = Thermodynamic temperature: Degrees Fahrenheit (0x27AC) - Bluetooth LE Unit List
  • Namespace = Bluetooth SIG Assigned Number (0x01)
  • Description = None (0x0000)

The results from Nordic's Master Control Panel app can be seen below:

{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com

AT+GATTCHAR

Gets or sets the value of the specified custom GATT characteristic (based on the index ID returned when the characteristic was added to the system via AT+GATTADDCHAR).

  • Codebase Revision: 0.3.0
  • Parameters: This function takes one or two comma-separated functions (one parameter = read, two parameters = write).
    • The first parameter is the characteristic index value, as returned from the AT+GATTADDCHAR function. This parameter is always required, and if no second parameter is entered the current value of this characteristic will be returned.
    • The second (optional) parameter is the new value to assign to this characteristic (within the MIN_SIZE and MAX_SIZE limits defined when creating it).
  • Response: If the command is used in read mode (only the characteristic index is provided as a value), the response will display the current value of the characteristics. If the command is used in write mode (two comma-separated values are provided), the characteristics will be updated to use the provided value.
# Clear any previous custom services/characteristics
AT+GATTCLEAR
OK

# Add a battery service (UUID = 0x180F) to the peripheral
AT+GATTADDSERVICE=UUID=0x180F
1
OK
  
# Add a battery measurement characteristic (UUID = 0x2A19), notify enabled
AT+GATTADDCHAR=UUID=0x2A19,PROPERTIES=0x10,MIN_LEN=1,VALUE=100
1
OK

# Read the battery measurement characteristic (index ID = 1)
AT+GATTCHAR=1
0x64
OK

# Update the battery measurement characteristic to 32 (hex 0x20)
AT+GATTCHAR=1,32
OK

# Verify the previous write attempt
AT+GATTCHAR=1
0x20
OK

AT+GATTLIST

Lists all custom GATT services and characteristics that have been defined on the device.

  • Codebase Revision: 0.3.0
  • Parameters: None
  • Response: A list of all custom services and characteristics defined on the device.
# Clear any previous custom services/characteristics
AT+GATTCLEAR
OK

# Add a battery service (UUID = 0x180F) to the peripheral
AT+GATTADDSERVICE=UUID=0x180F
1
OK
  
# Add a battery measurement characteristic (UUID = 0x2A19), notify enabled
AT+GATTADDCHAR=UUID=0x2A19,PROPERTIES=0x10,MIN_LEN=1,VALUE=100
1
OK
  
# Add a custom service to the peripheral
AT+GATTADDSERVICE=UUID128=00-11-00-11-44-55-66-77-88-99-AA-BB-CC-DD-EE-FF
2
OK

# Add a custom characteristic to the above service (making sure that there
# is no conflict between the 16-bit UUID and bytes 3+4 of the 128-bit service UUID)
AT+GATTADDCHAR=UUID=0x0002,PROPERTIES=0x02,MIN_LEN=1,VALUE=100
2
OK

# Get a list of all custom GATT services and characteristics on the device
AT+GATTLIST
ID=01,UUID=0x180F
  ID=01,UUID=0x2A19,PROPERTIES=0x10,MIN_LEN=1,MAX_LEN=1,VALUE=0x64
ID=02,UUID=0x11, UUID128=00-11-00-11-44-55-66-77-88-99-AA-BB-CC-DD-EE-FF
  ID=02,UUID=0x02,PROPERTIES=0x02,MIN_LEN=1,MAX_LEN=1,VALUE=0x64
OK

AT+GATTCHARRAW

This read only command reads binary (instead of ASCII) data from a characteristic. It is non-printable but has less overhead and is easier when writing libraries in Arduino.

  • Codebase Revision: 0.7.0
  • Parameters: The numeric ID of the characteristic to display the data for
  • Output: Binary data corresponding to the specified characteristic.

Basé sur "Bluefruit LE Shield" d'Adafruit Industries, écrit par Kevin Townsend - Traduit en Français par shop.mchobby.be CC-BY-SA pour la traduction
Toute copie doit contenir ce crédit, lien vers cette page et la section "crédit de traduction".

Based on "Bluefruit LE Shield" from Adafruit Industries, written by Kevin Townsend - Translated to French by shop.mchobby.be CC-BY-SA for the translation
Copies must includes this credit, link to this page and the section "crédit de traduction" (translation credit).

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com