user53592: With WebSocket various messages arrive.
Task:

Find message "setBrightness: 15"
Extract the value "15" from the message (the value can be any)
Convert this value to uint8_t

My code:
#include <string.h>

String payload_str = "setBrightness: 15"; // WebSocket message
const char* payload = payload_str.c_str(); // Convert string to char

const char* value; // Message value
uint8_t brightness;

void setup() {
  Serial.begin(9600);

  if(strncmp(payload, "setBri", 6) == 0) { // Search message
   value = strtok(payload, " ");
   value = strtok(NULL," "); // Get value (15)
   brightness = (uint8_t)atoi(value); // Convert to uint8_t 
  }
}

void loop() {}

Compilling error:

error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
error:   initializing argument 1 of 'char* strtok(char*, const char*)' [-fpermissive]

Maybe I'm doing it completely wrong and not safe. How can this be fixed?

user37622: strtok modifies the char buffer entered as first parameter. It replaces the delimiters with terminating zeros. To parse a constant string with strtok, you must first copy it into a working char buffer.
For your test you can initialize a char array as in following example.
char payload[] = "setBrightness: 15";

uint8_t brightness;

void setup() {
  Serial.begin(9600);

  if(strncmp(payload, "setBri", 6) == 0) { // Search message
   strtok(payload, " ");
   const char* tok = strtok(NULL," "); // Get value (15)
   brightness = (uint8_t) atoi(tok); // Convert to uint8_t
  }
}

void loop() {}


if you know the 'name' part of the name:value string, you can skip it for atoi this way:
brightness = (uint8_t) atoi(payload + strlen("setBrightness: "));
(strlen("setBrightness: " will be evaluated at compile time to a constant number)
const char payload[] = "setBrightness: 15";

uint8_t brightness;

void setup() {
  Serial.begin(9600);

  if(strncmp(payload, "setBri", 6) == 0) { // Search message
     brightness = (uint8_t) atoi(payload + strlen("setBrightness: ")); // Convert to uint8_t
  }
}

void loop() {}


53592: <p>With WebSocket various messages arrive.</p>
<p>Task:</p>
<ol>
<li>Find message &quot;setBrightness: 15&quot;</li>
<li>Extract the value &quot;15&quot; from the message (the value can be any)</li>
<li>Convert this value to uint8_t</li>
</ol>
<p>My code:</p>
<pre><code>#include &lt;string.h&gt;

String payload_str = &quot;setBrightness: 15&quot;; // WebSocket message
const char* payload = payload_str.c_str(); // Convert string to char

const char* value; // Message value
uint8_t brightness;

void setup() {
  Serial.begin(9600);

  if(strncmp(payload, &quot;setBri&quot;, 6) == 0) { // Search message
   value = strtok(payload, &quot; &quot;);
   value = strtok(NULL,&quot; &quot;); // Get value (15)
   brightness = (uint8_t)atoi(value); // Convert to uint8_t 
  }
}

void loop() {}
</code></pre>
<p>Compilling error:</p>
<blockquote>
<p>error: invalid conversion from 'const char*' to 'char*' [-fpermissive]</p>
<p>error:   initializing argument 1 of 'char* strtok(char*, const char*)' [-fpermissive]</p>
</blockquote>
<p>Maybe I'm doing it completely wrong and not safe. How can this be fixed?</p>
 37622: <p><code>strtok</code> modifies the char buffer entered as first parameter. It replaces the delimiters with terminating zeros. To parse a constant string with <code>strtok</code>, you must first copy it into a working char buffer.</p>

<p>For your test you can initialize a char array as in following example.</p>

<pre><code>char payload[] = "setBrightness: 15";

uint8_t brightness;

void setup() {
  Serial.begin(9600);

  if(strncmp(payload, "setBri", 6) == 0) { // Search message
   strtok(payload, " ");
   const char* tok = strtok(NULL," "); // Get value (15)
   brightness = (uint8_t) atoi(tok); // Convert to uint8_t
  }
}

void loop() {}
</code></pre>

<hr>

<p>if you know the 'name' part of the name:value string, you can skip it for <code>atoi</code> this way:</p>

<p><code>brightness = (uint8_t) atoi(payload + strlen("setBrightness: "));</code></p>

<p>(<code>strlen("setBrightness: "</code> will be evaluated at compile time to a constant number)</p>

<pre><code>const char payload[] = "setBrightness: 15";

uint8_t brightness;

void setup() {
  Serial.begin(9600);

  if(strncmp(payload, "setBri", 6) == 0) { // Search message
     brightness = (uint8_t) atoi(payload + strlen("setBrightness: ")); // Convert to uint8_t
  }
}

void loop() {}
</code></pre>
