Comments (1)
It looks like my issue is related to an issue that was closed in July 2021: #7
So, in the absence of a response, I decided to try and understand these utility classes better and see if I can come up with a solution that fits within this design structure.
Well I did come up with something that works and this also removes the need to hard code the device name within gatt_server_process.h (get_device_name override function).
So for gatt_server_process.h
/**
* Simple GattServer wrapper. It will advertise and allow a connection.
*/
class GattServerProcess : public BLEProcess
{
public:
static const char *DEVICE_NAME;
static const char *GATTSERVICE_UUID;
GattServerProcess(events::EventQueue &event_queue, BLE &ble_interface) :
BLEProcess(event_queue, ble_interface)
{
}
const char* get_device_name() override
{
return DEVICE_NAME;
}
/** Service list uuid */
virtual const UUID get_servicelist_uuid() override
{
return UUID(GATTSERVICE_UUID);
}
};
#endif /* GATT_SERVER_PROCESS_H_ */
Then within your main app code you can provide the data - note that here I simply created an example using a 128-bit UUID:
const char *GattServerProcess::DEVICE_NAME = "GattServer";
const char *GattServerProcess::GATTSERVICE_UUID = "51311102-030e-485f-b122-f8f381aa84ed";
int main()
{ .... }
And finally within ble_process.h you can add in a new virtual function, similar to get_device_name() to set the UUID service list. I did the following:
/** Name we advertise as. */
virtual const char* get_device_name()
{
static const char name[] = "";
return name;
}
/** Service list uuid */
virtual const UUID get_servicelist_uuid()
{
static const char serviceuuid[] = "0000";
return UUID(serviceuuid);
}
protected:
/**
* Start the advertising process; it ends when a device connects.
*/
void start_advertising()
{
ble_error_t error;
<<<<< ----- etc. ----- >>>>>>>>>>>>>>>
_adv_data_builder.clear();
_adv_data_builder.setFlags();
_adv_data_builder.setName(get_device_name());
UUID _GATT_uuid = get_servicelist_uuid();
_adv_data_builder.setLocalServiceList(mbed::make_Span(&_GATT_uuid, 1));
<<<<< ----- etc. ----- >>>>>>>>>>>>>>>
}
I have only tested once to confirm that I can see the device name and GATT service UUID being advertised and my phone was able to connect and view the added service etc.
If there is a cleaner way of doing this it would be good to know.
Thanks.
from mbed-os-ble-utils.
Related Issues (6)
- Is there a reason to time out advertising after 4 seconds and then restart advertising again (found within ble_process.h).
- The callback object is not called when connected to a peer (ble_process.h on_connect) HOT 1
- No examples can be found using ble_app.h
- Should BLEProcess and BLEApp run dispatch_forever()? HOT 1
- Allow more custimozation of the advertising payload HOT 2
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 mbed-os-ble-utils.