Two programs am only 1 arduino help

hello
I have two programs on two adruino

I would like to combine the two programs am only 1 arduino but I can't do it

can help me please


#include <ESP8266WiFi.h>

String apiKey = "xxxxxxxxxx";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";

const char *ssid =  "wifi-orbi-mams";     // replace with your wifi ssid and wpa2 key
const char *pass =  "0019041966";
const char* server = "api.thingspeak.com";

const int AnalogIn  = A0;
float suhu;
int dataadc;

WiFiClient client;

void setup() 
{
       Serial.begin(115200);
       delay(10);

       Serial.println("Connecting to ");
       Serial.println(ssid);

// Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");


      while (WiFi.status() != WL_CONNECTED) 
     {
            delay(500);
            Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected");
      
}



void loop() 
{
  
dataadc = analogRead(AnalogIn);
suhu = dataadc * (3.2/1023.0) * 100.0;


                         if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
                      {  
                            
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(suhu);
                             postStr += "\r\n\r\n";

                             //client.print(String("GET ") + resource + apiKey + "&field1=" + temperatureTemp + "&field2=" + humidityTemp + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
                             client.print(String("GET ") + resource + apiKey + "&field1=" + suhu + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");                             
                                        
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
                             
                             Serial.print("Capteur: ");
                             Serial.print(suhu);
                             Serial.println("  Valeur Capteur. Send to Thingspeak.");
                        }
                        
          client.stop();

          Serial.println("Waiting...");
  
  // thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
  delay(10000);
}

TWO PROGRAMME

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

#include <OneWire.h>
#include <DallasTemperature.h>

#include <SimpleDHT.h>

#define ONE_WIRE_BUS 15

int pinDHT11 = 13;
SimpleDHT11 dht11;

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

MDNSResponder mdns;

// Wi-Fi 
const char* ssid = "wifi_new";
const char* password = "0019041966";

byte arduino_mac[] = { 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192,168,1,50);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

ESP8266WebServer server(80);

int D0_pin = 16;
int D2_pin = 2;//d4
int D1_pin = 5;
int D6_pin = 12;

void setup(void){
  // preparing GPIOs
  pinMode(D0_pin, OUTPUT);
  digitalWrite(D0_pin, LOW);
  pinMode(D2_pin, OUTPUT);
  digitalWrite(D2_pin, LOW);
  pinMode(D1_pin, OUTPUT);
  digitalWrite(D1_pin, LOW);
 
  sensors.begin();

  delay(100);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  WiFi.config(ip, gateway, subnet);
  
 
  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("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }
  
  //+++++++++++++++++++++++ START  LED-1 ++++++++++++++++++++
  server.on("/", [](){
    server.send(200, "text/html", webPage());
  });
  server.on("/socket1On", [](){
    digitalWrite(D0_pin, HIGH);
    server.send(200, "text/html", webPage());
    delay(100);
    
  });
  server.on("/socket1Off", [](){
    digitalWrite(D0_pin, LOW);
    server.send(200, "text/html", webPage());
    delay(100);
 });   
   //+++++++++++++++++++++++ END  LED-1 ++++++++++++++++++++ 
    
   //+++++++++++++++++++++++ START  LED-2  ++++++++++++++++++++ 
  
  server.on("/socket2On", [](){
    digitalWrite(D2_pin, HIGH);
    server.send(200, "text/html", webPage());
    delay(100);    
  });
  server.on("/socket2Off", [](){
    digitalWrite(D2_pin, LOW);
    server.send(200, "text/html", webPage());
    delay(100);
    });  
   // +++++++++++++++++++++++ END  LED-2 ++++++++++++++++++++
   
   //+++++++++++++++++++++++ START  LED-3  ++++++++++++++++++++ 

  server.on("/socket3On", [](){
    digitalWrite(D1_pin, HIGH);
    server.send(200, "text/html", webPage());
    delay(100);    
  });
  server.on("/socket3Off", [](){
    digitalWrite(D1_pin, LOW);
    server.send(200, "text/html", webPage());
    delay(100);
   }); 
   // +++++++++++++++++++++++ END  LED-3 ++++++++++++++++++++
    
    
  
  server.begin();
  Serial.println("HTTP server started");
}
 
void loop(void){
  server.handleClient();
} 

String webPage()
{
  sensors.requestTemperatures();
  byte temperature = 0;
  byte humidity = 0;
  dht11.read(pinDHT11, &temperature, &humidity, NULL); 
  String web; 
  web += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/> <meta charset=\"utf-8\"><title>ESP 8266</title><style>button{color:red;padding: 10px 27px;}</style></head>";
  web += "<h1 style=\"text-align: center;font-family: Open sans;font-weight: 100;font-size: 20px;\"> SERVEUR WEB (La Mare de Gégé) </h1><div>";
  //++++++++++ LED-1  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">(Remplissage en Mode Automatique)</p>";
  if (digitalRead(D0_pin) == 1)
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #43a209;margin: 0 auto;\">Marche AUTO</div>";
  }
  else 
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #ec1212;margin: 0 auto;\">Mare à l'Arrêt</div>";
  }
  web += "<div style=\"text-align: center;margin: 5px 0px;\"> <a href=\"socket1On\"><button>Mise en Marche </button></a>&nbsp;<a href=\"socket1Off\"><button> Mise à l'Arrêt  </button></a></div>";
  // ++++++++ LED-1 +++++++++++++


  
  //++++++++++ LED-2  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">(Remplissage en Mode Continu)</p>";
  if (digitalRead(D2_pin) == 1)
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #43a209;margin: 0 auto;\"> Remplissage en Continu </div>";
  }
  else 
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #ec1212;margin: 0 auto;\">Arrêt</div>";
  }
  web += "<div style=\"text-align: center;margin: 5px 0px;\"> <a href=\"socket2On\"><button> Marche Forçé </button></a>&nbsp;<a href=\"socket2Off\"><button> Arrêt Forçage</button></a></div>";
  // ++++++++ LED-2 +++++++++++++


  
  //++++++++++ LED-3  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 30px;margin-bottom: 5px;\">(Sonde de Niveau)</p>";
  if (digitalRead(D6_pin) == 0)
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #43a209;margin: 0 auto;\">Niveau à 100%</div>";
  }
  else 
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #ec1212;margin: 0 auto;\">Niveau inf à 90%</div>";
  }
   // web += "<div style=\"text-align: center;margin: 5px 0px;\"> <a href=\"socket3On\"><button>ON</button></a>&nbsp;<a href=\"socket3Off\"><button>OFF</button></a></div>";
  // ++++++++ LED-3 +++++++++++++
  
   //++++++++++ DS18B20 TEMP  +++++++++++++
  //web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">----DS18B20 TEMP----</p>";
  
  //web += "<div style=\"text-align: center;width: 98px;color:white ;padding: 10px 30px;background-color: #5191e4;margin: 0 auto;\">"+ String(sensors.getTempCByIndex(0))+"</div>";
  // ++++++++ DS18B20 TEMP  +++++++++++++
  
  //++++++++++ DHT11 TEMP  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">(Température en C°)</p>";
  web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #5191e4;margin: 0 auto;\">"+ String((int)temperature)+"</div>";
  // ++++++++ DHT11 TEMP  +++++++++++++
  
  //++++++++++ DHT11 H  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">(Taux d'Humidité en %)</p>";
  web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #5191e4;margin: 0 auto;\">"+ String((int)humidity)+"</div>";
  // ++++++++ DHT11 H  +++++++++++++
  
  // ========REFRESH=============
  web += "<div style=\"text-align:center;margin-top: 20px;\"><a href=\"/\"><button style=\"width:158px;\">REFRESH</button></a></div>";
  // ========REFRESH=============
  
  
  web += "</div>";
  return(web);
}

`

What do you want the code to do?

really?

hello

I would like to have program 1 and 2 in the same program

both programs work for me
why is it not good?

not good

this program is used to fill my fish pond always at the same level

I would like to add in the attached program: the hours when the water flows

so that I know how long the water has been on


#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

#include <OneWire.h>
#include <DallasTemperature.h>

#include <SimpleDHT.h>

#define ONE_WIRE_BUS 15

int pinDHT11 = 13;
SimpleDHT11 dht11;

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

MDNSResponder mdns;

// Wi-Fi 
const char* ssid = "wifi_new";
const char* password = "0019041966";

byte arduino_mac[] = { 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192,168,1,50);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

ESP8266WebServer server(80);

int D0_pin = 16;
int D2_pin = 2;//d4
int D1_pin = 5;
int D6_pin = 12;

void setup(void){
  // preparing GPIOs
  pinMode(D0_pin, OUTPUT);
  digitalWrite(D0_pin, LOW);
  pinMode(D2_pin, OUTPUT);
  digitalWrite(D2_pin, LOW);
  pinMode(D1_pin, OUTPUT);
  digitalWrite(D1_pin, LOW);
 
  sensors.begin();

  delay(100);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  WiFi.config(ip, gateway, subnet);
  
 
  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("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }
  
  //+++++++++++++++++++++++ START  LED-1 ++++++++++++++++++++
  server.on("/", [](){
    server.send(200, "text/html", webPage());
  });
  server.on("/socket1On", [](){
    digitalWrite(D0_pin, HIGH);
    server.send(200, "text/html", webPage());
    delay(100);
    
  });
  server.on("/socket1Off", [](){
    digitalWrite(D0_pin, LOW);
    server.send(200, "text/html", webPage());
    delay(100);
 });   
   //+++++++++++++++++++++++ END  LED-1 ++++++++++++++++++++ 
    
   //+++++++++++++++++++++++ START  LED-2  ++++++++++++++++++++ 
  
  server.on("/socket2On", [](){
    digitalWrite(D2_pin, HIGH);
    server.send(200, "text/html", webPage());
    delay(100);    
  });
  server.on("/socket2Off", [](){
    digitalWrite(D2_pin, LOW);
    server.send(200, "text/html", webPage());
    delay(100);
    });  
   // +++++++++++++++++++++++ END  LED-2 ++++++++++++++++++++
   
   //+++++++++++++++++++++++ START  LED-3  ++++++++++++++++++++ 

  server.on("/socket3On", [](){
    digitalWrite(D1_pin, HIGH);
    server.send(200, "text/html", webPage());
    delay(100);    
  });
  server.on("/socket3Off", [](){
    digitalWrite(D1_pin, LOW);
    server.send(200, "text/html", webPage());
    delay(100);
   }); 
   // +++++++++++++++++++++++ END  LED-3 ++++++++++++++++++++
    
    
  
  server.begin();
  Serial.println("HTTP server started");
}
 
void loop(void){
  server.handleClient();
} 

String webPage()
{
  sensors.requestTemperatures();
  byte temperature = 0;
  byte humidity = 0;
  dht11.read(pinDHT11, &temperature, &humidity, NULL); 
  String web; 
  web += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/> <meta charset=\"utf-8\"><title>ESP 8266</title><style>button{color:red;padding: 10px 27px;}</style></head>";
  web += "<h1 style=\"text-align: center;font-family: Open sans;font-weight: 100;font-size: 20px;\"> SERVEUR WEB (La Mare de Gégé) </h1><div>";
  //++++++++++ LED-1  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">(Remplissage en Mode Automatique)</p>";
  if (digitalRead(D0_pin) == 1)
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #43a209;margin: 0 auto;\">Marche AUTO</div>";
  }
  else 
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #ec1212;margin: 0 auto;\">Mare à l'Arrêt</div>";
  }
  web += "<div style=\"text-align: center;margin: 5px 0px;\"> <a href=\"socket1On\"><button>Mise en Marche </button></a>&nbsp;<a href=\"socket1Off\"><button> Mise à l'Arrêt  </button></a></div>";
  // ++++++++ LED-1 +++++++++++++


  
  //++++++++++ LED-2  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">(Remplissage en Mode Continu)</p>";
  if (digitalRead(D2_pin) == 1)
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #43a209;margin: 0 auto;\"> Remplissage en Continu </div>";
  }
  else 
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #ec1212;margin: 0 auto;\">Arrêt</div>";
  }
  web += "<div style=\"text-align: center;margin: 5px 0px;\"> <a href=\"socket2On\"><button> Marche Forçé </button></a>&nbsp;<a href=\"socket2Off\"><button> Arrêt Forçage</button></a></div>";
  // ++++++++ LED-2 +++++++++++++


  
  //++++++++++ LED-3  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 30px;margin-bottom: 5px;\">(Sonde de Niveau)</p>";
  if (digitalRead(D6_pin) == 0)
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #43a209;margin: 0 auto;\">Niveau à 100%</div>";
  }
  else 
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #ec1212;margin: 0 auto;\">Niveau inf à 90%</div>";
  }
   // web += "<div style=\"text-align: center;margin: 5px 0px;\"> <a href=\"socket3On\"><button>ON</button></a>&nbsp;<a href=\"socket3Off\"><button>OFF</button></a></div>";
  // ++++++++ LED-3 +++++++++++++
  
   //++++++++++ DS18B20 TEMP  +++++++++++++
  //web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">----DS18B20 TEMP----</p>";
  
  //web += "<div style=\"text-align: center;width: 98px;color:white ;padding: 10px 30px;background-color: #5191e4;margin: 0 auto;\">"+ String(sensors.getTempCByIndex(0))+"</div>";
  // ++++++++ DS18B20 TEMP  +++++++++++++
  
  //++++++++++ DHT11 TEMP  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">(Température en C°)</p>";
  web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #5191e4;margin: 0 auto;\">"+ String((int)temperature)+"</div>";
  // ++++++++ DHT11 TEMP  +++++++++++++
  
  //++++++++++ DHT11 H  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">(Taux d'Humidité en %)</p>";
  web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #5191e4;margin: 0 auto;\">"+ String((int)humidity)+"</div>";
  // ++++++++ DHT11 H  +++++++++++++
  
  // ========REFRESH=============
  web += "<div style=\"text-align:center;margin-top: 20px;\"><a href=\"/\"><button style=\"width:158px;\">REFRESH</button></a></div>";
  // ========REFRESH=============
  
  
  web += "</div>";
  return(web);
}

I don't understand what should I do?

google

 arduino combine two sketches 

and/or

 arduino combine two programs

The better you understand each constituent sketch, the easier combining them will be.

The better the writer of the parts to be combined, the easier it will be. A sketch can be written with the idea that it might one day be part of something bigger; many, even by experience programmers, are not.

You may need also to google and follow the breadcrumbs on the matter of

 arduino two things at once

which shoukd probably begin with a stop and look at

 arduino blink without delay

Yes, lotsa google advice. Settle in and relax about the actual matter - combining sketches is a common inquiry and there is a crap-ton of good stuff to be found on doing it.

a7

you should begin with simple sketches. learn how anything work and go to the next, then to more complicated things. and then you will write such programs by self and/or adopt sketches from web to your needs.

both codes work separately but when be merges the two it always an error

And the error is . . . ?

That's because the two sketches use the same names for different variables. You have to re-name one or both of the variables or functions.

I have done enough to get it all to compile together without errors.

void setup()
{
  setup1();
  setup2();
}

void loop()
{
  loop1();
  loop2();
}


#include <ESP8266WiFi.h>

String apiKey = "xxxxxxxxxx";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";

const char *ssid1 =  "wifi-orbi-mams";     // replace with your wifi ssid and wpa2 key
const char *pass1 =  "0019041966";
const char* server1 = "api.thingspeak.com";

const int AnalogIn  = A0;
float suhu;
int dataadc;

WiFiClient client;

void setup1()
{
  Serial.begin(115200);
  delay(10);

  Serial.println("Connecting to ");
  Serial.println(ssid1);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid1);

  WiFi.begin(ssid1, pass1);

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");


  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

}



void loop1()
{

  dataadc = analogRead(AnalogIn);
  suhu = dataadc * (3.2 / 1023.0) * 100.0;


  if (client.connect(server1, 80))  //   "184.106.153.149" or api.thingspeak.com
  {

    String postStr = apiKey;
    postStr += "&field1=";
    postStr += String(suhu);
    postStr += "\r\n\r\n";

    //client.print(String("GET ") + resource + apiKey + "&field1=" + temperatureTemp + "&field2=" + humidityTemp + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
    client.print(String("GET ") + resource + apiKey + "&field1=" + suhu + " HTTP/1.1\r\n" + "Host: " + server1 + "\r\n" + "Connection: close\r\n\r\n");

    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);

    Serial.print("Capteur: ");
    Serial.print(suhu);
    Serial.println("  Valeur Capteur. Send to Thingspeak.");
  }

  client.stop();

  Serial.println("Waiting...");

  // thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
  delay(10000);
}


#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

#include <OneWire.h>
#include <DallasTemperature.h>

#include <SimpleDHT.h>

#define ONE_WIRE_BUS 15

int pinDHT11 = 13;
SimpleDHT11 dht11;

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

MDNSResponder mdns;

// Wi-Fi 
const char* ssid2 = "wifi_new";
const char* password2 = "0019041966";

byte arduino_mac[] = { 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192,168,1,50);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

ESP8266WebServer server(80);

int D0_pin = 16;
int D2_pin = 2;//d4
int D1_pin = 5;
int D6_pin = 12;

void setup2(void){
  // preparing GPIOs
  pinMode(D0_pin, OUTPUT);
  digitalWrite(D0_pin, LOW);
  pinMode(D2_pin, OUTPUT);
  digitalWrite(D2_pin, LOW);
  pinMode(D1_pin, OUTPUT);
  digitalWrite(D1_pin, LOW);
 
  sensors.begin();

  delay(100);
  Serial.begin(115200);
  WiFi.begin(ssid2, password2);
  WiFi.config(ip, gateway, subnet);
  
 
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
   Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid2);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  
  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }
  
  //+++++++++++++++++++++++ START  LED-1 ++++++++++++++++++++
  server.on("/", [](){
    server.send(200, "text/html", webPage());
  });
  server.on("/socket1On", [](){
    digitalWrite(D0_pin, HIGH);
    server.send(200, "text/html", webPage());
    delay(100);
    
  });
  server.on("/socket1Off", [](){
    digitalWrite(D0_pin, LOW);
    server.send(200, "text/html", webPage());
    delay(100);
 });   
   //+++++++++++++++++++++++ END  LED-1 ++++++++++++++++++++ 
    
   //+++++++++++++++++++++++ START  LED-2  ++++++++++++++++++++ 
  
  server.on("/socket2On", [](){
    digitalWrite(D2_pin, HIGH);
    server.send(200, "text/html", webPage());
    delay(100);    
  });
  server.on("/socket2Off", [](){
    digitalWrite(D2_pin, LOW);
    server.send(200, "text/html", webPage());
    delay(100);
    });  
   // +++++++++++++++++++++++ END  LED-2 ++++++++++++++++++++
   
   //+++++++++++++++++++++++ START  LED-3  ++++++++++++++++++++ 

  server.on("/socket3On", [](){
    digitalWrite(D1_pin, HIGH);
    server.send(200, "text/html", webPage());
    delay(100);    
  });
  server.on("/socket3Off", [](){
    digitalWrite(D1_pin, LOW);
    server.send(200, "text/html", webPage());
    delay(100);
   }); 
   // +++++++++++++++++++++++ END  LED-3 ++++++++++++++++++++
    
  server.begin();
  Serial.println("HTTP server started");
}
 
void loop2(void){
  server.handleClient();
} 

String webPage()
{
  sensors.requestTemperatures();
  byte temperature = 0;
  byte humidity = 0;
  dht11.read(pinDHT11, &temperature, &humidity, NULL); 
  String web; 
  web += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/> <meta charset=\"utf-8\"><title>ESP 8266</title><style>button{color:red;padding: 10px 27px;}</style></head>";
  web += "<h1 style=\"text-align: center;font-family: Open sans;font-weight: 100;font-size: 20px;\"> SERVEUR WEB (La Mare de Gégé) </h1><div>";
  //++++++++++ LED-1  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">(Remplissage en Mode Automatique)</p>";
  if (digitalRead(D0_pin) == 1)
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #43a209;margin: 0 auto;\">Marche AUTO</div>";
  }
  else 
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #ec1212;margin: 0 auto;\">Mare à l'Arrêt</div>";
  }
  web += "<div style=\"text-align: center;margin: 5px 0px;\"> <a href=\"socket1On\"><button>Mise en Marche </button></a>&nbsp;<a href=\"socket1Off\"><button> Mise à l'Arrêt  </button></a></div>";
  // ++++++++ LED-1 +++++++++++++


  
  //++++++++++ LED-2  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">(Remplissage en Mode Continu)</p>";
  if (digitalRead(D2_pin) == 1)
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #43a209;margin: 0 auto;\"> Remplissage en Continu </div>";
  }
  else 
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #ec1212;margin: 0 auto;\">Arrêt</div>";
  }
  web += "<div style=\"text-align: center;margin: 5px 0px;\"> <a href=\"socket2On\"><button> Marche Forçé </button></a>&nbsp;<a href=\"socket2Off\"><button> Arrêt Forçage</button></a></div>";
  // ++++++++ LED-2 +++++++++++++


  
  //++++++++++ LED-3  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 30px;margin-bottom: 5px;\">(Sonde de Niveau)</p>";
  if (digitalRead(D6_pin) == 0)
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #43a209;margin: 0 auto;\">Niveau à 100%</div>";
  }
  else 
  {
    web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #ec1212;margin: 0 auto;\">Niveau inf à 90%</div>";
  }
   // web += "<div style=\"text-align: center;margin: 5px 0px;\"> <a href=\"socket3On\"><button>ON</button></a>&nbsp;<a href=\"socket3Off\"><button>OFF</button></a></div>";
  // ++++++++ LED-3 +++++++++++++
  
   //++++++++++ DS18B20 TEMP  +++++++++++++
  //web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">----DS18B20 TEMP----</p>";
  
  //web += "<div style=\"text-align: center;width: 98px;color:white ;padding: 10px 30px;background-color: #5191e4;margin: 0 auto;\">"+ String(sensors.getTempCByIndex(0))+"</div>";
  // ++++++++ DS18B20 TEMP  +++++++++++++
  
  //++++++++++ DHT11 TEMP  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">(Température en C°)</p>";
  web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #5191e4;margin: 0 auto;\">"+ String((int)temperature)+"</div>";
  // ++++++++ DHT11 TEMP  +++++++++++++
  
  //++++++++++ DHT11 H  +++++++++++++
  web += "<p style=\"text-align: center;margin-top: 0px;margin-bottom: 5px;\">(Taux d'Humidité en %)</p>";
  web += "<div style=\"text-align: center;width: 98px;color:black ;padding: 10px 30px;background-color: #5191e4;margin: 0 auto;\">"+ String((int)humidity)+"</div>";
  // ++++++++ DHT11 H  +++++++++++++
  
  // ========REFRESH=============
  web += "<div style=\"text-align:center;margin-top: 20px;\"><a href=\"/\"><button style=\"width:158px;\">REFRESH</button></a></div>";
  // ========REFRESH=============
  
  
  web += "</div>";
  return(web);
}

HELLO
all works thank you very much!! :grinning: I understand the handling a bit better

on the other hand, the network is very ready now, is it normal?
I think it's due to the two ip addresses?

is it possible to create a single IP address for both programs?
because the page but about 45 sec to display locally

Remember that one of your 'loop()' functions has a 10-second delay in it. The other 'loop()' function can't do anything until that delay ends. You can fix that by using a millis() timer (See the "BlinkWithoutDelay" example) to only run only every 10 seconds and otherwise return immediately.

thanks for this lead i will check it out

what should I put instead?

 String web; 
  web += "<head>
String web; 
  web = "<head>

or

String web=""; 
  web += "<head>

or

String web = "<head>..."

OK
thank you :slight_smile:

All 3 work but I don't see any difference.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.