Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Manufacturer Data - Bug #646

Open
lilindian16 opened this issue Mar 11, 2024 · 1 comment
Open

Set Manufacturer Data - Bug #646

lilindian16 opened this issue Mar 11, 2024 · 1 comment

Comments

@lilindian16
Copy link

Current implementation to set manufacturer data void NimBLEAdvertising::setManufacturerData(const std::string &data)

Issue: Trying to set the first two bytes of the manufacturer data to Manufacturer ID from Bluetooth SIG list (Nordic Semi ASA - 0x0059) results in no manufacturer data shown in advertisement

Current implementation:

void NimBLEAdvertising::setManufacturerData(const std::string &data)
{
    m_mfgData.assign(data.begin(), data.end());
    m_advData.mfg_data = &m_mfgData[0];
    m_advData.mfg_data_len = m_mfgData.size();
    m_advDataSet = false;
} // setManufacturerData

My example where it breaks:

uint16_t manufacturerID = 0x0059; // Nordic Semi ASA
uint8_t dataToAdvertise[4];
dataToAdvertise[0] = (manufacturerID >> 8) & 0xFF;
dataToAdvertise[1] = (manufacturerID & 0xFF);
dataToAdvertise[2] = 0xAB; // Placeholder random data
dataToAdvertise[3] = 0xCD; // Placeholder random data
pAdvertising->setManufacturerData((char *)dataToAdvertise); // Cast to char * to work with std::string 

m_mfgData.size() returns zero since the first byte in dataToAdvertise array is a null-character (0)

Proposed Alternative:

void NimBLEAdvertising::setManufacturerData(uint8_t *data, uint8_t length)
{
    m_mfgData.assign(data, data + length);
    m_advData.mfg_data = &m_mfgData[0];
    m_advData.mfg_data_len = length;
    m_advDataSet = false;
} // setManufacturerData

We can overload the setManufacturerData function with the uint8_t* type and a length parameter to update the advertising vector

uint16_t manufacturerID = 0x0059; // Nordic Semi ASA
uint8_t dataToAdvertise[4];
dataToAdvertise[0] = (manufacturerID >> 8) & 0xFF;
dataToAdvertise[1] = (manufacturerID & 0xFF);
dataToAdvertise[2] = 0xAB;
dataToAdvertise[3] = 0xCD;
pAdvertising->setManufacturerData(dataToAdvertise, sizeof(dataToAdvertise));
@h2zero
Copy link
Owner

h2zero commented Apr 21, 2024

Thanks, I will look to change this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants