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.

String Characteristics

Other Parts Discussed in Thread: CC2540

Hi,

I was wondering how I would go about creating a string characteristic and adding a counter value to the string. Would I need to create a second characteristic to go with the first? Or just do an if-else statement. So say I input the string (can be different words) and every time the string is sent from the master, the output would become "Hello0", "Word1", "String2" etc. Or is this not possible?  Thank you.

Serena

  • Hi, this is a C programming question and nothing related to this forum. Anyway, the following is my answer for your reference. 

    You can use sprintf to compose the string in output buffer.

    char output[128];

    int cnt=0;

    cnt++;

    sprintf(output, "%s %d\n", send_from_master, cut);

  • Sorry, I started learning C when I started using the CC2540. I am currently using the SimpleBLEperipheral code. What do you mean by output buffer? Would I have to create my own section or include it in a method already made in the sample code? Thanks.

    Serena

  • The output buffer is char output[128]. I just give you a rough example to show you how to format string using sprintf. You could revise the code and put it to where you want to use it.