What's wrong with my httpd code?

Posts: 1
Joined: Thu Oct 15, 2020 9:16 am

What's wrong with my httpd code?

Postby eben80 » Thu Oct 15, 2020 12:05 pm

Hi all,
I'm trying to serve html from my SPIFSS but I only get a blank page.
When I print the char buffer to Serial it looks like the complete html.

What is wrong with my code? Can anyone help please?

Code: Select all

char file_buf[24000];

static esp_err_t index_handler(httpd_req_t *req)
    httpd_resp_set_type(req, "text/html");

    unsigned int file_size = 0;

    File file = SPIFFS.open("/index.html");

    if (!file)
        Serial.println("Failed to open file for reading");
        return ESP_FAIL;
        file_size = file.size();
        Serial.print("File Size:  ");

        uint16_t i = 0;
        while (file.available())
            file_buf[i] = file.read();
        file_buf[i] = '\0';
        Serial.print("Size of char buffer:  ");
        Serial.print(file_buf); //use for debug

    httpd_resp_set_type(req, "text/html");
    httpd_resp_send(req, file_buf, -1);
    return ESP_OK;
This is the serial output:

Code: Select all

WiFi connected, your IP address is
SPIFFS Mounted
Starting web server on port: '80'
Starting stream server on stream port: '9601'
Camera Ready! Use '' to connect
stream Ready! Use '
File Size:  23586
Size of char buffer:  24000
<!doctype html>
The browser window stays blank and doesn't finish loading.

Who is online

Users browsing this forum: Google [Bot] and 15 guests