ESP8266 Webserver ESP8266WebServer move Handler-Function in separate .h .c file The plan is to create a bigger project and to split the ESP8266 webserver-code over several modules (.h .c files). The main problem is that the ESP8266WebServer server is not declared in the index.h and index.c files.

What I've been trying to do:

Content main.c

#include &lt;ESP8266WiFi.h&gt;
#include "ESP8266WebServer.h"
#include "index.h"

ESP8266WebServer server(80);
const char* ssid =     "test";     
const char* password = "12345678";  

void setup() 
{
  WiFi.softAP(ssid, password);
  server.on("/", handleRoot(server));           // &lt;-- use of deleted function 'esp8266webserver::ESP8266WebServerTemplate&lt;WiFiServer&gt;::ESP8266WebServerTemplate(const esp8266webserver::ESP8266WebServerTemplate&lt;WiFiServer&gt;&amp;)'
  server.begin();
}

void loop()
{
  server1.handleClient();
}


Content index.h:

void handleRoot(ESP8266WebServer server); 

const char htmlIndex[] PROGMEM = R"=====(
&lt;html&gt;
  &lt;head&gt;
    &lt;meta http-equiv="content-type" content="text/html;charset=UTF-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    &lt;title&gt;Test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;Hello World!&lt;/h1&gt;
  &lt;/body&gt;
&lt;/html&gt;
)=====";


Content index.c:

#include "webpages/index.h"

void handleRoot(ESP8266WebServer server) 
{
  Serial.println("GET /");
  server.send(200, "text/html", htmlIndex);
}


How can I use the ESP8266WebServer server created in the main.c in index.c?
Move the webserver to index.c and include the webserver type:

ESP8266WebServer server(80);


Add an external reference in index.h and include it:

#include "ESP8266WebServer.h"

extern ESP8266WebServer server;


Index.h is included by both main.c and index.c so it will know about server being an ESP8266WebServer type, but does not allocate memory for it; that is done in index.c

This is called a forward reference.