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.

CC2652R7: Use GapInit_connect() function in Simple peripheral example

Part Number: CC2652R7
Other Parts Discussed in Thread: LAUNCHXL-CC26X2R1, SYSCONFIG

Tool/software:

Dear Team,

I am working on a project which is built on Simple_peripheral example with SimpleLink CC13xx CC26xx SDK (7.41.00.17), and I changed the device's pairing mode to 'Initiate a pairing request'. 

Now after the first time my phone connects to the device and bonds to the device, I want my device can auto reconnect to my phone when I power on it in the subsequent time (like those wireless speakers and earphones). Can I use the GapInit_connect() to do this? If yes, I am struggling how to get the bonded device address to use this function, do you have any suggestions?

Thanks a lot.

  • Hi,

    Thank you for reaching out. When using Bluetooth LE, only the central device can initiate a connection. Typically, smart phones will act as the central device and the accessories (such as speakers or headphones) behave as a peripheral. To cause the connection to auto-form, the CC2652R7 should be left advertising and the smart phone should have some sort of application that scans and connects to the CC2652R7 automatically. You can also implement certain accessory profiles (such as HID) which will cause the smart phone to auto-connect without the use of a custom app, but these are restricted to certain use cases.

    I highly recommend referencing the connections lab for more information:

    https://dev.ti.com/tirex/content/cc13xx_cc26xx_simplelink_academy_7_41_00_00/_build_cc13xx_cc26xx_simplelink_academy_7_41_00_00/source/ble5stack/ble_connections/ble_connections.html

    Best Regards,

    Jan

  • Thank you for the information.

    For accessory profiles (such as HID) you have mentioned, may I know is there any Ti related document for more information?

    Thanks a lot!

  • Hi,

    No problem! This will vary by the OS, but you should be able to find information about which services have native support for Android and iOS in their developer forums or their developer documentation.

    Best Regards,

    Jan

  • Hi Jan,

    I found your example 'The HID Over GATT Profile (HOGP)' in GitHub(https://github.com/TexasInstruments/HOGP-BLE-HID-EXAMPLE) and tried to import to CCS. But then I found that I cannot build the project, I am using CCS12.8.1.

    May I know is there another way to import the project like directly import via 'Resource Explorer'? Or the example is not compatible for CCS12.8,1 and CC2652R7?

    Thanks a lot!

  • Hi,

    Glad you were able to find the example! I would highly recommend reading the companion app note I have written for that example (linked below):

    https://www.ti.com/lit/swra715

    Table 5.1 lists the software and hardware requirements for that specific example. The example was made for SDK 5.10 and CCS 10.3 usign the LAUNCHXL-CC26X2R1. That said, you should be able to migrate the example to the latest SDK and the CC2652R7 through the use of the migration guides included in the SDK. Once migrated, I expect the example to be able to work as expected on the R7 device as well.

    Best Regards,

    Jan

  • Hi Jan, 

    I tried to migrate the example of 'The HID Over GATT Profile (HOGP)' these days. It seems it did not do the auto-connect to the phone. Then I tried to learn the codes in 'hiddev.c', and I found

    ' if (HidDev_bondCount() > 0)
    {
    // Start high duty cycle advertising.
    status = GapAdv_enable(advHandleHigh, GAP_ADV_ENABLE_OPTIONS_USE_MAX, 0);
    HIDDEV_ASSERT(status == SUCCESS);
    hidAdvState = HID_ADV_STATE_HIGH;
    }'

    It seems if found that there is a bounded device, it will change 'hidAdvState', but this is still in advertising stage. So, I am confused that which part of codes may do the auto-connect function. Could you help me with this? Thank you so much!

  • Hi,

    If the phone is not auto-connecting, then its possible the CC device is either not advertising or the bond was not formed. Can you double check if the pairing was completed or if you can see the advertisements from another device?

    Best Regards,

    Jan

  • Hi Jan,

    Maybe there were some missing parts when I migrated the example. 

    For:

    // Adverisement set #1, initial
    // Create Advertisement set #1 and assign handle
    status = GapAdv_create(&HidDev_advCallback, &advParamsInitial, &advHandleInitial);
    HIDDEV_ASSERT(status == SUCCESS);

    // Load advertising data for set #1 that is statically allocated by the app
    status = GapAdv_loadByHandle(advHandleInitial, GAP_ADV_DATA_TYPE_ADV,
    sizeof(advData), advData);
    HIDDEV_ASSERT(status == SUCCESS);

    // Load scan response data for set #1 that is statically allocated by the app
    status = GapAdv_loadByHandle(advHandleInitial, GAP_ADV_DATA_TYPE_SCAN_RSP,
    sizeof(scanData), scanData);
    HIDDEV_ASSERT(status == SUCCESS);

    // Set event mask for set #1
    status = GapAdv_setEventMask(advHandleInitial, GAP_ADV_EVT_MASK_START_AFTER_ENABLE
    | GAP_ADV_EVT_MASK_END_AFTER_DISABLE | GAP_ADV_EVT_MASK_SET_TERMINATED);

    // Adverisement set #2, high
    // Create Advertisement set #2 and assign handle
    status = GapAdv_create(&HidDev_advCallback, &advParamsHigh, &advHandleHigh);
    HIDDEV_ASSERT(status == SUCCESS);

    // Load advertising data for set #2 that is statically allocated by the app
    status = GapAdv_loadByHandle(advHandleHigh, GAP_ADV_DATA_TYPE_ADV,
    sizeof(advData), advData);
    HIDDEV_ASSERT(status == SUCCESS);

    // Load scan response data for set #2 that is statically allocated by the app
    status = GapAdv_loadByHandle(advHandleHigh, GAP_ADV_DATA_TYPE_SCAN_RSP,
    sizeof(scanData), scanData);
    HIDDEV_ASSERT(status == SUCCESS);

    // Set event mask for set #2
    status = GapAdv_setEventMask(advHandleHigh,GAP_ADV_EVT_MASK_START_AFTER_ENABLE
    | GAP_ADV_EVT_MASK_END_AFTER_DISABLE | GAP_ADV_EVT_MASK_SET_TERMINATED);

    // Adverisement set #3, low
    // Create Advertisement set #3 and assign handle
    status = GapAdv_create(&HidDev_advCallback, &advParamsLow, &advHandleLow);
    HIDDEV_ASSERT(status == SUCCESS);

    // Load advertising data for set #3 that is statically allocated by the app
    status = GapAdv_loadByHandle(advHandleLow, GAP_ADV_DATA_TYPE_ADV,
    sizeof(advData), advData);
    HIDDEV_ASSERT(status == SUCCESS);

    // Load scan response data for set #3 that is statically allocated by the app
    status = GapAdv_loadByHandle(advHandleLow, GAP_ADV_DATA_TYPE_SCAN_RSP,
    sizeof(scanData), scanData);
    HIDDEV_ASSERT(status == SUCCESS);

    // Set event mask for set #3
    status = GapAdv_setEventMask(advHandleLow, GAP_ADV_EVT_MASK_START_AFTER_ENABLE
    | GAP_ADV_EVT_MASK_END_AFTER_DISABLE | GAP_ADV_EVT_MASK_SET_TERMINATED);

    // Enable legacy advertising for set #1
    status = GapAdv_enable(advHandleInitial, GAP_ADV_ENABLE_OPTIONS_USE_MAX, 0);
    HIDDEV_ASSERT(status == SUCCESS);
    hidAdvState = HID_ADV_STATE_INITIAL;

    I could not find the declaration of 'advData' and 'scanData'. Is any part missing?

    And I cannot open the 'hid_emu_kbd.syscfg' file, CCS 12.8.1 shows 'Unexpected error encountered when opening the file!  Please make sure the file is within the context of a valid and opened CCS Project.  If the project has errors, these may be preventing this file from opening.' Will this be the reason that I failed to successfully run this sample? 

    Thank you so much!

  • Hi,

    No problem! The advData and and scanData variables i believe are declared within the auto-generated files created by SysConfig. It is possible that the issue is due to the sysconfig error. Can you confirm that there is only one sysconfig file in the project and it is placed as a local copy in the project root?

    Best Regards,

    Jan

  • Hi Jan,

    I think there is only one sysconfig file in this project:

  • Hi,

    Understood, I think i see what the problem is. I believe the .syscfg file has to be at the root of the project. Can you move i to the root where the README.md is located?

    Best Regards,

    Jan

  • Hi,

    I can open all files now, after learning the codes, I found this:

    // If bonded and normally connectable start advertising.
    if ((HidDev_bondCount() > 0) && (pHidDevCfg->hidFlags & HID_FLAGS_NORMALLY_CONNECTABLE))
    {
    if (hidAdvState != HID_ADV_STATE_NONE)
    {
    HidDev_StopAdvertising();
    }
    status = GapAdv_enable(advHandleLow, GAP_ADV_ENABLE_OPTIONS_USE_MAX, 0);
    HIDDEV_ASSERT(status == SUCCESS);
    hidAdvState = HID_ADV_STATE_LOW;
    }

    the above code snippet shows the device will advertise again after disconnection, if bondCount > 0. 

    After that the device and auto-reconnect to the phone again? If yes, what role do HID profiles play for the auto-reconnection function?

    Could you please help me, thanks a lot.

  • Also I found that, after I try to add some display message for debugging like the following:

    the auto-reconnect function cannot work anymore, but the connection and pair process should be the same.

    Could you please help me as well? Thank you so much.

  • Hi,

    Glad moving the syscfg file was helpful! By default, the device will advertise after disconnection if a bond has been made. The phone/computer will then be able to identify the advertisement as coming from a previously paired device and attempt to reconnect.

    I am not sure why the display would break the reconnecting. Is the device hanging?

    Best Regards,

    Jan

  • Hi, 

    I am trying to figure out. But now there is another question in this example:

    For my understanding, if the paring mode is 'wait for a pairing request', the peripheral device should not initiate a pairing request, that means there should not be a pop-up window that request the phone to pair, right?

    But after running this example, there is a pop-up window after I try to connect to the device from my phone, so could you please explain what's the logic behind it?

    Thank you so much!!! 

  • Hi,

    Your understanding is correct that the peripheral should not initiate the request, but not regarding the pop-up. I believe in the HID example, the central device (phone/PC/etc) will be the one to initiate the pairing and cause the pop-up to start. This occurs because the phone will attempt to access a characteristic that requires pairing and this kicks off the pairing process. In this case, it was the central who caused the pairing procedure to begin.

    Best Regards,

    Jan

  • Hi Jan,

    I noticed that there is an appearance value in syscfg in Advertisement data:

    and I found this value is related to the 'assigned numbers document' (Assigned Numbers | Bluetooth® Technology Website):

    May I know is this related to the small icon show in the nRF Connect app?

     (nRF Connect app)

    But I tried to change the value to 0x 3C1, the small icon still shows the Mouse instead of the keyboard.

    And for the icon shows in my iphone, it just even a bluetooth sign, not a mouse.

    May I know is there any ways to change the icon appearance?

      (iphone widget)

    Thanks a lot!

  • Hi,

    I believe the logo used by the smart phone and smart phone applications will depend on how they want to interpret each appearance option. I would recommend referecing the apple developer guide to see how they decide which logo to use in their bluetooth widgets. Its also possible that the previous apperance value is being cached and used by the app or phone to display the older logo instead of a new one.

    Best Regards,

    Jan