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.

LAUNCHXL-CC2640R2: Attempting to change the data packets advertised during runtime using the skeleton code of Simple_broadcaster

Part Number: LAUNCHXL-CC2640R2
Other Parts Discussed in Thread: CC2640

Hello,

I am able to run the simple broadcaster easily on CCS 9.1.0 using the CC2640R2, and the simplelink_cc2640r2_sdk_5_10_00_02. 

For my changing data packets i tried to use code found i this questions: https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/716072/ccs-launchxl-cc2640r2-dynamic-adjust-advertising-data-for-simple-broadcaster

This was unsuccessful as far as i am aware. The finished product should be a non-connectable beacon transmission in which the raw data within a BLE scanner app will show the Hex string packets changing during runtime. 

So far i have some idea of using GAPRole_SetParameter() . And an old example code that does not run on my version of CCS. 

Does anyone have any idea how to achieve this or has possibly done this before (Im new to the CC2640 and not sure how to correctly alter codes to my requirements just yet). I have also struggled to find any documentation of source code for my requirements. 

ANy help would be great!

Thanks 

Josh

  • Hi Josh,

    Could you please specify which BLE stack you are using? In other words, where in the SDK have you found the example you are using?

    Thanks and regards,

  • Hi, 

    im using the simple_broadcaster project from the BLE5stack examples within the simplelink_cc2640r2_sdk_5_10_00_02

  • Hi Joshua,

    Thank you for posting in the E2E forums, the information you are looking for can be found in the BLE5 Stack User's Guide under Generic Access Protocol (GAP). The section that discusses changing advertisement data is here.

    Please let me know if this helps.

    Best,

    Nima Behmanesh

  • Hi i have read a lot of stuff which all works within the simple_peripheral project. Will it also work for the non-connectable beacon transmission in Simple_broadcaster?

  • Also when i add the codes in this link i cannot see a data change in my BLE scanner! any idea how to correctly veiw the change in data?

  • Hi Joshua,

    Hi i have read a lot of stuff which all works within the simple_peripheral project. Will it also work for the non-connectable beacon transmission in Simple_broadcaster?

    Yes, the link above will work in the Simple Broadcaster example. Here is some example code to explain how I accomplished this. The following code is from the BLE 5 Simple Broadcaster example for the CC2640 device.

    Step 1) Change the event mask in SimpleBroadcaster_processGapMessage() function. The function is GapAdv_setEventMask(). Please look for the /**** SOLUTION ****/ comment in the code snippet.

    static void SimpleBroadcaster_processGapMessage(gapEventHdr_t *pMsg)
    {
      switch(pMsg->opcode)
      {
        case GAP_DEVICE_INIT_DONE_EVENT:
        {
          bStatus_t status = FAILURE;
    
          gapDeviceInitDoneEvent_t *pPkt = (gapDeviceInitDoneEvent_t *)pMsg;
    
          if(pPkt->hdr.status == SUCCESS)
          {
            // Store the system ID
            uint8_t systemId[DEVINFO_SYSTEM_ID_LEN];
    
            // use 6 bytes of device address for 8 bytes of system ID value
            systemId[0] = pPkt->devAddr[0];
            systemId[1] = pPkt->devAddr[1];
            systemId[2] = pPkt->devAddr[2];
    
            // set middle bytes to zero
            systemId[4] = 0x00;
            systemId[3] = 0x00;
    
            // shift three bytes up
            systemId[7] = pPkt->devAddr[5];
            systemId[6] = pPkt->devAddr[4];
            systemId[5] = pPkt->devAddr[3];
    
            // Set Device Info Service Parameter
            DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId);
    
            // Display device address
            Display_printf(dispHandle, 1, 0, "%s Addr: %s",
                           (addrMode <= ADDRMODE_RANDOM) ? "Dev" : "ID",
                           Util_convertBdAddr2Str(pPkt->devAddr));
            Display_printf(dispHandle, 2, 0, "Initialized");
    
            // Setup and start Advertising
            // For more information, see the GAP section in the User's Guide:
            // http://software-dl.ti.com/lprf/ble5stack-latest/
    
            // Temporary memory for advertising parameters. These will be copied
            // by the GapAdv module
            GapAdv_params_t advParamLegacy = GAPADV_PARAMS_LEGACY_SCANN_CONN_FIXED_CHAN;
    
            #ifndef BEACON_FEATURE
              advParamLegacy.eventProps = GAP_ADV_PROP_SCANNABLE | GAP_ADV_PROP_LEGACY;
            #else
              advParamLegacy.eventProps = GAP_ADV_PROP_LEGACY;
            #endif // !BEACON_FEATURE
    
            // Create Advertisement set
            status = GapAdv_create(&SimpleBroadcaster_advCallback, &advParamLegacy,
                                   &advHandleLegacy);
            SIMPLEBROADCASTER_ASSERT(status == SUCCESS);
    
            // Load advertising data
            status = GapAdv_loadByHandle(advHandleLegacy, GAP_ADV_DATA_TYPE_ADV,
                                         sizeof(advertData), advertData);
            SIMPLEBROADCASTER_ASSERT(status == SUCCESS);
    
            // Load scan response data
            status = GapAdv_loadByHandle(advHandleLegacy, GAP_ADV_DATA_TYPE_SCAN_RSP,
                                         sizeof(scanRspData), scanRspData);
            SIMPLEBROADCASTER_ASSERT(status == SUCCESS);
    
            /*** SOLUTION ***/
            status = GapAdv_setEventMask(advHandleLegacy, GAP_ADV_EVT_MASK_ALL); // <- Changed to GAP_ADV_EVT_MASK_ALL
            SIMPLEBROADCASTER_ASSERT(status == SUCCESS);
            /*** END SOLUTION ***/
            
            // Enable legacy advertising
            status = GapAdv_enable(advHandleLegacy, GAP_ADV_ENABLE_OPTIONS_USE_MAX , 0);
            SIMPLEBROADCASTER_ASSERT(status == SUCCESS);
          }
    
          break;
        }
    
        default:
          Display_clearLine(dispHandle, 2);
          break;
      }
    }

    Step 2) Change the advertisement data in the GAP_EVT_ADV_END case. This will change the advertisement data after the previous one is sent.

    static void SimpleBroadcaster_processAdvEvent(sbGapAdvEventData_t *pEventData)
    {
      switch (pEventData->event)
      {
        case GAP_EVT_ADV_START_AFTER_ENABLE:
          Display_printf(dispHandle, 2, 0, "Advertising");
          break;
        case GAP_EVT_ADV_END_AFTER_DISABLE:
          Display_printf(dispHandle, 3, 0, "Disabled");
          break;
        case GAP_EVT_INSUFFICIENT_MEMORY:
          break;
    
        case GAP_EVT_ADV_START:
            Display_printf(dispHandle, 4, 0, "STARTING");
          break;
    
        case GAP_EVT_ADV_END:
          Display_printf(dispHandle, 5, 0,"STOPPING");
          GapAdv_prepareLoadByHandle(advHandleLegacy, GAP_ADV_FREE_OPTION_DONT_FREE);
    
          // Sample buffer modification, advCount is a changing variable.
          if (advCount == 5) advCount = 0;
          else advCount += 1;
    
          advertData[5] = advCount;
          advertData[6] = advCount + 1;
          advertData[7] = advCount + 2;
          // Reload buffer to handle, enable advertising.
          GapAdv_loadByHandle(advHandleLegacy, GAP_ADV_DATA_TYPE_ADV, sizeof(advertData), advertData);
    
          break;      
          
        default:
          // Do nothing.
          break;
      }
      // All events have associated memory to free except the insufficient memory
      // event
      if (pEventData->event != GAP_EVT_INSUFFICIENT_MEMORY)
      {
        ICall_free(pEventData->pBuf);
      }
    }

    Also when i add the codes in this link i cannot see a data change in my BLE scanner! any idea how to correctly veiw the change in data?

    I'm not sure what BLE Scanner you're using, but some applications fail to show the new packets of information. I used the SmartRF Packet Sniffer 2.

    Please let me know if this helps!

    Best,

    Nima Behmanesh

  • Hi i have given this a go and i recieved an error saying advCount is undefined. Where would i initialise this in the code?

  • Hi, just an update i just set it to a variable in the local variables section and it works, my BLE scanner shows the hex string of advertisement data changing every time I refresh.

    Thanks for your help!

  • Hi Joshua, 

    Glad it worked! 

    Best,

    Nima Behmanesh