-
Notifications
You must be signed in to change notification settings - Fork 73
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
Adding Manufacturer specific data into Advertising data #26
Comments
Hi, |
For those interested, I also did something similar as the FTaluk solution. I'll have to think more how to include this in a way that's generic enough for making a PR but in the meanwhile, here's my implementation in Mgmt.cpp that calls addAdvertising adding one 128-bit service UUID and a 8 chars short name into the advertisement packet: // Start advertising with custom data
// Advertisement packet will contain: flags, shortName, uuid
bool Mgmt::addAdvertising(std::string shortName, const uint8_t* uuid)
{
constexpr size_t ADVERTISING_SHORTNAME_MAX_LEN = 8;
constexpr size_t ADVERTISING_UUID_LEN = 16;
constexpr size_t ADVERTISING_MAX_DATALEN = 2 + ADVERTISING_SHORTNAME_MAX_LEN + 2 + ADVERTISING_UUID_LEN;
struct SRequest : HciAdapter::HciHeader
{
uint8_t instance;
uint32_t flags;
uint16_t duration;
uint16_t timeout;
uint8_t advDataLen;
uint8_t scanRspLen;
uint8_t data[ADVERTISING_MAX_DATALEN];
} __attribute__((packed));
SRequest request;
request.code = Mgmt::EAddAdvertisingCommand;
request.controllerId = controllerIndex;
request.dataSize = sizeof(SRequest) - sizeof(HciAdapter::HciHeader);
request.instance = 1u;
request.flags = 3u; // Connectable && Discoverable, see Bluez/lib/mgmt.h
request.duration = 0;
request.timeout = 0;
size_t shortNameEffectiveLen = std::min(ADVERTISING_SHORTNAME_MAX_LEN, shortName.length());
request.advDataLen = ADVERTISING_MAX_DATALEN - (ADVERTISING_SHORTNAME_MAX_LEN - shortNameEffectiveLen);
request.scanRspLen = 0;
request.data[0] = static_cast<uint8_t>(ADVERTISING_UUID_LEN + 1);
request.data[1] = 0x07; // Incomplete UUID list
memcpy(&request.data[2], uuid, ADVERTISING_UUID_LEN);
request.data[2+ADVERTISING_UUID_LEN] = static_cast<uint8_t>(1 + shortNameEffectiveLen);
request.data[3+ADVERTISING_UUID_LEN] = 0x08; // Set short name
memcpy(&request.data[4+ADVERTISING_UUID_LEN], shortName.c_str(), shortNameEffectiveLen);
if (!HciAdapter::getInstance().sendCommand(request))
{
Logger::warn(SSTR << " + Failed to start advertising with UUID");
return false;
}
return true;
} |
@stez-mind can you give more detail about the usage of |
Hi @xuio, I just checked my implementation and I was not calling explicitly |
@stez-mind Thanks for answering! Can you share the context in which you call |
Hi,
I am kind of new to C++ and Bluetooth. I have just started using your server. I have successfully implemented a basic NUS based chat application by modifying your server code and standalone app code. Thanks for all your effort.
But I need to add manufacturer specific data into the advertising data. I could not find any easy way until now to do this. With my limited understanding, I realized that I have to change things much deep into your codes (e.g. using add Advertising command of management-api instead of set advertising command). But the problem is that I am afraid of chaning things without having a complete grasp (which I don't have at the moment).
p.s. I found a python based example where they provide a seperate method just to set this data. But I need a C++ based solution.
Could you please help? Thanks in advance.
The text was updated successfully, but these errors were encountered: