A characteristic holds a value. This value is represented by a std::vector<std::byte> byte vector.
A characteristic can also be set with properties to read, write, and notify. feeling-blue provides
the tools to read, write, and be notified from characteristics.
bluetooth::Characteristic¶Represents a characteristic.
Public Functions
T>read()¶Read the characteristic. Compatible template types are listed at supported template types section.
Recommended default usage to return a vector of bytes: std::vector<std::byte> bytes = some_char->read<std::vector<std::byte>>();
You can also return an int if you know your characteristic value is a 4-byte integer in little-endian order: int x = some_char->read<int>();
a byte vector.
T: the type your want the data to be read as.
T>write_without_response(T data)¶Write to characteristic using a vector of bytes. Will not print error if write fails. You can transmit more data with this method than write_with_response(). Compatible template types are listed at supported template types section.
examples: std::vector<std::byte> data = {...}; some_char->write_without_response<std::byte>(data); some_char->write_without_response<int>(1);
asynchronous.
data: byte vector of your data.
T>write_with_response(T data)¶Write to characteristic with response. If the write_without_response fails and verbose mode is on, the console will print an error and the program will continue running. Compatible template types are listed at supported template types section.
examples: std::vector<std::byte> data = {...}; some_char->write_with_response<std::byte>(data); some_char->write_with_response<int>(1);
data: byte vector of your data.
notify(const std::function<void(std::vector<std::byte>)> &callback)¶Enable notifications from the characteristic and set callback function to do something with the data when the device notifies.
this method returns when the callback is successfully set. Your callback is asynchronously called whenever a notification is triggered.
callback: function to do something with notification data.