diff --git a/src/NimBLEAdvertising.cpp b/src/NimBLEAdvertising.cpp index 26e5553..10ccaf6 100644 --- a/src/NimBLEAdvertising.cpp +++ b/src/NimBLEAdvertising.cpp @@ -151,23 +151,29 @@ void NimBLEAdvertising::setName(const std::string& name) { /** * @brief Set the advertised manufacturer data. * @param [in] data The data to advertise. + * @param [in] length The length of the data. */ -void NimBLEAdvertising::setManufacturerData(const std::string& data) { - std::vector(data.begin(), data.end()).swap(m_mfgData); +void NimBLEAdvertising::setManufacturerData(const uint8_t* data, size_t length) { + std::vector(data, data + length).swap(m_mfgData); m_advData.mfg_data = &m_mfgData[0]; m_advData.mfg_data_len = m_mfgData.size(); m_advDataSet = false; } // setManufacturerData +/** + * @brief Set the advertised manufacturer data. + * @param [in] data The data to advertise. + */ +void NimBLEAdvertising::setManufacturerData(const std::string& data) { + setManufacturerData(reinterpret_cast(data.data()), data.length()); +} // setManufacturerData + /** * @brief Set the advertised manufacturer data. * @param [in] data The data to advertise. */ void NimBLEAdvertising::setManufacturerData(const std::vector& data) { - std::vector(data.begin(), data.end()).swap(m_mfgData); - m_advData.mfg_data = &m_mfgData[0]; - m_advData.mfg_data_len = m_mfgData.size(); - m_advDataSet = false; + setManufacturerData(&data[0], data.size()); } // setManufacturerData /** diff --git a/src/NimBLEAdvertising.h b/src/NimBLEAdvertising.h index e3cd540..ca03dd0 100644 --- a/src/NimBLEAdvertising.h +++ b/src/NimBLEAdvertising.h @@ -94,6 +94,7 @@ class NimBLEAdvertising { bool stop(); void setAppearance(uint16_t appearance); void setName(const std::string& name); + void setManufacturerData(const uint8_t* data, size_t length); void setManufacturerData(const std::string& data); void setManufacturerData(const std::vector& data); void setURI(const std::string& uri);