invalid conversion from 'const char*' to 'char*' [-fpermissive] With WebSocket various messages arrive.
Task:

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

My 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() {}

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?
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() {}