Broadcaster and Observer BLE Types

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I believe that the mybeacon.c file is an example of a BLE Broadcaster type.  Is there an example of a BLE Observer type?  Also, how can I switch between Broadcaster and Observer dynamically in the same code?

I want each device to be able to broadcast packets periodically, but otherwise function as an observer and listen to all broadcast packets.  I am also not clear from the mybeacon.c file how to modify the data packet within the advertisement with my own data, nor how much data I can embed within an advertisement..

Thanks

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello sabertron_dev

Here is an example app that is capable of swapping between advertising and scanning.

Definitions

First things first. I hope we are on the same page with the definitions, because here at Broadcom we use "Advertising" and "Scanning". I'm not sure what the convention is for the whole BLE community in general, but we categorize the devices that transmit advertisement packets as "Advertisers" and the devices that scan for such advertisements as "Scanners". I hope these definitions match what you meant by broadcasters and observers.

Advertisement

BLE advertisement packets consists of 31 bytes. Each field (i.e. appearance, name, service UUID or similar) has a header of 2 bytes (length and type), meaning that the maximum user payload is 29 bytes. That means the more fields that are packed into one advertisement packet, there are less bytes freed for user payload.

Here's an example of advertisement data(AD) from Bluetooth SIG documentation. (pdf attached)

pastedImage_0.png

You can view all the different data types and formats in the documentation attached.

Advertisement Field

In our SDK, each field is represented by BLE_ADV_FIELD data structure. Here's the definition:

typedef PACKED struct
{
    UINT8 len; //length of field
    UINT8 val; //value of field
    UINT8 data[ADV_LEN_MAX-2]; // This is the data and the biggest one is 31-2 = 29
} BLE_ADV_FIELD;

Notice the length, value, and the actual data in the struct corresponds to how AD is formatted in the example above.

You can change the advertisement packet by defining the fields in an array and initializing them.

    BLE_ADV_FIELD adv[2];

     // Format advertisement data.  Data consists of 2 fields.  Standard Advertisement flags
     // and Broadcom Vendor specific data.  The vendor specific data consists of 
     // 16 byte UUID and a message "Hello"

     // flags
     adv[0].len     = 1 + 1; // 1 (data length) + 1 (value)
     adv[0].val     = ADV_FLAGS;
     adv[0].data[0] = LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED;

     adv[1].len     = 23 + 1; // 23 (data length) + (value)
     adv[1].val     = ADV_MANUFACTURER_DATA; // (AD_TYPE == 0xff)
     adv[1].data[0] = 0x0f;  // Broadcom  (Company Identifier 2 bytes)
     adv[1].data[1] = 0x00;

     // Set UUID
     BT_MEMCPY(&adv[1].data[2], mybeacon_uuid, 16);

     // Set "Hello" message
     BT_MEMCPY(&adv[1].data[18], msg, 5);

Then, you'll have to call bleprofile_GenerateADVData function to actually generate the AD.

bleprofile_GenerateADVData(adv, 2);

where the first parameter is the array to BLE_ADV_FIELD and the second is the number of fields.

Starting Advertisement

You can start advertising in few different ways.

If you have the BLE_PROFILE_CFG defined for the app, then you can simply start by calling:

    bleprofile_Discoverable(HIGH_UNDIRECTED_DISCOVERABLE, NULL);

Or you can start advertising by setting up the advertisement parameters yourself.

   blecm_startAdv(
        HCIULP_ADV_NONCONNECTABLE_EVENT,                        // non-connectable undirected advertisement
        160,                                                                                   // adv interval 100 msec
        HCIULP_ADV_CHANNEL_MAP_MASK,                               // all channels
        HCIULP_PUBLIC_ADDRESS,                                              // int advAdrType,
        HCIULP_ADV_FILTER_POLICY_WHITE_LIST_NOT_USED,   // int advFilterPolicy,
        HCIULP_PUBLIC_ADDRESS,                                             // int initiatorAdrType,
        NULL);

Advertisement packets have different types.

pastedImage_8.png

The first argument to this function, blecm_startAdv defines the type of the advertisement.

Value Passed
Advertisement Type
0x00ADV_IND
0x02ADV_DISCOVER_IND
0x03ADV_NONCONN_IND

You can refer to the "auto-generated API" for more details on this function.

Scanning

In order to start scanning, you simply need to call blecen_Scan function.

    blecen_Scan(HIGH_SCAN);

Or to turn it off:

    blecen_Scan(NO_SCAN);

Advertisement Handler

You need to register a handler if you want to do anything with the advertisement packet in the app create function.

 
void advertisement_handler(HCIULP_ADV_PACKET_REPORT_WDATA *evt);
...

void basic_create(void)
{
    ...

    // register to process peripheral advertisements, notifications and indications
    blecm_RegleAdvReportCb((BLECM_FUNC_WITH_PARAM) advertisement_handler);
    ...
}

Swapping between Advertiser and Scanner

I have made an example app that swaps its role between advertising and scanning. The files are attached as adv.h and adv.c

The app first starts scanning, but you can change its role by pushing the button on the board. It has a minimum RSSI value, so you'll need to have advertising device close to the scanner in order for the scanner to pick up the advertisement.

I was able to put the code into two Tag 3 boards and test their functions.

Here's the app in action.

Both apps started:

pastedImage_18.png

One of them starts advertising:

pastedImage_22.png

Roles switched:

pastedImage_24.png

AD in detail:

pastedImage_26.png

Notice how the advertisement data corresponds to how we set the BLE_ADV_FIELD array above.

API

Unfortunately, we currently don't have more detailed documentation other the ones that are already provided with the SDK.

However, we are trying to document better for the upcoming versions of the SDK. So until then please ask us any questions you have in the forums, and stay active in the community.

Please let us know if this helped or not.

Thank you.


jamesle1

andrew997

View solution in original post

0 Likes
3 Replies
Anonymous
Not applicable

Hi sabertron_dev,

For changing advertisement packets visit WICED Smart User's Guide ->advertising.

For scanning and advertising, check out hello_client.

-Kevin

0 Likes
Anonymous
Not applicable

Hi Kevin,

I have reviewed both of those resources previously.  The thread on changing advertisement packets doesn't actually demonstrate changing any packet.  It would be great if it demonstrated exactly how to inject new data into on of the example advertisements, but it doesn't do that..

The example for hello_client has a lot going on.  Does it handle dynamic switching between broadcast and observer types?  If so, how?

I feel like the docs are missing something.  The user guide is a collection of posts on the user forum. Where is the complete reference manual with API/architecture overview?  (And I'm not talking about the auto-generated API web page.)

Thanks

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello sabertron_dev

Here is an example app that is capable of swapping between advertising and scanning.

Definitions

First things first. I hope we are on the same page with the definitions, because here at Broadcom we use "Advertising" and "Scanning". I'm not sure what the convention is for the whole BLE community in general, but we categorize the devices that transmit advertisement packets as "Advertisers" and the devices that scan for such advertisements as "Scanners". I hope these definitions match what you meant by broadcasters and observers.

Advertisement

BLE advertisement packets consists of 31 bytes. Each field (i.e. appearance, name, service UUID or similar) has a header of 2 bytes (length and type), meaning that the maximum user payload is 29 bytes. That means the more fields that are packed into one advertisement packet, there are less bytes freed for user payload.

Here's an example of advertisement data(AD) from Bluetooth SIG documentation. (pdf attached)

pastedImage_0.png

You can view all the different data types and formats in the documentation attached.

Advertisement Field

In our SDK, each field is represented by BLE_ADV_FIELD data structure. Here's the definition:

typedef PACKED struct
{
    UINT8 len; //length of field
    UINT8 val; //value of field
    UINT8 data[ADV_LEN_MAX-2]; // This is the data and the biggest one is 31-2 = 29
} BLE_ADV_FIELD;

Notice the length, value, and the actual data in the struct corresponds to how AD is formatted in the example above.

You can change the advertisement packet by defining the fields in an array and initializing them.

    BLE_ADV_FIELD adv[2];

     // Format advertisement data.  Data consists of 2 fields.  Standard Advertisement flags
     // and Broadcom Vendor specific data.  The vendor specific data consists of 
     // 16 byte UUID and a message "Hello"

     // flags
     adv[0].len     = 1 + 1; // 1 (data length) + 1 (value)
     adv[0].val     = ADV_FLAGS;
     adv[0].data[0] = LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED;

     adv[1].len     = 23 + 1; // 23 (data length) + (value)
     adv[1].val     = ADV_MANUFACTURER_DATA; // (AD_TYPE == 0xff)
     adv[1].data[0] = 0x0f;  // Broadcom  (Company Identifier 2 bytes)
     adv[1].data[1] = 0x00;

     // Set UUID
     BT_MEMCPY(&adv[1].data[2], mybeacon_uuid, 16);

     // Set "Hello" message
     BT_MEMCPY(&adv[1].data[18], msg, 5);

Then, you'll have to call bleprofile_GenerateADVData function to actually generate the AD.

bleprofile_GenerateADVData(adv, 2);

where the first parameter is the array to BLE_ADV_FIELD and the second is the number of fields.

Starting Advertisement

You can start advertising in few different ways.

If you have the BLE_PROFILE_CFG defined for the app, then you can simply start by calling:

    bleprofile_Discoverable(HIGH_UNDIRECTED_DISCOVERABLE, NULL);

Or you can start advertising by setting up the advertisement parameters yourself.

   blecm_startAdv(
        HCIULP_ADV_NONCONNECTABLE_EVENT,                        // non-connectable undirected advertisement
        160,                                                                                   // adv interval 100 msec
        HCIULP_ADV_CHANNEL_MAP_MASK,                               // all channels
        HCIULP_PUBLIC_ADDRESS,                                              // int advAdrType,
        HCIULP_ADV_FILTER_POLICY_WHITE_LIST_NOT_USED,   // int advFilterPolicy,
        HCIULP_PUBLIC_ADDRESS,                                             // int initiatorAdrType,
        NULL);

Advertisement packets have different types.

pastedImage_8.png

The first argument to this function, blecm_startAdv defines the type of the advertisement.

Value Passed
Advertisement Type
0x00ADV_IND
0x02ADV_DISCOVER_IND
0x03ADV_NONCONN_IND

You can refer to the "auto-generated API" for more details on this function.

Scanning

In order to start scanning, you simply need to call blecen_Scan function.

    blecen_Scan(HIGH_SCAN);

Or to turn it off:

    blecen_Scan(NO_SCAN);

Advertisement Handler

You need to register a handler if you want to do anything with the advertisement packet in the app create function.

 
void advertisement_handler(HCIULP_ADV_PACKET_REPORT_WDATA *evt);
...

void basic_create(void)
{
    ...

    // register to process peripheral advertisements, notifications and indications
    blecm_RegleAdvReportCb((BLECM_FUNC_WITH_PARAM) advertisement_handler);
    ...
}

Swapping between Advertiser and Scanner

I have made an example app that swaps its role between advertising and scanning. The files are attached as adv.h and adv.c

The app first starts scanning, but you can change its role by pushing the button on the board. It has a minimum RSSI value, so you'll need to have advertising device close to the scanner in order for the scanner to pick up the advertisement.

I was able to put the code into two Tag 3 boards and test their functions.

Here's the app in action.

Both apps started:

pastedImage_18.png

One of them starts advertising:

pastedImage_22.png

Roles switched:

pastedImage_24.png

AD in detail:

pastedImage_26.png

Notice how the advertisement data corresponds to how we set the BLE_ADV_FIELD array above.

API

Unfortunately, we currently don't have more detailed documentation other the ones that are already provided with the SDK.

However, we are trying to document better for the upcoming versions of the SDK. So until then please ask us any questions you have in the forums, and stay active in the community.

Please let us know if this helped or not.

Thank you.


jamesle1

andrew997

0 Likes