Hello all,
I have a project based on the BLE bridge project. My CC2541 was set up to advertise as a peripheral immediately on bootup, and I wanted to change it to advertise after a button press (like the keyfob project).
I set up the GAP during initialization as follows:
// Setup the GAP Peripheral Role Profile { uint8 initial_advertising_enable = FALSE; // By setting this to zero, the device will go into the waiting state after // being discoverable for 30.72 second, and will not being advertising again // until the enabler is set back to TRUE uint16 gapRole_AdvertOffTime = 0; uint8 enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST; uint16 desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL; uint16 desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL; uint16 desired_slave_latency = DEFAULT_DESIRED_SLAVE_LATENCY; uint16 desired_conn_timeout = DEFAULT_DESIRED_CONN_TIMEOUT; // Set the GAP Role Parameters GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable ); GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &gapRole_AdvertOffTime ); GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( scanData ), scanData ); GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advData ), advData ); GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request ); GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval ); GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval ); GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &desired_slave_latency ); GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &desired_conn_timeout ); } // Set the GAP Characteristics GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName ); // Setup the GAP Bond Manager { uint32 passkey = DEFAULT_PASSCODE; uint8 pairMode = DEFAULT_PAIRING_MODE; uint8 mitm = DEFAULT_MITM_MODE; uint8 ioCap = DEFAULT_IO_CAPABILITIES; uint8 bonding = DEFAULT_BONDING_MODE; GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof( uint32 ), &passkey ); GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof( uint8 ), &pairMode ); GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof( uint8 ), &mitm ); GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof( uint8 ), &ioCap ); GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof( uint8 ), &bonding ); } #if defined FEATURE_OAD VOID OADTarget_AddService(); // OAD Profile #endif // Simple GATT Profile DataProfile_AddService( GATT_ALL_SERVICES ); // Setup the SimpleProfile Characteristic Values { uint8 charValue1 = 1; uint8 charValue2 = 2; DataProfile_SetParameter( DATAPROFILE_CHAR1, sizeof ( uint8 ), &charValue1 ); DataProfile_SetParameter( DATAPROFILE_CHAR2, sizeof ( uint8 ), &charValue2 ); } // Register callback with SimpleGATTprofile VOID DataProfile_Register( &DataProfileCBs ); // Set up HID keyboard service HidKbd_AddService( ); // Register for HID Dev callback TBHidDev_Register( &hidEmuKbdCfg, &BLE_BridgeCBs ); //disable halt during RF (needed for UART / SPI) HCI_EXT_HaltDuringRfCmd(HCI_EXT_HALT_DURING_RF_DISABLE); // Setup a delayed profile startup osal_set_event( BLE_Bridge_TaskID, SBP_START_DEVICE_EVT ); }
On the button press event handling, I use the following:
UINT8 gapRoleState;
GAPRole_GetParameter(GAPROLE_STATE, &gapRoleState);
if (gapRoleState!=GAPROLE_CONNECTED)
{
UINT8 current_adv_enabled_status;
UINT8 new_adv_enabled_status = TRUE;
GAPRole_GetParameter(GAPROLE_ADVERT_ENABLED, ¤t_adv_enabled_status);
if (current_adv_enabled_status==FALSE)
{
UINT8 pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status );
GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof( uint8 ), &pairMode);
}
}
The results are, I can see the unit broadcasting for 30sec after the button is pressed, but when I try to connect or pair from an iOS device, there is no response from the CC2541. However, if I set up initial_advertising_enable=TRUE in my initialization then even after several minutes I am able to press a key, advertise, and connect to the device.
This makes me feel that setting initial_advertising_enable= FALSE during initialization is causing some of the callbacks to be improperly set up, so that the CC2541 is unable to respond to the link request from the iOS device.
However, I have looked at the keyfob project and cannot see what I am leaving out.
Does anyone know if there is another critical part of the linking process that I need to, and have not, changed?
Thanks,
Sam