%% Write to a Descriptor on a Bluetooth Low Energy Peripheral Device
% Write data to a descriptor on a Bluetooth Low Energy Peripheral Device.
% 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 or 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 on the Bluetooth SIG website.
% This value changes when the notification or indication status changes. For example, write to this value to enable notification for the "Heart Rate Measurement" characteristic. Then, observe the change in values by reading the descriptor again.

write(d,[1 0])
data = read(d)

% Copyright 2019 The MathWorks, Inc.