ESP32 Serial Kommunikation mit Arduino Uno (GRBL)

void ReceivedGCodeData(uint8_t *payload, size_t length)
{
  // Tokenize the payload into lines
  char *token;
  char *saveptr;
  token = strtok_r((char *)payload, "\n", &saveptr);

  while (token != NULL)
  {
    // Send each line to the Serial port
    if (strcmp(token, "M7") == 0)
    {
      changePenPos(0);
      Serial2.println(token);
    }
    else if (strcmp(token, "M8") == 0)
    {
      changePenPos(1);
      Serial2.println(token);
    }
    else if (strcmp(token, "M2") == 0)
    {
      // Drawing send fully
      Serial.println("Drawing send fully");
      Serial2.println(token);
    }
    else if (strncmp(token, "G1", 2) == 0)
    {
      // Handle tokens that start with "G1"
      Serial.println(token);
      Serial2.println(token);
    }
    else if (strncmp(token, "G0", 2) == 0)
    {
      // Handle "G0"
      Serial.println(token);
      Serial2.println(token);
    }
    else if (strcmp(token, "G21") == 0)
    {
      // Handle "G21"
      Serial.println(token);
      Serial2.println(token);
    }
    else if (strcmp(token, "G90") == 0)
    {
      // Handle "G90"
      Serial.println(token);
      Serial2.println(token);
    }
    else if (strcmp(token, "F750") == 0)
    {
      // Handle "F750"
      Serial.println(token);
      Serial2.println(token);
    }

    // Get the next line
    token = strtok_r(NULL, "\n", &saveptr);

    // Delay for 100ms
    delay(100);
  }
}