Closed sanastasiou closed 1 year ago
fPAdvertisingData->setServiceData(NimBLEUUID(constants::SERVICE_UUID.c_str()), std::string((char*)&fState, sizeof(fState)));
fPAdvertisingData->setAdvertisementData(adData);
Those 2 lines are the issue. You cannot mix the use of the NimBLEAdvertisementData
and the advertising class data.
What you need to do is set one or the other, such as changing the first line here to:
adData.setServiceData(NimBLEUUID(constants::SERVICE_UUID.c_str()), std::string((char*)&fState, sizeof(fState)));
Or remove the use of NimBLEAdvertisementData
and instead just set the manufacturer data in the advertising class:
fPAdvertisingData->setManufacturerData(std::string((char *)&buffer[0], count));
Oh thank you very much for the fast reply. Going to try this out and let u know. I have just migrated from the old kolban libraries to this one and that used to work back there.
I will let u know and close this ticket if it works.
auto const count = sprintf(buffer, "v:%d|%d", aPseudoVoltage, fState);
fPAdvertisingData->stop();
fPAdvertisingData->setManufacturerData(std::string((char *)&buffer[0], count));
fPAdvertisingData->addServiceUUID(constants::SERVICE_UUID.c_str());
fPAdvertisingData->setScanResponse(true);
fPAdvertisingData->start();
So, after stoping / starting the advertisement like this, still the same issue.
More testing. Simply doing this (no start/stop involved):
char buffer[20];
auto const count = sprintf(buffer, "v:%d|%d", voltage, 5);
fPAdvertisingData->setServiceData(NimBLEUUID(constants::SERVICE_UUID.c_str()), std::string((char*)&count, sizeof(count)));
fPAdvertisingData->setScanResponse(true);
fPAdvertisingData->start();
Results in advertisement data but which does not contain any service information.
{
fPAdvertisingData = NimBLEDevice::getAdvertising();
char buffer[20];
auto const count = sprintf(buffer, "v:%d|%d", voltage, 5);
fAdvertisementData.setCompleteServices(NimBLEUUID(constants::SERVICE_UUID.c_str()));
fAdvertisementData.setManufacturerData(std::string((char*)&count, sizeof(count)));
fPAdvertisingData->setAdvertisementData(fAdvertisementData);
fPAdvertisingData->setScanResponse(true);
}
This works, including start/stop. Closing the ticket.
Hi,
I have the following code
` fPServer = BLEDevice::createServer(); fPServer->setCallbacks(new ble::ServerCallbacks(fDevicePin, *this));
That works fine and in the scan response I can see the service offered. Now, later in the code I want to modify the advertisement data.
After this is done, the advrtisement data does not contain any information about the service.. So I am confused a bit. Why does the advertisement data does not contain service info after I stop-start it?