Storing text send over BLE as a variable

Hello, programming knowledge fail. I'm trying to store "device ID" as a string. I want to send the name over android to Arduino 101.

I am using nRF master control panel to send text over BLE to Arduino 101.

The following code prints the text to the console as it has been sent via the android device.

 while (central.connected())
    {
       
      // central still connected to peripheral

      
      if (rxCharacteristic.written())
      {
        unsigned char len = rxCharacteristic.valueLength();
        const unsigned char *val = rxCharacteristic.value();
     //   Serial.println(len,DEC);
        

       // Serial.print("didCharacteristicWritten, Length: ");
       // Serial.println(len, DEC);
        char trueVal= -1;
        char Data[40];
        unsigned char i = 0;
        inputString = "";
        while(i<len)
        {
          
         Serial.write(val[i]);
}

However i'm trying to store value instead of printing it and I am not sure what algorithm or code to use.

Here is some attempts

trueVal = Serial.read();
         Serial.println(trueVal);

         Data.toCharArray(trueVal,50);

Alot of the time the stored value ends up as "-1" or "255" for all chars

        //  Serial.print(trueVal);
        //  long inByte1 =   long(Serial.read());

I'm not sure what is going on to be honest. The pointer variable "const unsigned char *val = rxCharacteristic.value();"

Mainly I guess, I'm trying to figure out how to convert that value to string characters instead.

I simply don't understand the pointer variable. I assume I have to read in each value as it comes through and store it in an array. But how do I do that without getting 255 or -1 value? I'm not sure how to convert it? Is it something to do with the byte size??

trueVal = Serial.read();
         Serial.println(trueVal);

         Data.toCharArray(trueVal,50);

This code snippet will read one character from the serial buffer whether or not there is any serial data to read and put it in the trueVal variable. If there is no serial data available the Serial.read() function will return -1.

Have a look at Serial input basics for ideas on how it should be done.

Thanks UKHeliBob, I will go over it and report back if successful or no.
:slight_smile: