Artouste:
Bonsoir
mets ton code complet (qui compile OK)
Je post mon code complet qui compile, en 2 parties.
J-M-L:
Vous balancez quelle tension sur A0? Votre ESP ne peut pas lire plus de 3.2V (de mémoire)
Vous êtes sûr d’avoir branché sur A0 et pas GPIO 0?
Oui c'est bien brancher sur A0, si je fais un petit prog juste pour lire le A0 et afficher le résultat dans le moniteur série ça marche, il se branche sur du 3V ou du 5V.
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h>
#include <FS.h>
#include <dampermotor.h>
const char* ssid = "ASUS";
const char* password = "Famillejacobi";
const String CONFIG_HTML = "/html/config.html";
const String DISPLAY_DATA_HTML = "/html/display_data.html";
const char *configUsername = "admin";
const char *configPwd = "admin";
ESP8266WebServer server(80);
#define SoilSensor A0
#define SoilSensorEnablePin1 D0
#define SoilSensorEnablePin2 D1
#define SoilSensorEnablePin3 D2
#define SoilSensorEnablePin4 D3
#define tap_solenoid_timeout 1500 // delay for 3 sec.
#define PumpPin 2
//Config cible humidité des plantes
const int MintSoilMoisture = 250;//Menth
const int ParsleySoilMoisture = 230;//Persil
const int BasilSoilMoisture = 260;//Basilic
const int CorianderSoilMoisture = 300;//Coriande
const int DillSoilMoisture = 2700;//Aneth
const int SageSoilMoisture = 310;//Sauge
const int rosemarySoilMoisture = 200;//Romarin
int PlantSensor1,PlantSensor2,PlantSensor3,PlantSensor4; //User final target after converted from WebForm
int read_sensor_value1,read_sensor_value2,read_sensor_value3,read_sensor_value4; //lire les donnees des capteurs
boolean electric_tap_motor1,electric_tap_motor2,electric_tap_motor3,electric_tap_motor4; //ouvrir ou fermets les robinets
String XML;
dampermotor tap_motor_sensor1(D4,D5,tap_solenoid_timeout); // définir pin 4,5 pour entraîner le moteur par a port au capteur1
dampermotor tap_motor_sensor2(D6,D7,tap_solenoid_timeout); // définir pin 6,7 pour entraîner le moteur par a port au capteur2
dampermotor tap_motor_sensor3(D8,D9,tap_solenoid_timeout); // définir pin 8,9 pour entraîner le moteur par a port au capteur3
//dampermotor tap_motor_sensor4(D10,11,tap_solenoid_timeout); // définir pin 10,11 pour entraîner le moteur par a port au capteur4
/*affiche la racine du site.*/
void handleRoot() {
server.send(200, "text/plain", "Welcome to my Irrigation System!");
}
/* Affiche la page de configuration.*/
void handleConfig()
{
String form = "";
File f = SPIFFS.open(CONFIG_HTML, "r");
if (!f){
Serial.println("Can't open config html file");
server.send(404, "text/html", "File not found");
}
else{
char buf[1024];
int siz = f.size();
while(siz > 0) {
size_t len = std::min((int)(sizeof(buf) - 1), siz);
f.read((uint8_t *)buf, len);
buf[len] = 0;
form += buf;
siz -= sizeof(buf) - 1;
}
f.close();
server.send(200, "text/html", form);
}
}
* Affiche la page display data.*/
void DisplayData()
{
String form = "";
File f = SPIFFS.open(DISPLAY_DATA_HTML, "r");
if (!f){
Serial.println("Can't open update html file");
server.send(404, "text/html", "File not found");
}
else{
char buf[1024];
int siz = f.size();
while(siz > 0) {
size_t len = std::min((int)(sizeof(buf) - 1), siz);
f.read((uint8_t *)buf, len);
buf[len] = 0;
form += buf;
siz -= sizeof(buf) - 1;
}
f.close();
server.send(200, "text/html", form);
}
}
void handleXML(){
XML="<?xml version='1.0'?>";
XML+="<xml>";
XML+="<sens1>";
XML+= read_sensor_value1;
XML+="</sens1>";
XML+="<sens2>";
XML+= read_sensor_value2;
XML+="</sens2>";
XML+="<sens3>";
XML+= read_sensor_value3;
XML+="</sens3>";
XML+="<sens4>";
XML+= read_sensor_value4;
XML+="</sens4>";
XML+="</xml>";
server.send(200,"text/xml",XML);
}
void handleReadUserPlantSelected()
{
// Recevoir les données cible par Form WEB dans String
String WebUserPlantSensor1 = server.arg("sensor1");
String WebUserPlantSensor2 = server.arg("sensor2");
String WebUserPlantSensor3 = server.arg("sensor3");
String WebUserPlantSensor4 = server.arg("sensor4");
// convertir le String en Int
PlantSensor1 = atoi(WebUserPlantSensor1.c_str());
PlantSensor2 = atoi(WebUserPlantSensor2.c_str());
PlantSensor3 = atoi(WebUserPlantSensor3.c_str());
PlantSensor4 = atoi(WebUserPlantSensor4.c_str());
// ajuster la cible correcte d'humidité du sol celon plante choisis Form WEB
PlantSensor1 = SoilSensorWebUser(PlantSensor1);
PlantSensor2 = SoilSensorWebUser(PlantSensor2);
PlantSensor3 = SoilSensorWebUser(PlantSensor3);
PlantSensor4 = SoilSensorWebUser(PlantSensor4);
server.sendHeader("Location","/config");
server.send(303);
}
void initWebserver()
{
server.on("/", handleRoot);
/* --- configure the config page, main page --- */
server.on("/config", [&](){
if(!server.authenticate(configUsername, configPwd)){
return server.requestAuthentication();
}else{
handleConfig(); // display the page
}
});
/* --- After press submit button for sensor --- */
server.on("/postindex", [&](){
handleReadUserPlantSelected(); // receive form's data from the form tag where action=postindex
});
/* --- After press display data on Menu run DisplayData()--- */
server.on("/display_data", [&](){
if(!server.authenticate(configUsername, configPwd)){
return server.requestAuthentication();
} else {
DisplayData(); // display the page
}
});
server.on("/reqEtatVariables",handleXML);
server.serveStatic("/css", SPIFFS, "/html/css");
server.serveStatic("/display_data.html", SPIFFS, "/html/display_data.html");
}