%% Read Descriptor Data from a Bluetooth Low Energy Peripheral Device
% Access a descriptor on your peripheral device and read its data.
% Create a connection to a nearby Bluetooth Low Energy peripheral device.

b = ble("DemoDev")

% Create a characteristic object that represents the "Heart Rate Measurement" characteristic.

c = characteristic(b,"Heart Rate","Heart Rate Measurement")

% Create a descriptor object that represents the "Client Characteristic Configuration" descriptor.

d = descriptor(c,"Client Characteristic Configuration")

% This descriptor contains information about whether notification and indication are enabled or disabled. You can use read to get the current data.

data = read(d)

% Interpret this data by referring to the specification for this descriptor found in the Bluetooth Core Specification on the Bluetooth SIG website.
% This value changes when the notification or indication status changes. For example, subscribe to notification using subscribe. Then, observe the change in the value by reading the descriptor again.

subscribe(c,'notification');
data = read(d)

% Copyright 2019 The MathWorks, Inc.