Zusammenfügen zweier Codes ESP32 Smart Home Control

Hallo ich habe hier zwei Codes die ich gerne zusammenfügen möchte. Leider kommt immer der Fehler wenn ich diese zusammen füge: conflicting declaration 'WebServer server'.

Hier sind die beiden Codes:

#include <WiFi.h>
#include <Adafruit_NeoPixel.h>

const char* ssid = "";           //Netzwerk Name
const char* password = "";            //Netzwerk Passwort

WiFiServer server(80);

#define Steckdose_PIN 22
#define LED_PIN    23
#define LED_COUNT 300

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
uint32_t red = strip.Color(255, 0, 0);
uint32_t green = strip.Color(0, 255, 0);
uint32_t blue = strip.Color(0, 0, 255);
uint32_t white = strip.Color(255, 255, 255);
uint32_t yellow = strip.Color(227, 235, 7);
uint32_t orange = strip.Color(235, 151, 7);
uint32_t lila = strip.Color(235, 7, 201);
uint32_t cyan = strip.Color(5, 240, 208);

String header;
String outputredState = "Aus";
String outputgreenState = "Aus";
String outputblueState = "Aus";
String outputwhiteState = "Aus";
String outputyellowState = "Aus";
String outputorangeState = "Aus";
String outputlilaState = "Aus";
String outputcyanState = "Aus";
String outputrainbowState = "Aus";
String outputsteckdoseState = "Aus";

unsigned long currentTime = millis();
unsigned long previousTime = 0;

const long timeoutTime = 2000;


void setup() {
  strip.begin();
  strip.show();
  
  Serial.begin(115200);

  Serial.print("Verbinden mit ");           //Verbinden mit WiFi
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() !=WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");           //Zeigt die IP Adresse
  Serial.println("WiFi verbunden");
  Serial.println("IP Adresse: ");
  Serial.println(WiFi.localIP());
  server.begin();
  pinMode(Steckdose_PIN, OUTPUT);
}

void loop() {
  WiFiClient client = server.available();

  if (client) {
    currentTime = millis();
    previousTime = currentTime;
    Serial.println("Neue Aktion.");
    String currentLine = "";
    while (client.connected() && currentTime - previousTime <= timeoutTime) {
      currentTime = millis();
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        header +=c;
        if (c == '\n') {
          if (currentLine.length() ==0) {
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();

            if (header.indexOf("GET /red/on") >=0) {
              Serial.println("GPIO Rot an");
              outputredState = "an";
              strip.fill(red, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /red/off") >= 0) {
              Serial.println("GPIO Rot aus");
              outputredState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /green/on") >=0) {
              Serial.println("GPIO Grün an");
              outputgreenState = "an";
              strip.fill(green, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /green/off") >= 0) {
              Serial.println("GPIO Grün aus");
              outputgreenState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /blue/on") >=0) {
              Serial.println("GPIO Blau an");
              outputblueState = "an";
              strip.fill(blue, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /blue/off") >= 0) {
              Serial.println("GPIO Blau aus");
              outputblueState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /white/on") >=0) {
              Serial.println("GPIO Weiß an");
              outputwhiteState = "an";
              strip.fill(white, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /white/off") >= 0) {
              Serial.println("GPIO Weiß aus");
              outputwhiteState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /yellow/on") >=0) {
              Serial.println("GPIO Gelb an");
              outputyellowState = "an";
              strip.fill(yellow, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /yellow/off") >= 0) {
              Serial.println("GPIO Gelb aus");
              outputyellowState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /orange/on") >=0) {
              Serial.println("GPIO Orange an");
              outputorangeState = "an";
              strip.fill(orange, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /orange/off") >= 0) {
              Serial.println("GPIO Orange aus");
              outputorangeState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /lila/on") >=0) {
              Serial.println("GPIO Lila an");
              outputlilaState = "an";
              strip.fill(lila, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /lila/off") >= 0) {
              Serial.println("GPIO Lila aus");
              outputlilaState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /cyan/on") >=0) {
              Serial.println("GPIO Türkis an");
              outputcyanState = "an";
              strip.fill(cyan, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /cyan/off") >= 0) {
              Serial.println("GPIO Türkis aus");
              outputcyanState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /steckdose/on") >=0) {
              Serial.println("GPIO Steckdose an");
              outputsteckdoseState = "an";
              delay(500);
              digitalWrite(Steckdose_PIN, HIGH);
            } else if (header.indexOf("GET /steckdose/off") >= 0) {
              Serial.println("GPIO Steckdose aus");
              outputsteckdoseState = "aus";
              delay(500);
              digitalWrite(Steckdose_PIN, LOW);
            }
            if (header.indexOf("GET /rainbow/on") >=0) {
              Serial.println("GPIO Regenbogen an");
              outputrainbowState = "an";
              while (true) {
                rainbow(30);
                delay(10);
              }
            } else if (header.indexOf("GET /rainbow/off") >= 0) {
              Serial.println("GPIO Regenbogen aus");
              outputrainbowState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<title>Smart Home Control</title>");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
            client.println(".button { background-color: #4CAF50; border: solid; color: black; padding: 16px 40px;");
            client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer");
            client.println(".button2 {background-color: #555555;}</style></head>");
            client.println("<body><h1>LED Strip Steuerung</h1>");
            client.println("<p>Rot " + outputredState + "</p>");
            client.println("<p><a href=\"/red/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/red/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Gr&uuml;n " + outputgreenState + "</p>");
            client.println("<p><a href=\"/green/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/green/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Blau " + outputblueState + "</p>");
            client.println("<p><a href=\"/blue/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/blue/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Wei&szlig; " + outputwhiteState + "</p>");
            client.println("<p><a href=\"/white/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/white/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Gelb " + outputyellowState + "</p>");
            client.println("<p><a href=\"/yellow/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/yellow/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Orange " + outputorangeState + "</p>");
            client.println("<p><a href=\"/orange/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/orange/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Lila " + outputlilaState + "</p>");
            client.println("<p><a href=\"/lila/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/lila/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>T&uuml;rkis " + outputcyanState + "</p>");
            client.println("<p><a href=\"/cyan/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/cyan/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Steckdose " + outputsteckdoseState + "</p>");
            client.println("<p><a href=\"/steckdose/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/steckdose/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Regenbogen " + outputrainbowState + "</p>");
            client.println("<p><a href=\"/rainbow/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/rainbow/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("</body></html>");
            client.println();
            break;  
          } else {
            currentLine = "";
          }
        } else if (c != '\r') {
          currentLine += c;
        }
      }
    }
    header = "";
    client.stop();
    Serial.println("Aktion beendet.");
    Serial.println("");
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i*1+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } 
  else if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } 
  else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}
zweiter code

#include <WiFi.h>
#include <WebServer.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>

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

WebServer server(80);

Adafruit_BMP085 bmp;

float temperatur = 0.0;
float druck = 0.0;

void updateSensorValues() {
  double t = bmp.readTemperature();
  double p = bmp.readPressure() / 100.0;

  temperatur = t;
  druck = p;
}

void handleRoot() {
  String html = "<html><body>";
  html += "<h1>W&auml;hlen Sie, welche Werte angezeigt werden sollen</h1>";
  html += "<form action='/temperature'><button type='submit'>Temperatur anzeigen</button></form>";
  html += "<form action='/pressure'><button type='submit'>Luftdruck anzeigen</button></form>";
  html += "</body></html>";

  server.send(200, "text/html", html);
}

void handleTemperature() {
  updateSensorValues();

  String html = "<html><body>";
  html += "<div style='font-size: 4,5em; text-align: center;'>";
  if (temperatur <= -10) {
    html += "<span style='color: #0099cc;'>" + String(temperatur) + " &#8451;</span>";
  } else if (temperatur > -10 && temperatur <= 0) {
    html += "<span style='color: #00cc66;'>" + String(temperatur) + " &#8451;</span>";
  } else if (temperatur > 0 && temperatur <= 10) {
    html += "<span style='color: #ffcc00;'>" + String(temperatur) + " &#8451;</span>";
  } else if (temperatur > 10 && temperatur <= 20) {
    html += "<span style='color: #ff9900;'>" + String(temperatur) + " &#8451;</span>";
  } else if (temperatur > 20 && temperatur <= 30) {
    html += "<span style='color: #ff6600;'>" + String(temperatur) + " &#8451;</span>";
  } else {
    html += "<span style='color: #cc0000;'>" + String(temperatur) + " &#8451;</span>";
  }
  html += "</div>";
  html += "</body></html>";

  server.send(200, "text/html", html);
}

void handlePressure() {
  updateSensorValues();

  String html = "<html><body>";
  html += "<div style='font-size: 4,5em; text-align: center;'>";
  html += "<span style='color: #000000;'>" + String(druck) + " hPa</p>";
  html += "</body></html>";

  server.send(200, "text/html", html);
}

void setup() {
  Serial.begin(115200);
  
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("");
  Serial.println("WiFi verbunden");
  Serial.println("IP Adresse: ");
  Serial.println(WiFi.localIP());

  if (!bmp.begin()) {
    Serial.println("Could not find a valid BMP180 sensor, check wiring!");
    while (1);
  }

  server.on("/", handleRoot);
  server.on("/temperature", handleTemperature);
  server.on("/pressure", handlePressure);
  server.begin();
  Serial.println("Webserver started!");
}

void loop() {
  server.handleClient();

  delay(100);
  updateSensorValues();
}

ich hoffe jemand kann mir helfen

Alles was mit WLAN zu tun hat nur einmal machen.

Hallo,
na ja so einfach ist das nicht, Du kannst nicht nur einfach was zusammen kopieren. Es kann nur ein Setup und nur ein loop geben.

Du kannst aber das bei dem zweiten Code umbenennen und im ersten aufrufen.
alle include in den ersten packen
Achtung globale Variable checken damit sie nicht doppelt vorkommen , eventuell umbenennen

eventuell auch einen zweiten Tab nutzen

Du kannst auch hier im Forum mal suchen , die Frage taucht alle paar Wochen mal auf , und es gibt sicher Beispiele hier und Hilfen

das ist schon klar. ich habe alles in die jeweiligen voids kopiert und der Fehler kommt bei der Zeile wo ich den WebServer server (80); und WiFiServer server (80); zusammen mache. liegt wahrscheinlich an der WiFi.h und WebServer.h Bibliothek

Und warum sehe ich dann z.B zweimal setup und 2 mal loop in Deinem code.

wie sollen wir das denn teste , so gehts nicht das muss sich keiner irgendwo reinkopieren .

Heinz

Ganz sicher nicht, sondern es liegt an deinem Sketch den du uns hier zeigst.

Dan schau hier
Nicht vergessen Augen aufmachen und oder Brille putzen :wink:
Schreibe uns was dort für Bibliotheken benutz werden, und vergleiche deine Duplikate

ich konnte nicht beide codes getrennt schreiben

#include <WiFi.h>
#include <WebServer.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>

const char* ssid = "WLANWAHN16";
const char* password = "Niclas:11-2004DD-KraFrie";

WebServer server(80);

Adafruit_BMP085 bmp;

float temperatur = 0.0;
float druck = 0.0;

void updateSensorValues() {
  double t = bmp.readTemperature();
  double p = bmp.readPressure() / 100.0;

  temperatur = t;
  druck = p;
}

void handleRoot() {
  String html = "<html><body>";
  html += "<h1>W&auml;hlen Sie, welche Werte angezeigt werden sollen</h1>";
  html += "<form action='/temperature'><button type='submit'>Temperatur anzeigen</button></form>";
  html += "<form action='/pressure'><button type='submit'>Luftdruck anzeigen</button></form>";
  html += "</body></html>";

  server.send(200, "text/html", html);
}

void handleTemperature() {
  updateSensorValues();

  String html = "<html><body>";
  html += "<div style='font-size: 4,5em; text-align: center;'>";
  if (temperatur <= -10) {
    html += "<span style='color: #0099cc;'>" + String(temperatur) + " &#8451;</span>";
  } else if (temperatur > -10 && temperatur <= 0) {
    html += "<span style='color: #00cc66;'>" + String(temperatur) + " &#8451;</span>";
  } else if (temperatur > 0 && temperatur <= 10) {
    html += "<span style='color: #ffcc00;'>" + String(temperatur) + " &#8451;</span>";
  } else if (temperatur > 10 && temperatur <= 20) {
    html += "<span style='color: #ff9900;'>" + String(temperatur) + " &#8451;</span>";
  } else if (temperatur > 20 && temperatur <= 30) {
    html += "<span style='color: #ff6600;'>" + String(temperatur) + " &#8451;</span>";
  } else {
    html += "<span style='color: #cc0000;'>" + String(temperatur) + " &#8451;</span>";
  }
  html += "</div>";
  html += "</body></html>";

  server.send(200, "text/html", html);
}

void handlePressure() {
  updateSensorValues();

  String html = "<html><body>";
  html += "<div style='font-size: 4,5em; text-align: center;'>";
  html += "<span style='color: #000000;'>" + String(druck) + " hPa</p>";
  html += "</body></html>";

  server.send(200, "text/html", html);
}

void setup() {
  Serial.begin(115200);
  
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("");
  Serial.println("WiFi verbunden");
  Serial.println("IP Adresse: ");
  Serial.println(WiFi.localIP());

  if (!bmp.begin()) {
    Serial.println("Could not find a valid BMP180 sensor, check wiring!");
    while (1);
  }

  server.on("/", handleRoot);
  server.on("/temperature", handleTemperature);
  server.on("/pressure", handlePressure);
  server.begin();
  Serial.println("Webserver started!");
}

void loop() {
  server.handleClient();

  delay(100);
  updateSensorValues();
}
#include <WiFi.h>
#include <Adafruit_NeoPixel.h>

const char* ssid = "WLANWAHN16_PL";           //Netzwerk Name
const char* password = "Niclas:11-2004DD-KraFrie";            //Netzwerk Passwort

WiFiServer server(80);

#define Steckdose_PIN 22
#define LED_PIN    23
#define LED_COUNT 300

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
uint32_t red = strip.Color(255, 0, 0);
uint32_t green = strip.Color(0, 255, 0);
uint32_t blue = strip.Color(0, 0, 255);
uint32_t white = strip.Color(255, 255, 255);
uint32_t yellow = strip.Color(227, 235, 7);
uint32_t orange = strip.Color(235, 151, 7);
uint32_t lila = strip.Color(235, 7, 201);
uint32_t cyan = strip.Color(5, 240, 208);

String header;
String outputredState = "Aus";
String outputgreenState = "Aus";
String outputblueState = "Aus";
String outputwhiteState = "Aus";
String outputyellowState = "Aus";
String outputorangeState = "Aus";
String outputlilaState = "Aus";
String outputcyanState = "Aus";
String outputrainbowState = "Aus";
String outputsteckdoseState = "Aus";

unsigned long currentTime = millis();
unsigned long previousTime = 0;

const long timeoutTime = 2000;


void setup() {
  strip.begin();
  strip.show();
  
  Serial.begin(115200);

  Serial.print("Verbinden mit ");           //Verbinden mit WiFi
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() !=WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");           //Zeigt die IP Adresse
  Serial.println("WiFi verbunden");
  Serial.println("IP Adresse: ");
  Serial.println(WiFi.localIP());
  server.begin();
  pinMode(Steckdose_PIN, OUTPUT);
}

void loop() {
  WiFiClient client = server.available();

  if (client) {
    currentTime = millis();
    previousTime = currentTime;
    Serial.println("Neue Aktion.");
    String currentLine = "";
    while (client.connected() && currentTime - previousTime <= timeoutTime) {
      currentTime = millis();
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        header +=c;
        if (c == '\n') {
          if (currentLine.length() ==0) {
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();

            if (header.indexOf("GET /red/on") >=0) {
              Serial.println("GPIO Rot an");
              outputredState = "an";
              strip.fill(red, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /red/off") >= 0) {
              Serial.println("GPIO Rot aus");
              outputredState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /green/on") >=0) {
              Serial.println("GPIO Grün an");
              outputgreenState = "an";
              strip.fill(green, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /green/off") >= 0) {
              Serial.println("GPIO Grün aus");
              outputgreenState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /blue/on") >=0) {
              Serial.println("GPIO Blau an");
              outputblueState = "an";
              strip.fill(blue, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /blue/off") >= 0) {
              Serial.println("GPIO Blau aus");
              outputblueState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /white/on") >=0) {
              Serial.println("GPIO Weiß an");
              outputwhiteState = "an";
              strip.fill(white, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /white/off") >= 0) {
              Serial.println("GPIO Weiß aus");
              outputwhiteState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /yellow/on") >=0) {
              Serial.println("GPIO Gelb an");
              outputyellowState = "an";
              strip.fill(yellow, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /yellow/off") >= 0) {
              Serial.println("GPIO Gelb aus");
              outputyellowState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /orange/on") >=0) {
              Serial.println("GPIO Orange an");
              outputorangeState = "an";
              strip.fill(orange, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /orange/off") >= 0) {
              Serial.println("GPIO Orange aus");
              outputorangeState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /lila/on") >=0) {
              Serial.println("GPIO Lila an");
              outputlilaState = "an";
              strip.fill(lila, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /lila/off") >= 0) {
              Serial.println("GPIO Lila aus");
              outputlilaState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /cyan/on") >=0) {
              Serial.println("GPIO Türkis an");
              outputcyanState = "an";
              strip.fill(cyan, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /cyan/off") >= 0) {
              Serial.println("GPIO Türkis aus");
              outputcyanState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /steckdose/on") >=0) {
              Serial.println("GPIO Steckdose an");
              outputsteckdoseState = "an";
              delay(500);
              digitalWrite(Steckdose_PIN, HIGH);
            } else if (header.indexOf("GET /steckdose/off") >= 0) {
              Serial.println("GPIO Steckdose aus");
              outputsteckdoseState = "aus";
              delay(500);
              digitalWrite(Steckdose_PIN, LOW);
            }
            if (header.indexOf("GET /rainbow/on") >=0) {
              Serial.println("GPIO Regenbogen an");
              outputrainbowState = "an";
              while (true) {
                rainbow(30);
                delay(10);
              }
            } else if (header.indexOf("GET /rainbow/off") >= 0) {
              Serial.println("GPIO Regenbogen aus");
              outputrainbowState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<title>Smart Home Control</title>");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
            client.println(".button { background-color: #4CAF50; border: solid; color: black; padding: 16px 40px;");
            client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer");
            client.println(".button2 {background-color: #555555;}</style></head>");
            client.println("<body><h1>LED Strip Steuerung</h1>");
            client.println("<p>Rot " + outputredState + "</p>");
            client.println("<p><a href=\"/red/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/red/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Gr&uuml;n " + outputgreenState + "</p>");
            client.println("<p><a href=\"/green/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/green/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Blau " + outputblueState + "</p>");
            client.println("<p><a href=\"/blue/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/blue/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Wei&szlig; " + outputwhiteState + "</p>");
            client.println("<p><a href=\"/white/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/white/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Gelb " + outputyellowState + "</p>");
            client.println("<p><a href=\"/yellow/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/yellow/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Orange " + outputorangeState + "</p>");
            client.println("<p><a href=\"/orange/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/orange/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Lila " + outputlilaState + "</p>");
            client.println("<p><a href=\"/lila/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/lila/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>T&uuml;rkis " + outputcyanState + "</p>");
            client.println("<p><a href=\"/cyan/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/cyan/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Steckdose " + outputsteckdoseState + "</p>");
            client.println("<p><a href=\"/steckdose/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/steckdose/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Regenbogen " + outputrainbowState + "</p>");
            client.println("<p><a href=\"/rainbow/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/rainbow/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("</body></html>");
            client.println();
            break;  
          } else {
            currentLine = "";
          }
        } else if (c != '\r') {
          currentLine += c;
        }
      }
    }
    header = "";
    client.stop();
    Serial.println("Aktion beendet.");
    Serial.println("");
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i*1+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } 
  else if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } 
  else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

das sind die beiden Codes die ich gerne zusammenfügen möchte

das ist der zusammengefügte code mit der fehler meldung: conflicting declaration 'WebServer server'

#include <WiFi.h>
#include <Adafruit_NeoPixel.h>
#include <WebServer.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>

const char* ssid = "WLANWAHN16_PL";           //Netzwerk Name
const char* password = "Niclas:11-2004DD-KraFrie";            //Netzwerk Passwort

WiFiServer server(80);
WebServer server(80);

Adafruit_BMP085 bmp;

float temperatur = 0.0;
float druck = 0.0;

#define Steckdose_PIN 22
#define LED_PIN    23
#define LED_COUNT 300

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
uint32_t red = strip.Color(255, 0, 0);
uint32_t green = strip.Color(0, 255, 0);
uint32_t blue = strip.Color(0, 0, 255);
uint32_t white = strip.Color(255, 255, 255);
uint32_t yellow = strip.Color(227, 235, 7);
uint32_t orange = strip.Color(235, 151, 7);
uint32_t lila = strip.Color(235, 7, 201);
uint32_t cyan = strip.Color(5, 240, 208);

String header;
String outputredState = "Aus";
String outputgreenState = "Aus";
String outputblueState = "Aus";
String outputwhiteState = "Aus";
String outputyellowState = "Aus";
String outputorangeState = "Aus";
String outputlilaState = "Aus";
String outputcyanState = "Aus";
String outputrainbowState = "Aus";
String outputsteckdoseState = "Aus";

unsigned long currentTime = millis();
unsigned long previousTime = 0;

const long timeoutTime = 2000;

void updateSensorValues() {
  double t = bmp.readTemperature();
  double p = bmp.readPressure() / 100.0;

  temperatur = t;
  druck = p;
}

void handleRoot() {
  String html = "<html><body>";
  html += "<h1>W&auml;hlen Sie, welche Werte angezeigt werden sollen</h1>";
  html += "<form action='/temperature'><button type='submit'>Temperatur anzeigen</button></form>";
  html += "<form action='/pressure'><button type='submit'>Luftdruck anzeigen</button></form>";
  html += "</body></html>";

  server.send(200, "text/html", html);
}

void handleTemperature() {
  updateSensorValues();

  String html = "<html><body>";
  html += "<div style='font-size: 4,5em; text-align: center;'>";
  if (temperatur <= -10) {
    html += "<span style='color: #0099cc;'>" + String(temperatur) + " &#8451;</span>";
  } else if (temperatur > -10 && temperatur <= 0) {
    html += "<span style='color: #00cc66;'>" + String(temperatur) + " &#8451;</span>";
  } else if (temperatur > 0 && temperatur <= 10) {
    html += "<span style='color: #ffcc00;'>" + String(temperatur) + " &#8451;</span>";
  } else if (temperatur > 10 && temperatur <= 20) {
    html += "<span style='color: #ff9900;'>" + String(temperatur) + " &#8451;</span>";
  } else if (temperatur > 20 && temperatur <= 30) {
    html += "<span style='color: #ff6600;'>" + String(temperatur) + " &#8451;</span>";
  } else {
    html += "<span style='color: #cc0000;'>" + String(temperatur) + " &#8451;</span>";
  }
  html += "</div>";
  html += "</body></html>";

  server.send(200, "text/html", html);
}

void handlePressure() {
  updateSensorValues();

  String html = "<html><body>";
  html += "<div style='font-size: 4,5em; text-align: center;'>";
  html += "<span style='color: #000000;'>" + String(druck) + " hPa</p>";
  html += "</body></html>";

  server.send(200, "text/html", html);
}

void setup() {
  strip.begin();
  strip.show();
  
  Serial.begin(115200);

  Serial.print("Verbinden mit ");           //Verbinden mit WiFi
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() !=WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");           //Zeigt die IP Adresse
  Serial.println("WiFi verbunden");
  Serial.println("IP Adresse: ");
  Serial.println(WiFi.localIP());
  if (!bmp.begin()) {
    Serial.println("Could not find a valid BMP180 sensor, check wiring!");
    while (1);
  }
  server.on("/", handleRoot);
  server.on("/temperature", handleTemperature);
  server.on("/pressure", handlePressure);
  server.begin();
  pinMode(Steckdose_PIN, OUTPUT);
}

void loop() {
  server.handleClient();
  delay(100);
  updateSensorValues();
  
  WiFiClient client = server.available();

  if (client) {
    currentTime = millis();
    previousTime = currentTime;
    Serial.println("Neue Aktion.");
    String currentLine = "";
    while (client.connected() && currentTime - previousTime <= timeoutTime) {
      currentTime = millis();
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        header +=c;
        if (c == '\n') {
          if (currentLine.length() ==0) {
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();

            if (header.indexOf("GET /red/on") >=0) {
              Serial.println("GPIO Rot an");
              outputredState = "an";
              strip.fill(red, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /red/off") >= 0) {
              Serial.println("GPIO Rot aus");
              outputredState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /green/on") >=0) {
              Serial.println("GPIO Grün an");
              outputgreenState = "an";
              strip.fill(green, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /green/off") >= 0) {
              Serial.println("GPIO Grün aus");
              outputgreenState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /blue/on") >=0) {
              Serial.println("GPIO Blau an");
              outputblueState = "an";
              strip.fill(blue, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /blue/off") >= 0) {
              Serial.println("GPIO Blau aus");
              outputblueState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /white/on") >=0) {
              Serial.println("GPIO Weiß an");
              outputwhiteState = "an";
              strip.fill(white, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /white/off") >= 0) {
              Serial.println("GPIO Weiß aus");
              outputwhiteState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /yellow/on") >=0) {
              Serial.println("GPIO Gelb an");
              outputyellowState = "an";
              strip.fill(yellow, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /yellow/off") >= 0) {
              Serial.println("GPIO Gelb aus");
              outputyellowState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /orange/on") >=0) {
              Serial.println("GPIO Orange an");
              outputorangeState = "an";
              strip.fill(orange, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /orange/off") >= 0) {
              Serial.println("GPIO Orange aus");
              outputorangeState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /lila/on") >=0) {
              Serial.println("GPIO Lila an");
              outputlilaState = "an";
              strip.fill(lila, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /lila/off") >= 0) {
              Serial.println("GPIO Lila aus");
              outputlilaState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /cyan/on") >=0) {
              Serial.println("GPIO Türkis an");
              outputcyanState = "an";
              strip.fill(cyan, 0, 300);
              strip.show();
            } else if (header.indexOf("GET /cyan/off") >= 0) {
              Serial.println("GPIO Türkis aus");
              outputcyanState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            if (header.indexOf("GET /steckdose/on") >=0) {
              Serial.println("GPIO Steckdose an");
              outputsteckdoseState = "an";
              delay(500);
              digitalWrite(Steckdose_PIN, HIGH);
            } else if (header.indexOf("GET /steckdose/off") >= 0) {
              Serial.println("GPIO Steckdose aus");
              outputsteckdoseState = "aus";
              delay(500);
              digitalWrite(Steckdose_PIN, LOW);
            }
            if (header.indexOf("GET /rainbow/on") >=0) {
              Serial.println("GPIO Regenbogen an");
              outputrainbowState = "an";
              while (true) {
                rainbow(30);
                delay(10);
              }
            } else if (header.indexOf("GET /rainbow/off") >= 0) {
              Serial.println("GPIO Regenbogen aus");
              outputrainbowState = "aus";
              strip.fill((0, 0, 0), 0, 300);
              strip.show();
            }
            
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<title>Smart Home Control</title>");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
            client.println(".button { background-color: #4CAF50; border: solid; color: black; padding: 16px 40px;");
            client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer");
            client.println(".button2 {background-color: #555555;}</style></head>");
            client.println("<body><h1>LED Strip Steuerung</h1>");
            client.println("<p>Rot " + outputredState + "</p>");
            client.println("<p><a href=\"/red/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/red/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Gr&uuml;n " + outputgreenState + "</p>");
            client.println("<p><a href=\"/green/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/green/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Blau " + outputblueState + "</p>");
            client.println("<p><a href=\"/blue/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/blue/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Wei&szlig; " + outputwhiteState + "</p>");
            client.println("<p><a href=\"/white/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/white/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Gelb " + outputyellowState + "</p>");
            client.println("<p><a href=\"/yellow/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/yellow/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Orange " + outputorangeState + "</p>");
            client.println("<p><a href=\"/orange/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/orange/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Lila " + outputlilaState + "</p>");
            client.println("<p><a href=\"/lila/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/lila/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>T&uuml;rkis " + outputcyanState + "</p>");
            client.println("<p><a href=\"/cyan/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/cyan/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Steckdose " + outputsteckdoseState + "</p>");
            client.println("<p><a href=\"/steckdose/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/steckdose/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("<p>Regenbogen " + outputrainbowState + "</p>");
            client.println("<p><a href=\"/rainbow/on\"><button class=\"button\">Einschalten</button></a></p>");
            client.println("<p><a href=\"/rainbow/off\"><button class=\"button button2\">Ausschalten</button></a></p>");
            client.println("</body></html>");
            client.println();
            break;  
          } else {
            currentLine = "";
          }
        } else if (c != '\r') {
          currentLine += c;
        }
      }
    }
    header = "";
    client.stop();
    Serial.println("Aktion beendet.");
    Serial.println("");
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i*1+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } 
  else if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } 
  else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Hallo,

die beiden Sketche beruhen auf 2 unterschiedlichen Methoden einen Webserver zu bauen.

Ich denke das wird so nichts werden. Man müsste den zweiten so umbauen das er auch auf den gleichen Methode, unter Nutzung der webserver.h beruht und die gleiche Funktionalität bereitstellt. Das ist eigentlich die beste und empfohlene Methode für einen ESP
Ich lasse mich aber gerne eines besseren belehren.

Eventuell hat ja sonst noch jemand eine andere Idee. Ich bin da jetzt raus.
Heinz

@Rentner war schneller :wink:
Du versuchst 2 unterschiedliche Server zusammen kleben das geht nicht.
Der einer ist im Format client.println(), der zweiter ein text/html einen must du umschreiben. Im jedem Fall so wie das ist wird nicht gehen, so sehe ich das, wehre schön wen ich unrecht hatte :wink:

Ich sehe auch keine andere Möglichkeit.

Hallo
@fony da wird der TO doch etwa tiefer einsteigen müssen als wie vorgesehen

Gruß Heinz

Es gäbe evtl. eine dreckige Variante, von der ich allerdings auch abraten möchte:
Alle "server" aus dem 1. Code in wserver umbenennen und dann neu zusammen fügen. Das sollte zumindest kompilieren, sinnvoll ist es nicht. Ob es funktioniert ist auch nicht sicher.

Gruß Tommy

Bin kein HTML Mensch, nehme Beispiele und passe die an.
Wo bei der Konstrukt mit client.println(), ist sehr einfach aber hat seine Grenzen

Gruß Bernhard

@Tommy56 gute Idee das könnte klappen , ob's dann stabil läuft kommt auf einen Versuch an dann gibt's quasi 2 Webserver auf einem System

Gruß Heinz

Also da wurde mir was bei Fips klauen und neu schreiben, die Arbeit ist gleiche und wurde funktionieren.

Gruß Bernhard

Weis nicht, ist wie Quadrat in Kreis formen.

Gruß Bernhard

Nicht klauen, sonder nutzen. Die Codes von Fips stehen unter LGPL. Ansonsten gebe ich Dir Recht.
Das setzt aber voraus, dass der TO sich wenigstens minimal mit der Problematik beschäftigen will oder nur C&P machen will (was meist schief geht und viel mehr Zeit beansprucht, aber leichter aussieht).

Gruß Tommy