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.

Compiler/CC2541KEYFOB-RD: Receive/transmit code flow

Part Number: CC2541KEYFOB-RD
Other Parts Discussed in Thread: CC2540, CC2650

Tool/software: TI C/C++ Compiler

Good Day,

I'm new here and can someone kindly explain the flow in the code of how the chars/strings of commands are being received/transmitted then processed in some BLE sample projects like "keyfob".

i am still new to this and need to be enlightened. i am currently working on playing with the sample codes but still can trace where in the codes the receiving/transmitting of chars/string.

i am using the CC2541Keyfob board and BLE scanner app to communicate with it.

Thanks.

  • Hi,

    What exactly in the code are you asking about? Where the writes and notifications, for example, are being received?

    -Nathan
  • Hello Sir Nathan,

    Yes, like that. For example, from a client (android phone using BLE Scanner app) to the Keyfob device. I need to send a string of commands to the device then at least try to "chopped" or i think tokenized those to execute a certain command like sending back data to client or lighting up an LED.

    i already posted this to the BLE wireless forums and they recommended to me some sites to read. But i am more on a person learning by an example, playing with sample codes. :)

    Thanks.
  • Hi,

    The KeyFobDemo application does not receive writes from the central application (scanner app). SimpleBLEPeripheral, however, does, and it has a configuration for the keyfob. I would suggest you use this project instead to see how you would write data to a characteristic. The simpleProfileChangeCB function would be a good place to start to see how this is handled.

    -Nathan
  • Hello Sir Nathan,

    Thanks for pointing me to the right sample application. right now i am checking the simpleProfileChangeCB() within the SimpleBLEperipheral project.

    Using write properties of characteristic 3, i can already command an LED to turn "on" and "off" by writing a single byte (ex. if newValue == 'y' or 0x79, then turn on LED, else if off..).

    But now, i need to send/write not only a single byte but a whole string/s to execute a command/s (LED On/Off) and i can't seem to get it right when trying to adjust the SimpleProfile_GetParameter(....).

    And I also need to store those string/s then process for whatever purpose needed.

    My questions are:

    - do i need to make a new GetParameter function or the default is enough?

    - do i need to check and adjust other functions as well? what are those?

    Sorry for a lot of questions, your time is much appreciated.

    Thanks.

  • Hi,

    You don't need to create a new GetParameter function, but you do need to make changes for the characteristic that you are using. If you are using characteristic 1, for example, you would need to make simpleProfileChar1 an array that is the length of the number of bytes in your characteristic. You would also have to make other changes, such as in simpleProfileChangeCB to account for the use of multiple bytes (this data would have to be copied into an array).

    -Nathan
  • Hello,

    Thanks for confirmation. Actually before i read your reply, while digging deeper into the simpleBLEPeripheral sample code, i happen to find the simpleProfile_WriteAttrCB(..) function under simpleGATTprofile.

    Noticed there some filtering happening with the the write values for characteristic 3, tried editing and can already execute a command with string values entered in the write attributes... ex. write "asas" then checked/compared pValue indices 0-3 (did this "if" method for checking only, planning to tokenize the values).

    Although, I somehow manage to do what i want now, just want to confirm if this is the right approach?

    Thanks.

  • Hi,

    Yes, there are different ways to hand the data that is being read. This approach should be fine.

    -Nathan
  • Hello Again Sir Nathan,

    Thank you for that confirmation.
    I am on-going with my projects and haven't encountered problems so far.
    Will get back to you again if ever a new problem arises, if you don't mind.. :)
    Again, thanks for the time.
  • Hello Again Sir Nathan,

    Since my question is still related to this post, I will ask anyway.

    If the function I use for receiving commands from smartphone to the peripheral device is simpleProfile_WriteAttrCB(..) function, then for transmitting from peripheral device to smartphone is simpleProfile_ReadAttrCB(..) function? Is this correct?

    Just want to confirm.

    Thanks.

  • Hi,

    Yes, this is correct.

    -Nathan
  • Hello Sir Nathan,

    Thanks again for the confirmation.

    Right now, I am trying to figure out why only 1 byte is being read.

  • Hello Again Sir Nathan,

    I am not sure if i have to ask this here but i will do anyway.
    Currently, i am trying to browse the forums regarding reading/writing from eeprom of CC2540.
    I need to store a value in the MCU, particularly a "password", so that even when the MCU is powered off, it will retain the current value to be use when it powered on again. Can you point me again to the right direction? Is there any sample codes related in the BLE stack?
    Thanks.
  • Hello Again Sir Nathan,

    I had an issue regarding the SimpleProfile_WriteAttrCB() function. It's about the pValue. I noticed that it can only store 20 characters. Is that fix or can still be adjusted? I need more than 20 characters to send to peripheral device to be process.

    Thanks.

  • Good Day Sir Nathan,

    I have a follow-up question regarding the ReadAttrCB/WriteAttrCB function I used which can only process 20bytes of data.
    I need to transmit/receive more than 20ytes (maybe 30bytes max). Is the said functions can still be edited to fit my project's needs?
    Or should i use these functions "GATT_ReadLongCharValue/GATT_WriteLongCharValue instead? And how?
    I can't find any sample code using this functions.
    Thanks again.
  • Hi,

    20 bytes is the max length for characteristics. If you want to send more data, you will have to write and read to and from the characteristic multiple times.

    Please see the following SimpleLink Academy modules for more information on using characteristics: software-dl.ti.com/.../overview.html

    It is for the CC2650, but much of the procedure will be the same.

    -Nathan
  • Hello,

    Thanks for replying.
    Is there any sample code given within the v1.4 stack related to this?
    How about this two functions GATT_ReadLongCharValue/GATT_WriteLongCharValue?
    I will start reading the link you provided.
    Thanks.
  • Hi,

    You can use GATT_ReadLongCharValue and GATT_WriteLongCharValue, but this will be slower than using multiple Write Without Response commands or notifications. You can see an example of writing more bytes to a characteristic in the HidAdvRemote project (the HID Report Map characteristic).

    For more information, please see this thread: e2e.ti.com/.../783758

    -Nathan
  • Hello Sir Nathan,

    Thanks for that clarification.

    Regarding your suggestion of read/write data multiple times, i was wondering if the client would send multiple data, should there be an interval in between or no need (ex. 2 sets of 20bytes in one command/button pressed/etc. from app..)? In peripheral side, I will just check received multiple data from the client if matched with a string of command more than 20 bytes. Haven't tried it, just want to confirm if that is the right approach.

    I will read the link you provided.

    Thanks Again.

  • Hello Again Sir,

    I just want to confirm again if the function responsible for sending a data to client when a key is pressed is the sk_ReadAttrCB() from simplekeys.c. I am planning to add in my project an interrupt handler for inputs at port1. If an input state change, it will send a message to the client.
    I am slowly getting there :)
    Thanks.