---------------------------------------------------------------------------------------------------------------------
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
//#include <DHT.h>
//#include <Adafruit_BMP085.h>
#include "index.h"
#define ssid "MO-Internet" // WiFi SSID
#define password "19881990MO" // WiFi password
//#define DHTTYPE DHT22 // DHT type (DHT11, DHT22)
//#define DHTPIN D4 // Broche du DHT / DHT Pin
//#define LEDPIN D3 // Led
int LEDPIN = 13;
int LEDPIN1 = 12;
ESP8266WebServer server ( 80 );
void handleRoot(){
if ( server.hasArg("LED") ) {
handleSubmit();
} else {
server.send ( 200, "text/html", MAIN_page );
}
}
void handleSubmit() {
// Actualise le GPIO / Update GPIO
String LEDValue;
String LED1Value;
LEDValue = server.arg("LED");
if ( LEDValue == "1" ) {
digitalWrite(LEDPIN, 1);
server.send ( 200, "text/html", MAIN_page );
}
else if ( LEDValue == "0" ) {
digitalWrite(LEDPIN, 0);
server.send ( 200, "text/html", MAIN_page );
} else {
Serial.println("Err Led Value");
}
LED1Value = server.arg("LED1");
if ( LED1Value == "1" ) {
digitalWrite(LEDPIN1, 1);
//
server.send ( 200, "text/html", MAIN_page );
}
else if ( LED1Value == "0" ) {
digitalWrite(LEDPIN1, 0);
//etatLed = "Off";
server.send ( 200, "text/html", MAIN_page );
} else {
Serial.println("Err Led Value");
}
}
void setup() {
pinMode(LEDPIN, OUTPUT);
pinMode(LEDPIN1, OUTPUT);
digitalWrite(LEDPIN, 0);
digitalWrite(LEDPIN1, 0);
Serial.begin ( 115200 );
WiFi.begin ( ssid, password );
// Attente de la connexion au réseau WiFi / Wait for connection
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 ); Serial.print ( "." );
}
// Connexion WiFi établie / WiFi connexion is OK
Serial.println ( "" );
Serial.print ( "Connected to " ); Serial.println ( ssid );
Serial.print ( "IP address: " ); Serial.println ( WiFi.localIP() );
// On branche la fonction qui gère la premiere page / link to the function that manage launch page
server.on ( "/", handleRoot );
server.begin();
Serial.println ( "HTTP server started" );
}
void loop() {
server.handleClient();
//t = dht.readTemperature();
//h = dht.readHumidity();
// p = bmp.readPressure() / 100.0F;
// delay(1000);
}
-----------------------------------------------------------------
Index.html
-----------------------------------------------------------------
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char MAIN_page[] PROGMEM= R"=====(
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<FORM action="/" method="post">
<P>ssid;</p>
<button name="LED" type="submit" value="1" class="btn btn-primary">ON</button>
<button name="LED" type="submit" value="0" class="btn btn-primary">OFF</button>
</FORM>
</body>
</html>
)=====";