Search code examples
htmlwebserveresp8266

ESP/HTML invalid characters when string is 11 characters or more


So my problem is as the title says, my html page cannot display strings with 11 or more characters and they are being displayed as - L1�?, I don't know what is the problem the strings are not using any special characters and are composed of English letters only, what could cause this problem if the strings are 11 characters long or more? This is the code:

server.on("/", HTTP_GET, [] (AsyncWebServerRequest *request) {

  AsyncResponseStream *response = request->beginResponseStream("text/html");

  response->print("<!DOCTYPE html><html><head>");
  response->print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><style>body{background-color: #92a8d1;}</style></head><body>");
  response->print("<img src=\"0\" width=\"100\" height=\"100\">");
  for (int i = 0; i < n; ++i){
    response->printf("<p>%d: %s (%s)%s<br>", i+1, first[i], second[i], third[i]);
  }
  response->printf(" <embed type=\"text/html\" src=\"textplaceholder\"> "); 
  response->print("</body></html>");
  request->send(response);
});

I tried to use utf-8 charset but it didn't solve the problem. The 9th line is where I am sending the strings to the webserver and first[i] is the string where it can also be more than 11 characters, so some strings are displaying correctly and ones that are too long are being displayed as - L1�?.

Any help is appreciated thanks!


Solution

  • The problem was that the %s printf requires const char * value, adding .c_str()); to the end of string variable solved the problem.