user83195: I am sending a string from a Raspberry Pi to an ESP32 via BT. I am getting one ASCII value per line. How to convert it into one whole String? I tried as follows, but I get an error while running the method  printReceivedMEssage(buffer):
invalid conversion from 'uint8_t {aka unsigned char}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]
uint8_t buffer; 

void printReceivedMessage(const uint8_t* buf) {
  char string_var[100];
  size_t bufflen = sizeof(buf);

  for (int i = 0; i < bufflen; ++i) {
    Serial.println(static_cast<char>(buf[i]));
  }

  memcpy( string_var, buf, bufflen );
  string_var[bufflen] = '\0'; // 'str' is now a string
  Serial.print("string_var=");
  Serial.println(string_var);
}

void loop() {
  buffer = (char)SerialBT.read();  
  Serial.println(buffer); // THIS SHOWS AN ASCII VALUES ONE PER LINE
  printReceivedMessage(buffer); // ERROR
  delay(1000);
}


user42015: There are multiple problems with your code. They suggest, that you don't know what strings really are.
In C/C++ strings are actually arrays of characters (char). A uint8_t is the same size of a single character, so you can only save a single character in it. For saving a string, you would need an array of them. So buffer should be declared like
uint8_t buffer[20] = "";

Now buffer can hold a string of 19 characters. The 20th character is the terminating null character \0, which marks the end of a string. You must always leave enough space for the null character to terminate your strings correctly.
Serial reading: There are many ways how you can read from Serial. Look at the Serial.readStringUntil() function, which will read from Serial until it reaches a specified character. This way you can easily divide the continuous stream of bytes from Serial into distinct messages. It is common to end all ASCII encoded messages with a newline \n character to mark the end of the message. With Serial.readStringUntil('\n') (note the single quotes for a single character) you will read until it reaches the newline character (or it times out). You can then process the read string as a full message.
Providing a string as parameter to a function: In C/C++ you cannot just provide an array as parameter to a function as other variables. It is a bit more complex. That is because internal the array consists just of a few bytes in a row and the variable just points to the first element of it. It is a pointer (thats a specific C/C++ term). Pointers are marked with *, which you already did with your
void printReceivedMessage(const uint8_t* buf)

function. So the parameter is just a pointer to a uint8_t. That also explains the error message, because you provided an uint8_t, but the function expects a pointer to uint8_t instead. While you still can access the array data through this parameter (given you have implemented what I wrote above about the array), sizeof(buf) will only give you the size of the pointer (2 bytes on most Arduino platforms). So you need to add a parameter and also provide the size of the array. Or you can utilize the correct termination of strings with the null character and get the length of the string with strlen(). That functions iterates the pointer of the array, until it finds the null character and gives you the resulting length.

83195: <p>I am sending a string from a Raspberry Pi to an ESP32 via BT. I am getting one ASCII value per line. How to convert it into one whole String? I tried as follows, but I get an error while running the method  <code>printReceivedMEssage(buffer)</code>:</p>
<p>invalid conversion from 'uint8_t {aka unsigned char}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]</p>
<pre><code>uint8_t buffer; 

void printReceivedMessage(const uint8_t* buf) {
  char string_var[100];
  size_t bufflen = sizeof(buf);

  for (int i = 0; i &lt; bufflen; ++i) {
    Serial.println(static_cast&lt;char&gt;(buf[i]));
  }

  memcpy( string_var, buf, bufflen );
  string_var[bufflen] = '\0'; // 'str' is now a string
  Serial.print(&quot;string_var=&quot;);
  Serial.println(string_var);
}

void loop() {
  buffer = (char)SerialBT.read();  
  Serial.println(buffer); // THIS SHOWS AN ASCII VALUES ONE PER LINE
  printReceivedMessage(buffer); // ERROR
  delay(1000);
}
</code></pre>
 42015: <p>There are multiple problems with your code. They suggest, that you don't know what strings really are.</p>
<p>In C/C++ strings are actually arrays of characters (<code>char</code>). A <code>uint8_t</code> is the same size of a single character, so you can only save a single character in it. For saving a string, you would need an array of them. So <code>buffer</code> should be declared like</p>
<pre><code>uint8_t buffer[20] = &quot;&quot;;
</code></pre>
<p>Now <code>buffer</code> can hold a string of 19 characters. The 20th character is the terminating null character <code>\0</code>, which marks the end of a string. You must always leave enough space for the null character to terminate your strings correctly.</p>
<p><strong>Serial reading:</strong> There are many ways how you can read from Serial. Look at the <code>Serial.readStringUntil()</code> function, which will read from Serial until it reaches a specified character. This way you can easily divide the continuous stream of bytes from Serial into distinct messages. It is common to end all ASCII encoded messages with a newline <code>\n</code> character to mark the end of the message. With <code>Serial.readStringUntil('\n')</code> (note the single quotes for a single character) you will read until it reaches the newline character (or it times out). You can then process the read string as a full message.</p>
<p><strong>Providing a string as parameter to a function:</strong> In C/C++ you cannot just provide an array as parameter to a function as other variables. It is a bit more complex. That is because internal the array consists just of a few bytes in a row and the variable just points to the first element of it. It is a pointer (thats a specific C/C++ term). Pointers are marked with <code>*</code>, which you already did with your</p>
<pre><code>void printReceivedMessage(const uint8_t* buf)
</code></pre>
<p>function. So the parameter is just a pointer to a <code>uint8_t</code>. That also explains the error message, because you provided an <code>uint8_t</code>, but the function expects a pointer to <code>uint8_t</code> instead. While you still can access the array data through this parameter (given you have implemented what I wrote above about the array), <code>sizeof(buf)</code> will only give you the size of the pointer (2 bytes on most Arduino platforms). So you need to add a parameter and also provide the size of the array. Or you can utilize the correct termination of strings with the null character and get the length of the string with <code>strlen()</code>. That functions iterates the pointer of the array, until it finds the null character and gives you the resulting length.</p>
