Comments (5)
Hi,
I figured it out. Actually, I created a simple work-around. The setAdvertising() method Mgmt.cpp file has been modified. This method now disables the "setAdvertising" command and then uses "addAdvertising Command" to make use of a custom AD-Payload. I used only one instance, zero for all time related parameters, zero for all flags. I didn't use the scan response field. The whole raw-advertising data is provied as adv_data. This worked for me.
from gobbledegook.
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;
}
from gobbledegook.
@stez-mind can you give more detail about the usage of Mgmt::addAdvertising
?
It is not working for me. You have to do Mgmt::setAdvertising(0)
after, right?
from gobbledegook.
Hi @xuio,
sorry it has been quite a long time since I worked on this.
I just checked my implementation and I was not calling explicitly Mgmt::setAdvertising(0)
directly from the C++ sources but I remember that I was doing a few tasks separately with a script calling hcitool.
from gobbledegook.
@stez-mind Thanks for answering!
Can you share the context in which you call Mgmt::addAdvertising(...)
. Thanks!
from gobbledegook.
Related Issues (20)
- Discovering GATT Services: Error 22 (0x16) terminate local host HOT 2
- Support for org.bluez.LEAdvertisingManager1 ? HOT 1
- Sending raw bytes instead of null terminated string.
- Pairing/Bonding planned? HOT 1
- Is there a callback on connect and disconnect? HOT 5
- Using Cmake with gobbledegook
- thread too slow when used with external hardware device (realsense camera)
- Is there any example of how to read descriptors that are being updated by clients ?
- Example Server cannot connect to iOS device
- Nordic UART GATT Service for GGK
- Glib Lib HOT 5
- gattLoggerDebug() ConnectionEvent address byte order inverted from BlueZ
- Making GGK work on Gentoo64?
- Application as Maintainer HOT 1
- Not an issue
- .onWriteValue stalls
- Why limit the length of shortname to 10?
- Set Local Name Command
- Advice for anyone using ggk in an autostart context
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gobbledegook.