ChristiaM:
Je n'ai pas l'impression d'avoir dit que j'avais un problème d'upload, mais un problème de fonctionnement.
Excuse moi si je me suis mal exprimé.
Mon ESP8266 est alimenté par 2 piles AA neuves
comme indiqué par al1fch 2 piles AA c'est très limite en V et en debit instantané
fais tes test avec une vraie alim 3.3V capable de debiter en continu mini 500 mA
accessoirement un petit sketch "sans lib externe " gerant 2 sorties
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
const char* ssid = "SSID"; // SSID of LAN/WLAN
const char* password = "PASS"; // password
const int port = 80; // port to serve pages through
const int led0 = 13;
const int led1 = 12;
const int led2 = 14;
int v1 = 0;
int v2 = 0;
unsigned long da1 = 149;
WiFiServer server(port);
IPAddress ip(192, 168, 1, 190); // OK IP BOX ORANGE
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
void setup() {
Serial.begin(115200);
confap();
// start serial for debug
delay(10);
scannw();
Serial.println();
Serial.print("Flash Size = ");
Serial.println(ESP.getFlashChipSize());
pinMode(led0, OUTPUT); // all outputs for LEDs
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
digitalWrite(led0, 0); // all LEDs off to start
digitalWrite(led1, 0);
digitalWrite(led2, 0);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet);
// connect to WiFi network
while (WiFi.status() != WL_CONNECTED) { // wait until connected
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
server.begin(); // Start the server
Serial.println("Server started");
Serial.println(WiFi.localIP()); // Print the servers IP address
WiFi.printDiag(Serial);
Serial.println(WiFi.macAddress());
Serial.println(WiFi.localIP());
Serial.println(WiFi.softAPmacAddress());
Serial.println(WiFi.softAPIP());
}
void loop() {
WiFiClient client = server.available(); // Check if a client has connected
if (!client) {
return;
}
Serial.println("New client"); // Wait until the client sends some data
while (!client.available()) {
delay(1);
}
String req = client.readStringUntil('\r'); // Read the first line of the request
Serial.println(req);
client.flush();
if (req.indexOf("/led1/0") != -1) // if req = /led1/0
v1 = 0; // set flag to turn LED1 off
else if (req.indexOf("/led1/1") != -1) // if req = /led1/1
v1 = 1; // set flag to turn LED1 on
else if (req.indexOf("/led2/0") != -1) // if req = /led2/0
v2 = 0; // set flag to turn LED2 off
else if (req.indexOf("/led2/1") != -1) // if req = /led2/1
v2 = 1; // set flag to turn LED2 on
else {
Serial.println("Invalid request"); // URL not recognised
String r = HTMLHeader(); // display home page
r += HTMLPage();
r += HTMLFooter();
client.print(r); // send page to clients browser
client.stop(); // disconnect client
return;
}
digitalWrite(led1, v1); // set LED1 according to v1
digitalWrite(led2, v2); // set LED2 according to v2
client.flush();
String s = HTMLHeader(); // display page
s += HTMLPage();
s += HTMLFooter();
digitalWrite(led0, 1); // page is being sent
client.print(s); // send the response to the client
client.stop(); // disconnect client
digitalWrite(led0, 0); // finished sending page
Serial.print("A0= ");
Serial.println(analogRead(A0));
delay(1);
Serial.println("Client disconnected");
Serial.println("");
}
String HTMLHeader() { // standard HTML header
String h = "HTTP/1.1 200 OK\r\n";
h += "Content-Type: text/html\r\n\r\n";
h += "<meta http-equiv=refresh content=5>\r\n";
h += "<!DOCTYPE HTML>";
h += "<html>\n";
h += "<body>\n";
return h;
}
String HTMLFooter() { // standard HTML footer
String f = "<table width=\"100%\" bgcolor=\"green\" cellpadding=\"12\" border=\"0\">\n";
f += "<tr><td><p style = \"color: white; background: black;font-size: 0.8em;";
f += "font-weight: bold; text-align: center; margin: 0px 10px 0px 10px;\">\n";
f += "<a href = \"HANGAR </a> © 2015</p></td></tr>";
f += "</table>";
f += "</body>\n";
f += "</html>\n";
return f;
}
String HTMLPage() { // main HTML for page, edit to suit your application
String p = "<h1>DELESTEUR SECTORIEL </h1>\n";
p += "<p>HANGAR 76520 1 ET 2</b></p>\n";
da1 = millis() / 1000;
p += (da1);
p += "<p>DELESTAGE</b> HANGAR 76520</p>\n";
// display links depending on current state of LEDs 1 & 2
p += (v1) ? "<p><a href = \"/led1/0\">DESACTIVER DELESTEUR 1 </a></p>\n" : "<p><a href = \"/led1/1\">ACTIVER DELESTEUR 1 </a></p>\n";
p += (v2) ? "<p><a href = \"/led2/0\">DESACTIVER DELESTEUR 2</a></p>\n" : "<p><a href = \"/led2/1\">ACTIVER DELESTEUR 2</a></p>\n";
return p;
}
void scannw()
{
// scan network
Serial.println("scan start");
// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0)
Serial.println("no networks found");
else
{
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i)
{
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");
delay(10);
}
}
}
void confap() {
const char *apssid = "76520 H1 H2";
const char *appassword = "";
Serial.println();
Serial.print("SOFTAP SSID = ");
Serial.println(apssid);
Serial.print("SOFTAP PASSWORD = ");
Serial.println(appassword);
Serial.print("Configuring access point...");
IPAddress APIp(189, 32, 16, 8); // ok IP SOFT AP
IPAddress NMask(255, 255, 255, 0);
WiFi.softAPConfig(APIp, APIp, NMask);
WiFi.softAP(apssid, appassword);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
}