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.

Enabling Keypress Notification In SimpleBLEPeripheral KeyFob (CC2540 MINI DK) Using SimpleBLECentral Sample Code (CC2540 DK)

Other Parts Discussed in Thread: CC2540

Greg,

I am running SimpleBLEPeripheral code on the CC2540 MINI keyfob hardware and SimpleBLECentral code on the CC2540 DK hardware.  After they are powering up, what I like to do is scan, connect, and turn on key press notification of the SimpleBLEPeripheral from the SimpleBLECentral.  Could you give me some pointers of how to do that?  I read the software developer guide and it said “writing a value of 0x0001 to the characteristic configuration attribute” to turn on either left or right key of the keyfob, but not yet know how to do that inside the SimpleBLECentral code.

Right now, I can do the above using BTool as a replacement of the SimpleBLECentral.

Thanks,

Simon

------------------------------------------------------------------------------------------------------

Usually you would let client enable/disable Client Config, but you can also call it directly and skip the enable check.

 Call –directly à

 VOID GATT_Notification( pItem->connHandle, &noti, authenticated );

-Greg

  • Greg,

    In this case, the client is the Central and the server is the Peripheral. So did you mean enabling the notification in the server (Peripheral) code directly by calling the GATT_Notification() from inside its code? I will try this tomorrow.

    If we will do this from the client side (Central), how do we go about of doing that in the code?

    Thanks,
    Simon

  • I just made it works by calling GATT_Notification() directly as Greg suggested from the SimpleBLEPeripheral code.  Now I am looking into of how to enable/update the notification from the SimpleBLECentral code.  Any helps will be appreciated!!! 

    Simon

  • Hi Simon,

    in simpleBLECentral.c, have a look in the simpleBLECentral_HandleKeys function:

    // Do a write
    attWriteReq_t req;

    req.handle = simpleBLECharHdl;
    req.len = 1;
    req.value[0] = simpleBLECharVal;
    req.sig = 0;
    req.cmd = 0;
    status = GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );

    That's how you would do a write embedded in the code, you can modify this based on the handle and value you would like to send.
    Br
  • It works!  Thanks Nick.

  • Simon

    Would you care to post the way you did it? I tried the above but I can not get it to work, not sure where my problem is. I can appreciate the help.

  • Hi all,

    I'm sorry for waking up this old thread, but I have a question in simpleBLECharHdl.

    I use sample BLECentral and BLEperipheral, when the central discovered the uuid service on peripheral, I see the simpleBLECharHdl is 0x0025, but I can't find where is this number defined. This is not the UUID, and it does not meet the number which is described in software dev guide (in this document, 0x25 is characteristic 2 value).

    I can use this handle number to perform read or write to SIMPLEPROFILE_CHAR1, but how about SIMPLEPROFILE_CHAR3 or something else, what handle I have to use?

  • Hi Tuan,

    The handles are enumerated during the initialization of the application, so those are not available in the code. You would have to do a "Discover characteristic by UUID" to find out which handle it has been "handed".

    Best Regards

  • Hi Nick, Thanks for explanation.

    But I experimented many times and I see for SIMPLEPROFILE_CHAR1, handle is always 0x0025, and for SIMPLEPROFILE_CHAR2, handle is always 0x0028. For others (CHAR3, 4, 5), they cannot be discovered by GATT_ReadUsingCharUUID() due to lacking of read permission.

    Anyway, I'm working on project that the Central and Peripheral will connect and then central read a characteristic and write to another characteristic just once, then disconnect. Connecting -> reading -> writing -> disconnecting should be as fast as possible, also the distance between central and peripheral is large, packets may drop... so I want to skip the service discovery process. Can I use GATT_ReadUsingCharUUID() to read a characteristic? and is there GATT_WriteUsingCharUUID() ?

  • Hi Tuan,

    If your application "knows" the handle, of course you can access the data without the service discovery, but that wont be following the core spec.

    There is not such thing as GATT_WriteUsingCharUUID() as far as I know.

    Using  GATT_ReadUsingCharUUID() will actually call for sub-procedure ATT_ReadByTypeReq() which will generate a response OTA of ATT_ReadByTypeRsp containing the handle and data. So I suppose you can do Connecting -> reading Char 1 -> reading Char 2 (obtaining handle) -> writing Char 2 -> disconnecting ...but I am just thinking out loud.

    If you are designing the Peripheral, you will know the handle anyway so you can just hard code it.

    Best Regards

  • Thank you, Nick,

    I will do so :)

  • Hi, I have a similar setup as the OP. And I can not discovered char4 handler with GATT_ReadUsingCharUUID() neither. Is there any other function to discover connection handle?

    ---------

    Never mind, I have found the GATT_DiscAllChars!!