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.

Read BLEPeripheral char #4 notification data in BLECentral example code

Hello Ti team

I am working on BLEPeripheral and BLECentral example code on CC2640R2 launchpad. My requirement is to send 20 bytes of data on Char #4 "FFF4" from simplePeripheral to SimpleCentral device so how we can enable the Char #4 notification and how notification handler get called when data arrive in Central device?

I have already followed below example but it's not help full also here not mentioned the notification data handler.

Please send me sample central code which can enable the notification and read data on notification data handler from peripheral device when new data arrive.

Any help will be appreciated.

Regards

Raj

  • Hi Raj,

    If you look in simple_gatt_profile.c, you will notice that characteristic 4 is already setup to use notifications. In order to make the characteristic to support more than a byte, please refer to how the characteristic 5 is setup (i.e. make use of array instead of a single byte variable).

    Also, please have a look at this SLA module on the same topic;

     

  • Hello Joakim

    Thanks for quick answer.

    Your answer is not relevant to my question. I know how to increase one byte to 244 byte (implement DLE support). 

    My question is, how to enable Char #4 notification and receive notification data in SimpleBLEClient example code? Mean to enable and received both things should happen from CC2640R2 client example code.

    Please let me know if my question is not clear.

  • Hi,

    Sorry for misunderstanding. There is a good example in our Simple Serial Socket application, found here:

    Specifically, take a look at the SimpleStreamClient_enableNotifications function

    /*********************************************************************
     * @fn      SimpleStreamClient_enableNotifications
     *
     * @brief   Enable notifications for given connection and CCCD handle
     *
     * @return  FAILURE or GATT_WriteNoRsp return value
     */
    bStatus_t SimpleStreamClient_enableNotifications(uint16_t connHandle)
    {
        // Process message.
        attWriteReq_t req;
        bStatus_t retVal = FAILURE;
        uint8 configData[2] = {0x01,0x00};
        req.pValue = GATT_bm_alloc(connHandle, ATT_WRITE_REQ, 2, NULL);
    
        // Enable notify for outgoing data
        if ( (req.pValue != NULL) && streamServiceHandle.chars[1].cccdHandle)
        {
            req.handle = streamServiceHandle.chars[1].cccdHandle;
            req.len = 2;
            memcpy(req.pValue, configData, 2);
            req.cmd = TRUE;
            req.sig = FALSE;
            retVal = GATT_WriteNoRsp(connHandle, &req);
        }
    
        return retVal;
    }

    Does this help?

  • Thanks Joakim.

    The answer is clear my first question like how to enable the notification but cloud you please let me know where I receive the notification data. I meant where is the notification data handler where I just read the new arrived data.

  • Hi,

    Refer to the same example

    /*********************************************************************
     * @fn      SimpleSerialSocketClient_processGATTMsg
     *
     * @brief   Process GATT messages and events.
     *
     * @return  none
     */
    static void SimpleSerialSocketClient_processGATTMsg(gattMsgEvent_t *pMsg)
    {
      if (state == BLE_STATE_CONNECTED)
      {
        // A notification was received, process data recevied from the steam socket
        if (pMsg->method == ATT_HANDLE_VALUE_NOTI)
        {
            uartMsg_t *newMsg;
            newMsg = SimpleStreamClient_allocateWithHeadroom(sizeof(uartMsg_t) + pMsg->msg.handleValueNoti.len);
    
            if (newMsg) {
    
                newMsg->len = pMsg->msg.handleValueNoti.len;
                memcpy(newMsg->buffer, pMsg->msg.handleValueNoti.pValue, pMsg->msg.handleValueNoti.len);
    
                List_put(&uartWriteList, (List_Elem *) newMsg);
    
                if (uartWriteActive == 0) {
                    uartWriteActive = 1;
                    uartCurrentMsg = (uartMsg_t *) List_get(&uartWriteList);
    
                    UART_write(uartHandle, uartCurrentMsg->buffer, uartCurrentMsg->len);
                }
            }
        }
        else if (discoveryDone == FALSE)
        {
          SimpleSerialSocketClient_processGATTDiscEvent(pMsg);
        }
      } // else - in case a GATT message came after a connection has dropped, ignore it.
    
      // Needed only for ATT Protocol messages
      GATT_bm_free(&pMsg->msg, pMsg->method);
    }
  • Thanks.

    Now Char #4 notification enabled and receive the notification data.

    Your reply and following thread is helps a lot to solve the issue:

    https://e2e.ti.com/support/wireless-connectivity/bluetooth/f/538/t/676659?LAUNCHXL-CC2650-how-to-enable-notification-in-HID-over-BLE-device-with-simple-central-project-