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.

CC2541 iBeacon. Change advertising data regularly

Hello,

I have adapted the SimpleBLEBroadcaster in order to send data as an iBeacon like this:

0x02, 0x01, 0x06, 0x1A, 0xFF, 0x4C, 0x00, 0x02, 0x15, //iBeacon Prefix
0xAB, 0xAB, 0xAB, 0xBB, 0xCC, 0x11, 0x22, 0x22, 0x55, 0x77, 0x11, 0x11, 0x11, 0x11, 0x99, 0x99, //UUID
0x9F, 0xAC, //Major
0x98, 0xAD, //Minor
0xC2 // Tx Power

Once I get this I want to change the Major and Minor in each advert the iBeacon do. I tried changing the adv data before calling:

GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData );

But it doesn't work, and it's the only place where advertData is used, so I don't find out where the change must be done.

Any idea?

Thanks.

Iván Gómez Bustinduy.

  • Hey Iván,

    The GAPRole_SetParamter() for ADVERT_DATA in broadcaster.c simply does a memcpy of new data to the gapRole_AdvertData array. This new value doesn't get passed down into the link layer and actually take affect until you disable and re-enable advertising.

    Try using GAP_UpdateAdvertisingData() after you set the gapRole_AdvertData. This should update without having to disable/enable advertising.

    -Matt

  • Hi Matthew,

    If I understand you well I should use GAP_UpdateAdvertisingData(); after the GAPRole_SetParameter in SimpleBLEBroadcaster_Init, so like this:

    int cont=0;

    if(cont==0)
    {
    uint8 advertData[] =
    {
    0x02, 0x01, 0x06, 0x1A, 0xFF, 0x4C, 0x00, 0x02, 0x15, //iBeacon Prefix
    0xAB, 0xAB, 0xAB, 0xBB, 0xCC, 0x11, 0x22, 0x22, 0x55, 0x77, 0x11, 0x11, 0x11, 0x11, 0x99, 0x99, //UUID
    0x9F, 0xAC, //Major
    0x00, 0x00, //Minor
    0xC2
    };

    GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData );

    cont++;
    }
    else if(cont==1)
    {
    uint8 advertData[] =
    {
    0x02, 0x01, 0x06, 0x1A, 0xFF, 0x4C, 0x00, 0x02, 0x15, //iBeacon Prefix
    0xAB, 0xAB, 0xAB, 0xBB, 0xCC, 0x11, 0x22, 0x22, 0x55, 0x77, 0x11, 0x11, 0x11, 0x11, 0x99, 0x99, //UUID
    0x9F, 0xAC, //Major
    0x00, 0x01, //Minor
    0xC2
    };

    GAP_UpdateAdvertisingData(task_id, TRUE,sizeof( advertData ), advertData );


    cont=0;
    }

     

    GAPRole_SetParameter( GAPROLE_ADV_EVENT_TYPE, sizeof( uint8 ), &advType );

     

    But it doesn't work. I want that the advertising change continuously, in some codes I see the advertisement was in a infinite for, but here I have only seen something similar in OSAL, so only enters once in the function and only uses the 1st if clause, and I want it enters as many times as I need.

     

    Iván.

     

  • Hey Ivan,

    I would recommend setting up a periodic event and making the adv data updates within that event. OSAL is event based so instead of a for loop where you continuously update the adv data you'll have to use events. You can control the timing of the event as well.

    Take a look at simpleBLEPeripheral for an example of using periodic events and performing periodic tasks. Any variables declared within your periodic task that you want to keep consistent across events will have to be declared as static. This means your "cont" variable will have to be static.

    -Matt

  • Hi Matthew,

    It worked perfectly.

    Thanks you very much.

    Now I'm going to add some extra features including some external libs, I hope I won't have problems :).

    Regards,

    Iván