This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-EM-CC2340R5: How to dynamic change advertising data?

Part Number: LP-EM-CC2340R5

Hi,

My goal is : change advertising data for each advertising.

So I change manufactor data to increase 1.

For example, advertising once every 6 seconds. it will be:

second 0, payload 0x01

sencond 6, advertising with payload 0x02.

second N*6, advertising with payload 0xN(N by hex and uint32_t)

Below is my change:

But when I test it, I am not sure it work properly or not.  It does change but not evey time advertising in my Android Phone. 

I am not sure it is my coding issue or mabe my andoid app tool issue.

So i just post my code here to be confirmed.

Thanks.

  • Hi,

    Thank you for reaching out. Can you specify which SDK version you are using? We will look into this and get back to you as soon as possible.

    Best Regards,

    Jan

  • Hello Aichi,

    I am assuming you are using the latest SDK.

    I would suggest looking into our training material here. Especially the "Advertising Task 2 – Change the Advertisement Data".

    I think you may be missing to disable advertising first (for example GapAdv_prepareLoadByBuffer() will automatically  for all advertising handles that use this buffer) .

    Also, don't forget to enable again the GAP_ADV_EVT_MASK_START flag as part of the GAP_ADV_EVT_MASK_ALL that you disabled for power testing (if not yet enabled again).

    Then, you could do something like this:

    BLEAppUtil_EventHandler_t peripheralAdvHandler =
    {
        .handlerType    = BLEAPPUTIL_GAP_ADV_TYPE,
        .pEventHandler  = Broadcaster_AdvEventHandler,
        .eventMask      = BLEAPPUTIL_ADV_START_AFTER_ENABLE |
                          BLEAPPUTIL_ADV_END_AFTER_DISABLE |
                          BLEAPPUTIL_ADV_START
    };
    
    void Peripheral_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {
       switch(event)
       {
            .
            .
            .
            
            case BLEAPPUTIL_ADV_START:
            {
                updateAdvData = false;
                    
                //Don't free anything since we're going to use the same buffer to re-load
                status = GapAdv_prepareLoadByBuffer(broadcasterAdvHandle_1, GAP_ADV_FREE_OPTION_DONT_FREE);
                    
                //Only update the data when return is successful
                if (status == SUCCESS)
                {
                    // Sample buffer modification
                    advData1[26] = new_value; //could be a global variable that is constantly incrementing here. 
                        
                    // Reload buffer to handle
                    // Here the advDataLen = sizeof(advData1) and it is setup in the app\_peripheral.c
                    // under advSetInitParamsSet_1
                    GapAdv_loadByHandle(broadcasterAdvHandle_1, GAP_ADV_DATA_TYPE_ADV, broadcasterInitAdvSet1.advDataLen, advData1);
                }
                break;
            }
        }
     }

    Consider that doing this every time will increase max power consumption as you are constantly waking up to increase the manufacturer value at every advertisement start.

    Please let me know how it goes.

    BR,

    David.

  • it works by this way:GapAdv_prepareLoadByBuffer

    The last byte is changed

    But i dont know why it will be icall_abort if i am using GapAdv_prepareLoadByHandle, maybe my parameters are incorrect.

  • Hello Aichi,

    Could you please share more details about the error (icall_abort)? When is this happening?

    BR,

    David