5 years, 3 months ago.

How can add multiple SERVICE_DATA ?

Hi,

I need to add more than one SERVICE_DATA in the GAP advertising frame. At the moment with the following piece of code I add one service_data and it is working!

uint8_t service_data[4];

Service Data UUID Address service_data[0] = GAPButtonUUID & 0xff; service_data[1] = GAPButtonUUID >> 8; Values (ie temperature = 20.39 °C) service_data[2] = 2039 & 0xff; service_data[3] = 2039 >> 8;

ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, (uint8_t *)service_data, sizeof(service_data));

I need to add one more service data but calling this : "ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, (uint8_t *)service_data, sizeof(service_data));" update service_data instead of adding new one...

For information : I manage to do that (adding 2 services data) with a custom code (not mbed) with Visual Studio and GDB

Thank you, Fred

Ok guys...here is a working solution but you need to edit GapAvertisingData.h...

addData function in GapAvertisingData checks whether the advDataType to be inserted does not already exist...so just remove this check to add more than one : GapAdvertisingData::SERVICE_DATA :)

Replace :

ble_error_t addData(DataType_t advDataType, const uint8_t *payload, uint8_t len) { /* Find field */ uint8_t* field = findField(advDataType);

if (field) { /* Field type already exist, either add to field or replace */ return addField(advDataType, payload, len, field); } else { /* Field doesn't exists, insert new */ return appendField(advDataType, payload, len); } }

By

ble_error_t addData(DataType_t advDataType, const uint8_t *payload, uint8_t len) { /* Find field */ uint8_t* field = findField(advDataType);

if (field) { /* Field type already exist, either add to field or replace */ return addField(advDataType, payload, len, field); } else { /* Field doesn't exists, insert new */ return appendField(advDataType, payload, len); } }

posted by Frederic Guiet 15 Dec 2018

For mbed guys : maybe it could be a good idea to allow adding more than one advDataType GapAdvertisingData::SERVICE_DATA ?

Can you take this suggestion into account in the next mbed release?

Fred

posted by Frederic Guiet 15 Dec 2018

1 Answer

5 years, 3 months ago.

Hi Frederic,

Thank you for this suggestion, it is a good point, I will take this into internal discussion.

Would you mind to tell me more about the application requiring multiple SERVICE_DATA?

Thanks,

- Desmond, team Mbed

Accepted Answer

Hi Desmond,

Thank you for answering.

I am requiring multiple SERVICE_DATA in one of my home automation scenario. The idea is to put an mbed powered beacon in each room of my house. Each beacon will advertise the following data:

  • Temperature
  • Humidity
  • Battery level

I am using the htu21d sensor.

I could have used typical BLE services with characteristics but it would have meant that my main program should connect to each BLE beacon:

1. Lost of time 2. Lost of battery

So I decided to use directly SERVICE_DATA in the GAP advertisements...

Moreover, when I am using nRF Connect from my mobile...all the service_data are displayed!!

Is it clear?

Yours Truly, Frederic

posted by Frederic Guiet 19 Dec 2018

Thanks, it is clear!

Using adv is making more sense than typical services in this scenario.

We really appreciate this suggestion.

- Desmond

posted by Desmond Chen 19 Dec 2018

For everyone has the same question,

With mbed OS 5.11, we introduced some new API, we provide an advertising data builder https://github.com/ARMmbed/mbed-os/blob/master/features/FEATURE_BLE/ble/gap/AdvertisingDataBuilder.h that has less limitation than the previous one. With setAdvertisingPayload(), you can set any payload you want.

We will keep improving those APIs for better using on advertising packets.

- Desmond, team Mbed

posted by Desmond Chen 27 Dec 2018