Bluetooth Services, Characteristics and Value - ozarchie/BlueBasic GitHub Wiki

Syntax

GATT SERVICE "<uuid>"
GATT CHARACTERISTIC "<uuid>" "<description>"
GATT [READ|WRITE|WRITENORSP|NOTIFY|INDICATE] <variable> [ONREAD GOSUB <linenum>][ONWRITE GOSUB <linenum>]
GATT END


Description

The BLE Generic Attribute Protocol allows you to read, write, and access data seamlessly. It’s a protocol for handling generic attributes. It manages Writing and Reading these attributes, as well as notifications when an attribute changes state. It is only available when the two BLE devices are connected to each other. To get the attributes, both devices need to exchange multiple packets, so the client discovers the services available and then reads their information. You can’t access GATT services and GATT characteristics when broadcasting because advertising is unidirectional.
Services, Characteristics and Descriptors are organised in a hierarchy with Services at the top and Descriptors at the bottom. Services contain one or more Characteristics. A Characteristic owns zero or more Descriptors because Descriptors are completely optional whereas a Service must contain at least one Characteristic.
A Service is a container for logically related Bluetooth data items. Those data items are called Characteristics.
Characteristics are items of data which relate to a particular internal state of the device or perhaps some state of the environment which the device can measure using a sensor.
Sometimes Characteristics represent configuration data such as the frequency at which you want something to be measured.


Examples

10 PINMODE P1(1) OUTPUT    
40 // Identify the GATT Service 25FB9E92-1616-448D-B5A3-F70A64BDA73A      
41 GATT SERVICE "25FB9E92-1616-448D-B5A3-F70A64BDA73A"      
50 // Identify the Characteristic D8ABBBE7-F10B-4EC3-B781-DBCBD2334400 as having two states  
51 GATT CHARACTERISTIC "D8ABBBE7-F10B-4EC3-B781-DBCBD2334400" "On/Off"      
60 // When the characteristic is written call the sub-routine      
61 GATT READ WRITE A ONWRITE GOSUB 200      
71 GATT END    
201 P1(1)=A    
210 RETURN    
⚠️ **GitHub.com Fallback** ⚠️