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.

Stop non connectable advertisement

Other Parts Discussed in Thread: CC2541

Hi,

Using CC2541 with BLE stack 1.4.0

My scenario is such that I need to toggle between non connectable indirect advertisement and connectable indirect advertisement.

So, I went to GAPROLE_WAITING and added a code to toggle the GAPROLE_ADV_EVENT_TYPE.

However once it goes to non connectable advertisement mode, it never stops advertising! I checked the GAPROLE_WAITING and it never enters that state. In Btool the device is always discovered in Btool as non connectable advertisement.

I have tried setting TGAP_LIM_ADV_TIMEOUT so that it stops advertising but no use.

Regards,

Tejas J

  • Can you post your code snippet how you are toggling the advertisements? Are you disabling/stopping the previous advertisement before enabling/starting the new one?
  • case GAPROLE_WAITING:
          {
            #if defined ( _DEBUG_MODE )
              printf("GAP role waiting\n");
            #endif
              
            if (broadcastMode == 1) {
              broadcastMode = 0;
              uint8 advertEnabled = 1;
              uint8 advType = GAP_ADTYPE_ADV_IND;
              GAPRole_SetParameter( GAPROLE_ADV_EVENT_TYPE, sizeof( uint8 ), &advType );
              GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof(advertData), advertData );
              GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof(uint8),  &advertEnabled );
            }
          }
          break;

    This is the code where, after advertisement is over, I check whether it was using broadcast mode or not. In order to enter this state, the device should have stopped advertisement.

    static void broadcastShift(uint8 *count, uint8 flag)
    {
      if (*count == ADVERTISEMENT_OFFTIME)
      {
        *count = 0;
        broadcastMode = 1;
        // Broadcast mode. Non connectable.
        uint8 advType = GAP_ADTYPE_ADV_NONCONN_IND;
        GAPRole_SetParameter( GAPROLE_ADV_EVENT_TYPE, sizeof( uint8 ), &advType );
        GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( broadcastData ), broadcastData );
        GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof(uint8),  &broadcastMode );
      }
    }

    This function is called from a periodic event where I increment count only if device is not advertising. Else, I reset count back to zero.

    The idea is that after some condition checks, I enter GAP_ADTYPE_ADV_NONCONN_IND type of adv for 20 sec, then as a normal peripheral for 20 sec and then I go to sleep for  ADVERTISEMENT_OFFTIME. After ADVERTISEMENT_OFFTIME, it again enters GAP_ADTYPE_ADV_NONCONN_IND adv and the process repeats.

    Currently, it starts advertising with type GAP_ADTYPE_ADV_NONCONN_IND after sleep time and never enters GAPROLE_WAITING

    As I mentioned earlier, using GAP_ADTYPE_FLAGS_LIMITED with TGAP_LIM_ADV_TIMEOUT set to 20.