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

b = ble("Thingy")

% Create a characteristic object that represents the "Temperature" characteristic.

c = characteristic(b,"Weather Station Service","Temperature")

% Because this characteristic supports "Notify", you can use read to get the latest data.

data = read(c)

% You can also return the timestamp of the latest data.

[data,timestamp] = read(c)

% Interpret the data in Celsius. The first byte represents the integer part of the temperature and the second byte represents the decimal part with a resolution of 0.01.

temperature = data(1) + data(2)*0.01

% Copyright 2019 The MathWorks, Inc.