Other Parts Discussed in Thread: BLE-STACK
I am developing the CC2640 and I seems like BLE advertise would timeout after a while.
Is this control in the Stack level ?
How could I check for status or change the timeout value ?
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.
Hi Dilbert,
I am assuming that you are developing off of the simple_peripheral?
I'd recommend you to look at the GAP (section 5.1.8) and GAP Role (section 5.2 and 5.2.1) sections in the device's software developer guide. This is available in the docs folder of the SDK or at the following link: http://www.ti.com/lit/swru393
You will find in the GAP section that to configure the GAP layer, you will be able to modify and check various parameters that involve things such as advertising intervals and windows by using GAP_SetParameter() and GAP_GetParameter(). I'd recommend you to check Appendix A for the full GAP API. Section A.2 will give you a list and descriptions of all the configurable parameters.
For reference, I have included below an example of how this is used in the SimpleBLEPeripheral_init() of simple_peripheral.c:
// Set advertising interval for limited and general advertising modes { uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL; GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MIN, advInt); GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MAX, advInt); GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MIN, advInt); GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, advInt); }
Similarly in the GAP Role Peripheral section, you'll find that you can use GAPRole_SetParameter() and GAPRole_GetParameter() to modify and check various parameters that involve things such as GAPROLE_ADVERT_OFF_TIME. This determines how long to remain off after advertising stops before starting again. For the full GAPRole Peripheral API refer to Appendix B. Section B.2 will give you a list and descriptions of all the configurable parameters.
For reference, I have included below an example of how this is used in the SimpleBLEPeripheral_init() of simple_peripheral.c:
uint16_t advertOffTime = 0; uint8_t enableUpdateRequest = DEFAULT_ENABLE_UPDATE_REQUEST; uint16_t desiredMinInterval = DEFAULT_DESIRED_MIN_CONN_INTERVAL; uint16_t desiredMaxInterval = DEFAULT_DESIRED_MAX_CONN_INTERVAL; uint16_t desiredSlaveLatency = DEFAULT_DESIRED_SLAVE_LATENCY; uint16_t desiredConnTimeout = DEFAULT_DESIRED_CONN_TIMEOUT; // Set the GAP Role Parameters GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initialAdvertEnable); GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t), &advertOffTime); GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData), scanRspData); GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData); GAPRole_SetParameter(GAPROLE_PARAM_UPDATE_ENABLE, sizeof(uint8_t), &enableUpdateRequest); GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, sizeof(uint16_t), &desiredMinInterval); GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, sizeof(uint16_t), &desiredMaxInterval); GAPRole_SetParameter(GAPROLE_SLAVE_LATENCY, sizeof(uint16_t), &desiredSlaveLatency); GAPRole_SetParameter(GAPROLE_TIMEOUT_MULTIPLIER, sizeof(uint16_t), &desiredConnTimeout);
You will want to note that when setting GAPROLE_ADVERT_OFF_TIMEto zero the device will go into the waiting state after being discoverable and will not advertise again until GAPROLE_ADVERT_ENABLED is set back to TRUE.
Also to advertise indefinitely, you will want to make sure DEFAULT_DISCOVERABLE_MODE is defined as GAP_ADTYPE_FLAGS_GENERAL.
-Sy Su
Hi Dilbert,
From the CC2640 known issues page on the wiki (linked at the end of post), there is a known issue where advertising may stop when performing extended periods (i.e., more than 1 hour) of continuous advertising due to an anomaly in the TI-RTOS RF Driver used by BLE-Stack v2.2.0 and v2.2.1. A patch and a workaround using a periodic clock to stop and restart advertisements is detailed on the third bullet at the following link: http://processors.wiki.ti.com/index.php/CC2640_Porting_Projects#Known_Issues_.2F_Workarounds_for_BLEv2.2.1
This might be the issue you are facing.
-Sy Su
Thanks so much for the info. I believe this was the issue I faced before.
However, after I changed the design to stop BLE after 30mins without connect. But after number of hours (not sure how long),
BLE advertise did not wake up...I just reviewed the patch, it is using same calls as below.
void processGapStateChange(bool mode)
{
uint8_t adv_enabled;
if (mode==ON) // ON service
{
// Start advertising
adv_enabled = TRUE;
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &adv_enabled);
}
else
{
// Disconnect
GAPRole_TerminateConnection();
// Stop advertising
adv_enabled = FALSE;
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &adv_enabled);
}
}
Hi Dilbert,
Yes that is similar. A few questions:
How is the project triggering to re-advertise after the mentioned "number of hours"?
Is the re-advertisement and the stop advertisement both tied to a periodic clock?
In processGapStateChange(), when mode = ON does that indicate that it was already advertising?
If possible please attach your .c file so I can take a look at the full story.
-Sy Su
Hi Sy Su,
Thanks for the info... I think having the Stack turn OFF and turn ON within 30 mins solve the problem. Need to test more to confirm.
In my project :
processGapStateChange(OFF) is called by a Application Task which set to 30 mins when no activity.
processGapStateChange(ON) is called when User press a button to wake up device.