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.

CCS/CC2640R2F: Read Characteristic Value from a Device (Thermometer)

Part Number: CC2640R2F


Tool/software: Code Composer Studio

Hello,

I try to read the Characteristic Value from a Thermometer. I use the CC2640RF as a central, i make a BLE connection with the Thermometer and i wold like to read the "Temperature Measurement Characteristic".

How can I read the value?

// Temperature Measurement Characteristic defines
#define HT_TEMPERATURE_MEASUREMENT_ID 0
#define HT_TEMPERATURE_MEASUREMENT_UUID 0x2A1C
#define HT_TEMPERATURE_MEASUREMENT_LEN 20
#define HT_TEMPERATURE_MEASUREMENT_LEN_MIN

I use this code:

// Do a read
uint8_t status;
attReadReq_t req;

req.handle = (uint16)HT_TEMPERATURE_MEASUREMENT_UUID;
status = GATT_ReadCharValue(connHandle, &req, selfEntity);

if (status == SUCCESS)
{
Display_print0(dispHandle, 9, 0, "SUCCESS");
}

best reagrds,

Fares Rabuts

  • You need to do a general service discovery first. Is your thermometer also TI device?
  • Hello Christin,

    No, it es from Philips (Ear thermometer). I have now a new Problem, my GATT_ReadCharValue() returned SUCCESS, but at :

    else if ((pMsg->method == ATT_READ_RSP) ||
    ((pMsg->method == ATT_ERROR_RSP) &&
    (pMsg->msg.errorRsp.reqOpcode == ATT_READ_REQ)))
    {
    if (pMsg->method == ATT_ERROR_RSP)
    {
    Display_print1(dispHandle, 4, 0, "Read Error %d", pMsg->msg.errorRsp.errCode);
    }
    else
    {
    // After a successful read, display the read value
    Display_print1(dispHandle, 4, 0, "Read rsp: %d", pMsg->msg.readRsp.pValue[0]);
    }

    i got ATT_ERROR_RSP.
    I think that i must to enable the Indication or the Notification, How i can do that?
    I use the this function GATT_Indication(), but the CC2640R2F stands still.

    attHandleValueInd_t *pInd;
    pInd->handle = charHdl;
    pInd->len = (uint16)HT_TEMPERATURE_MEASUREMENT_LEN;
    pInd->pValue = (uint8 *)ATT_MTU_SIZE;
    //GATT_Notification(connHandle, pNoti, authenticated);
    status = GATT_Indication(connHandle, pInd, 0x02, selfEntity);


    Sorry about my Englisch

    best regards,
    Fares Rabuts
  • Have you checked if you get a valid handle for service discovery? Can you provide sniffer log?

    The GATT_ReadCharValue only checks if it's a valid handle value, client is available to operate a att read, but it does not know if this is the correct handle for a read type characteristic.

    What you can try is to program CC2640R2 as host test and using Btool to do a full service discovery. Then you can write down the handle of interest.

    You can then start implementing simple_central and can verify the handle based on the BTool overview.

    You can take a look at the following sessions in SimpleLink Academy:
    dev.ti.com/.../ble_01_basic.html

    dev.ti.com/.../ble_01_custom_profile.html
  • Hello Christin,

    the Characteristic wich i try to read is an indicated  Characteristic, and i think, i should to enable the indication. i read that i should write the the Value {0x01,0x00} to the Characteristic Descriptor. How can i do that ?

    I do this:

    attReadByTypeReq_t req;

    // Discover characteristic

    discState = BLE_DISC_STATE_CHAR;

    req.startHandle = svcStartHdl;

    req.endHandle = svcEndHdl;

    req.type.len = ATT_BT_UUID_SIZE;

    req.type.uuid[0] = LO_UINT16(HT_TEMPERATURE_MEASUREMENT_UUID);

    req.type.uuid[1] = HI_UINT16(HT_TEMPERATURE_MEASUREMENT_UUID);

    bStatus_t status = GATT_DiscCharsByUUID(connHandle,&req,selfEntity);

    if(status == SUCCESS){

                Display_print0(dispHandle, 8, 0, "GATT_DiscCharsByUUID: Success" );

    }

    // Characteristic found, store handle

    if ((pMsg->method == ATT_READ_BY_TYPE_RSP) &&

           (pMsg->msg.readByTypeRsp.numPairs > 0))

    {

           charHdl = BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[0],

                                pMsg->msg.readByTypeRsp.pDataList[1]);

           attWriteReq_t pReq;

           pReq.handle = charHdl;

           pReq.len = 1;

           uint8 onPacket [] = {0x01,0x00};

           pReq.pValue = onPacket;

           pReq.sig = 0;

           pReq.cmd = 0;

           bStatus_t status = GATT_WriteCharDesc(connHandle,&pReq,selfEntity);

           if ( status == SUCCESS )

           {

              Display_print0(dispHandle, 9, 0, "GATT_WriteCharDesc: Success" );

           }else{

               Display_print0(dispHandle, 9, 0, "GATT_WriteCharDesc: NOT SUCCESS" );

           }

    }

    I get :

    GATT_DiscCharsByUUID: Success

    GATT_WriteCharDesc: NOT SUCCESS

    How to insert the Handle ?

    best regards,

    Fares

  • Unfortunately the newer SDKs do not contain example code for using indication.
    However, in our BLE STACK 2.2.2, there does exist example using indication. You can take a look at the glucose_collector example.
    You can download BLE STACK 2.2.2 here:
    www.ti.com/.../BLE-STACK