Remove Webserver library dependency on FS library

gailu96
Posts: 9
Joined: Sat Aug 10, 2024 6:06 pm

Remove Webserver library dependency on FS library

Postby gailu96 » Sun Aug 25, 2024 10:26 am

Hi Experts,

I am using ESP32 with Arduino. My requirement is only to accept TCP connection on a port and responding to TCP client when a TCP client connects to server (without any file system).

When I searched for the server I found examples for Webserver library only and decided to use it. However biggest problem with Webserver library is that it seems to have permanent dependency on File System (FS) library even for a basic HelloServer example that does not need file system.

Below is the example code taken from Examples for HelloServer and when build it, it also builds FS library that increases my image size. How do I remove FS library from build as I do not need any file system. ? Is there any other better library just to handle TCP server that you can suggest?

Code: Select all

#include <WiFi.h>
#include <NetworkClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>

const char *ssid = "........";
const char *password = "........";

WebServer server(80);

const int led = 13;

void handleRoot() {
  digitalWrite(led, 1);
  server.send(200, "text/plain", "hello from esp32!");
  digitalWrite(led, 0);
}

void handleNotFound() {
  digitalWrite(led, 1);
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(led, 0);
}

void setup(void) {
  pinMode(led, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp32")) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);

  server.on("/inline", []() {
    server.send(200, "text/plain", "this works as well");
  });

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
}

void loop(void) {
  server.handleClient();
  delay(2);  //allow the cpu to switch to other tasks
}

chegewara
Posts: 2362
Joined: Wed Jun 14, 2017 9:00 pm

Re: Remove Webserver library dependency on FS library

Postby chegewara » Sun Aug 25, 2024 11:15 am

Does it have to be arduino library? I mean, i have some very rough C++ wrapper around esp-idf API which should works just fine with arduino projects.

gailu96
Posts: 9
Joined: Sat Aug 10, 2024 6:06 pm

Re: Remove Webserver library dependency on FS library

Postby gailu96 » Sun Aug 25, 2024 11:47 am

@chegewara

Thanks for your reply. I am OK to call IDF functions also. I am migrating code from ESP8266 NON OS SDK to ESP32. I could use IDF only (i.e. without Arduino) but I chose to go with Arduino because of rich eco system of readymade libraries (one such library is IRremoteESP8266 for my IR blaster product). So my current approach is to use Arduino library as much as possible and use IDF routines wherever requirement is not met with Arduino library. The image size that I had on my esp8266 with NONOS SDK was around 380KB and now moving same code to Arduino ESP32 my image size is 1MB (probably because of some components/library that I do not need actually, like FS as I pointed out in this post). I am trying to see if FS is removed what will be my image size.

On esp8266 NONOS SDK I used to have following code, I think I need to find something similar in ESP32 IDF if I can not remove FS dependency for Webserver library. If you know something equivalent please let me know.

Code: Select all

    httpconn.type = ESPCONN_TCP;
    httpconn.state = ESPCONN_NONE;;
    httpconn.proto.tcp = &httptcp;
    httpconn.proto.tcp->local_port = 80;

    if(0 != espconn_regist_connectcb(&httpconn, httpserver_listen))
    {
        LOG(("ERROR: %s:%d\r\n",__FILE__,__LINE__));
        return ERROR;
    }

    if(0 != espconn_accept(&httpconn))
    {
        LOG(("ERROR: %s:%d

MicroController
Posts: 1688
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Remove Webserver library dependency on FS library

Postby MicroController » Sun Aug 25, 2024 5:23 pm

gailu96 wrote:
Sun Aug 25, 2024 10:26 am
My requirement is only to accept TCP connection on a port and responding to TCP client when a TCP client connects to server (without any file system).
You can look into the TCP server example of the IDF for 'inspiration'.

Who is online

Users browsing this forum: No registered users and 86 guests