diff --git a/ESP8266_BATTERIE_INJECTION/ESP8266_BATTERIE_INJECTION.ino b/ESP8266_BATTERIE_INJECTION/ESP8266_BATTERIE_INJECTION.ino index be4438a..8e0f62e 100644 --- a/ESP8266_BATTERIE_INJECTION/ESP8266_BATTERIE_INJECTION.ino +++ b/ESP8266_BATTERIE_INJECTION/ESP8266_BATTERIE_INJECTION.ino @@ -38,26 +38,26 @@ const char* adminPassword = "setaou"; // Mot de passe pour la connexion //#define PIN_DIMMER_OUTPUT 18 // D8 //#define PIN_DIMMER_ZEROCROSS 19 // 12 // D6 for boards with CHANGEBLE input pins #ifdef ESP8266 - #define PIN_SOFTWARE_SERIAL_RX D4 // GPIO2 - #define PIN_SOFTWARE_SERIAL_TX D2 // GPIO4 +#define PIN_SOFTWARE_SERIAL_RX D4 // GPIO2 +#define PIN_SOFTWARE_SERIAL_TX D2 // GPIO4 #elif defined(ESP32) - //#define PZEM true - #define PIN_LED 2 - #define SERIAL_BLUE_SOLAR true - #define SERIAL_XY6020L true - //#define SERIAL_XY6020L_2 true - - - #define PIN_SOFTWARE_SERIAL_RX 4 - #define PIN_SOFTWARE_SERIAL_TX 5 - #define PIN_SOFTWARE_SERIAL_RX2 25 - #define PIN_SOFTWARE_SERIAL_TX2 26 - #define PIN_SOFTWARE_SERIAL_TX3 32 - #define PIN_SOFTWARE_SERIAL_RX3 33 +//#define PZEM true +#define PIN_LED 2 +#define SERIAL_BLUE_SOLAR true +#define SERIAL_XY6020L true +//#define SERIAL_XY6020L_2 true - #define PIN_REGULATION 21 - // #define PIN_DALLAS 26 // D5 - //#define PIN_HALL 33 + +#define PIN_SOFTWARE_SERIAL_RX 4 +#define PIN_SOFTWARE_SERIAL_TX 5 +#define PIN_SOFTWARE_SERIAL_RX2 25 +#define PIN_SOFTWARE_SERIAL_TX2 26 +#define PIN_SOFTWARE_SERIAL_TX3 32 +#define PIN_SOFTWARE_SERIAL_RX3 33 + +#define PIN_REGULATION 21 +// #define PIN_DALLAS 26 // D5 +//#define PIN_HALL 33 #endif @@ -146,21 +146,21 @@ dimmerLamp dimmer(PIN_DIMMER_OUTPUT, PIN_DIMMER_ZEROCROSS); //initialase port fo // DALLAS ///////////////////////////////////////// #ifdef PIN_DALLAS - float temperature = 0; - - #include - #include - #define onewirepin PIN_DALLAS // DATA pin of DS18B20 wired to pin DALLAS of Arduino - - OneWire oneWire(onewirepin); - DallasTemperature sensors(&oneWire); - - // find the DeviceAddress of your DS18B20 with the sketch DS18B20_address_reporter - // then replace the 8-byte ID below with the reported one - - DeviceAddress Probe = { 0x28, 0xFF, 0x61, 0x1D, 0x76, 0x04, 0x00, 0x34 }; - - float printTemperature(DeviceAddress deviceAddress); +float temperature = 0; + +#include +#include +#define onewirepin PIN_DALLAS // DATA pin of DS18B20 wired to pin DALLAS of Arduino + +OneWire oneWire(onewirepin); +DallasTemperature sensors(&oneWire); + +// find the DeviceAddress of your DS18B20 with the sketch DS18B20_address_reporter +// then replace the 8-byte ID below with the reported one + +DeviceAddress Probe = { 0x28, 0xFF, 0x61, 0x1D, 0x76, 0x04, 0x00, 0x34 }; + +float printTemperature(DeviceAddress deviceAddress); #endif void blink(); @@ -216,26 +216,26 @@ unsigned long lastTimeRead = millis(); // PZEM for arduino // ----------------- #ifdef PZEM - #include - - #ifdef ESP8266 - #define PIN_PZEM_1 D5 - #define PIN_PZEM_2 D6 - PZEM004Tv30 pzem(PIN_PZEM_1, PIN_PZEM_2); - - #elif defined(ESP32) - - #define RXD2 16 - #define TXD2 17 - PZEM004Tv30 pzem(&Serial2); - #endif - - double voltage; - double current; - double pf; - double power; - double energy; - double frequency; +#include + +#ifdef ESP8266 +#define PIN_PZEM_1 D5 +#define PIN_PZEM_2 D6 +PZEM004Tv30 pzem(PIN_PZEM_1, PIN_PZEM_2); + +#elif defined(ESP32) + +#define RXD2 16 +#define TXD2 17 +PZEM004Tv30 pzem(&Serial2); +#endif + +double voltage; +double current; +double pf; +double power; +double energy; +double frequency; #endif @@ -245,130 +245,130 @@ void setup() { // initialize digital pin LED_BUILTIN as an output. Serial.begin(115200); - #ifdef PZEM - #ifdef ESP32 - Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2); - #endif - #endif - - #ifdef PIN_TENSION - pinMode(PIN_TENSION, INPUT); - #endif - #ifdef PIN_HALL - pinMode(PIN_HALL, INPUT); - delay(200); - getHall(); - #endif - #ifdef PIN_POWER - pinMode(PIN_POWER, OUTPUT); - #endif - #ifdef PIN_LED - pinMode(PIN_LED, OUTPUT); - #endif - - pinMode(PIN_INJECTION, OUTPUT); - pinMode(PIN_CHARGE, OUTPUT); - #ifdef PIN_BATTERIE - pinMode(PIN_BATTERIE, OUTPUT); - #endif - #ifdef PIN_REGULATION - - #ifdef ESP32 - // ledcAttachPin(PIN_REGULATION, 0); // assign a led pins to a channel - // // Initialize channels - // // channels 0-15, resolution 1-16 bits, freq limits depend on resolution - // // ledcSetup(uint8_t channel, uint32_t freq, uint8_t resolution_bits); - // ledcSetup(0, 4000, 8); // 12 kHz PWM, 8-bit resolution - pinMode(PIN_REGULATION, OUTPUT); - #else - pinMode(PIN_REGULATION, OUTPUT); // set mtorPin as output - #endif - #endif - #ifdef SERIAL_BLUE_SOLAR - #ifdef ESP32 - Serial1.begin(19200, SERIAL_8N1, PIN_SOFTWARE_SERIAL_RX, PIN_SOFTWARE_SERIAL_TX); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 - #else - // Serial port configuration - //Baud rate:19200 - //Data bits: 8 - //Parity: None - //Stop bits: 1 - //Flow control: None - victronSerial.begin(19200); //, SWSERIAL_8N1); - #endif - #endif - char tmpBuf[30]; // text buffer for serial messages +#ifdef PZEM +#ifdef ESP32 + Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2); +#endif +#endif - #ifdef SERIAL_XY6020L - #ifdef ESP32 - xy6020l xy(Serial2, 0x01, 50, XY6020_OPT_SKIP_SAME_HREG_VALUE | XY6020_OPT_NO_HREG_UPDATE); - - Serial2.begin(115200, SERIAL_8N1, PIN_SOFTWARE_SERIAL_RX2, PIN_SOFTWARE_SERIAL_TX2); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 - Serial.println("HardwareSerial (Serial) initialisé"); +#ifdef PIN_TENSION + pinMode(PIN_TENSION, INPUT); +#endif +#ifdef PIN_HALL + pinMode(PIN_HALL, INPUT); + delay(200); + getHall(); +#endif +#ifdef PIN_POWER + pinMode(PIN_POWER, OUTPUT); +#endif +#ifdef PIN_LED + pinMode(PIN_LED, OUTPUT); +#endif - // 12 V supply - Mem.Nr = MemIdx; - Mem.VSet = 0; // 10v - Mem.ISet = 500; - Mem.sLVP = 1000; - Mem.sOVP = 1300; - Mem.sOCP = 620; - Mem.sOPP = 1040; - Mem.sOHPh= 0; - Mem.sOHPm= 0; - Mem.sOAH = 0; - Mem.sOWH = 0; - Mem.sOTP = 61; - Mem.sINI = 0; - xy.SetMemory(Mem); - xy.PrintMemory(Mem); - - - // START DISABLE ALL - xy.setOutput(false); - xy.setCV(0); - xy.setCC(0); + pinMode(PIN_INJECTION, OUTPUT); + pinMode(PIN_CHARGE, OUTPUT); +#ifdef PIN_BATTERIE + pinMode(PIN_BATTERIE, OUTPUT); +#endif +#ifdef PIN_REGULATION - sprintf( tmpBuf, "Modele 1 :%04X Version 1 :%04X\n", xy.getModel(), xy.getVersion() ); +#ifdef ESP32 + // ledcAttachPin(PIN_REGULATION, 0); // assign a led pins to a channel + // // Initialize channels + // // channels 0-15, resolution 1-16 bits, freq limits depend on resolution + // // ledcSetup(uint8_t channel, uint32_t freq, uint8_t resolution_bits); + // ledcSetup(0, 4000, 8); // 12 kHz PWM, 8-bit resolution + pinMode(PIN_REGULATION, OUTPUT); +#else + pinMode(PIN_REGULATION, OUTPUT); // set mtorPin as output +#endif +#endif +#ifdef SERIAL_BLUE_SOLAR +#ifdef ESP32 + Serial1.begin(19200, SERIAL_8N1, PIN_SOFTWARE_SERIAL_RX, PIN_SOFTWARE_SERIAL_TX); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 +#else + // Serial port configuration + //Baud rate:19200 + //Data bits: 8 + //Parity: None + //Stop bits: 1 + //Flow control: None + victronSerial.begin(19200); //, SWSERIAL_8N1); +#endif +#endif + char tmpBuf[30]; // text buffer for serial messages + +#ifdef SERIAL_XY6020L +#ifdef ESP32 + xy6020l xy(Serial2, 0x01, 50, XY6020_OPT_SKIP_SAME_HREG_VALUE | XY6020_OPT_NO_HREG_UPDATE); + + Serial2.begin(115200, SERIAL_8N1, PIN_SOFTWARE_SERIAL_RX2, PIN_SOFTWARE_SERIAL_TX2); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 + Serial.println("HardwareSerial (Serial) initialisé"); + + // 12 V supply + Mem.Nr = MemIdx; + Mem.VSet = 0; // 10v + Mem.ISet = 500; + Mem.sLVP = 1000; + Mem.sOVP = 1300; + Mem.sOCP = 620; + Mem.sOPP = 1040; + Mem.sOHPh = 0; + Mem.sOHPm = 0; + Mem.sOAH = 0; + Mem.sOWH = 0; + Mem.sOTP = 61; + Mem.sINI = 0; + xy.SetMemory(Mem); + xy.PrintMemory(Mem); + + + // START DISABLE ALL + xy.setOutput(false); + xy.setCV(0); + xy.setCC(0); + + sprintf( tmpBuf, "Modele 1 :%04X Version 1 :%04X\n", xy.getModel(), xy.getVersion() ); Serial.print(tmpBuf); - #endif - #endif +#endif +#endif - #ifdef SERIAL_XY6020L_2 - #ifdef ESP32 - - // xy6020l xy2(Serial3, 0x01, 50, XY6020_OPT_SKIP_SAME_HREG_VALUE | XY6020_OPT_NO_HREG_UPDATE); - - Serial3.begin(115200); //, SERIAL_8N1); //, PIN_SOFTWARE_SERIAL_RX2, PIN_SOFTWARE_SERIAL_TX2); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 - Serial.println("SoftwareSerial (Serial3) initialisé à 115200 baud."); - - // 12 V supply - Mem2.Nr = MemIdx; - Mem2.VSet = 0; // 10v - Mem2.ISet = 500; - Mem2.sLVP = 1000; - Mem2.sOVP = 1300; - Mem2.sOCP = 619; - Mem2.sOPP = 1041; - Mem2.sOHPh= 0; - Mem2.sOHPm= 0; - Mem2.sOAH = 0; - Mem2.sOWH = 0; - Mem2.sOTP = 60; - Mem2.sINI = 0; - xy2.SetMemory(Mem2); - xy2.PrintMemory(Mem2); - - - // START DISABLE ALL - xy2.setOutput(false); - xy2.setCV(0); - xy2.setCC(0); +#ifdef SERIAL_XY6020L_2 +#ifdef ESP32 - sprintf( tmpBuf, "Modele 2 :%04X Version 2 :%04X\n", xy.getModel(), xy.getVersion() ); + // xy6020l xy2(Serial3, 0x01, 50, XY6020_OPT_SKIP_SAME_HREG_VALUE | XY6020_OPT_NO_HREG_UPDATE); + + Serial3.begin(115200); //, SERIAL_8N1); //, PIN_SOFTWARE_SERIAL_RX2, PIN_SOFTWARE_SERIAL_TX2); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 + Serial.println("SoftwareSerial (Serial3) initialisé à 115200 baud."); + + // 12 V supply + Mem2.Nr = MemIdx; + Mem2.VSet = 0; // 10v + Mem2.ISet = 500; + Mem2.sLVP = 1000; + Mem2.sOVP = 1300; + Mem2.sOCP = 619; + Mem2.sOPP = 1041; + Mem2.sOHPh = 0; + Mem2.sOHPm = 0; + Mem2.sOAH = 0; + Mem2.sOWH = 0; + Mem2.sOTP = 60; + Mem2.sINI = 0; + xy2.SetMemory(Mem2); + xy2.PrintMemory(Mem2); + + + // START DISABLE ALL + xy2.setOutput(false); + xy2.setCV(0); + xy2.setCC(0); + + sprintf( tmpBuf, "Modele 2 :%04X Version 2 :%04X\n", xy.getModel(), xy.getVersion() ); Serial.print(tmpBuf); - #endif - #endif +#endif +#endif delay(10); @@ -377,7 +377,7 @@ void setup() { // Connectez-vous au réseau WiFi WiFi.begin(ssid, pass); Serial.println("Connexion au WiFi en cours."); - + while (WiFi.status() != WL_CONNECTED) { digitalWrite(PIN_LED, LOW); delay(500); @@ -410,30 +410,30 @@ void setup() { server.on("/save", HTTP_POST, handleSave); //server.on("/test", HTTP_GET, handleTestConnection); server.on("/slider", HTTP_POST, handleUpdate); - - #ifdef SERIAL_BLUE_SOLAR - - // Initialisation de l'EEPROM - EEPROM.begin(EEPROM_SIZE); //sizeof(To_Store) + sizeof(config)); - - // Lire la valeur stockée dans l'EEPROM - EEPROM.get(TO_STORE_ADDRESS, to_store); - // Lire la configuration - readConfiguration(); - - // initialize_arrays(); - for (int i = 0; i < maxSize; i++) { - if (to_store.tensions[i] > 30000 || to_store.tensions[i] < 10) { - to_store.tensions[i] = 26000; - } - // to_store.hour[i] = 0; - // to_store.min[i] = 0; + +#ifdef SERIAL_BLUE_SOLAR + + // Initialisation de l'EEPROM + EEPROM.begin(EEPROM_SIZE); //sizeof(To_Store) + sizeof(config)); + + // Lire la valeur stockée dans l'EEPROM + EEPROM.get(TO_STORE_ADDRESS, to_store); + // Lire la configuration + readConfiguration(); + + // initialize_arrays(); + for (int i = 0; i < maxSize; i++) { + if (to_store.tensions[i] > 30000 || to_store.tensions[i] < 10) { + to_store.tensions[i] = 26000; } - if (to_store.total_elements > maxSize) { - to_store.total_elements = 0; - } - - #endif + // to_store.hour[i] = 0; + // to_store.min[i] = 0; + } + if (to_store.total_elements > maxSize) { + to_store.total_elements = 0; + } + +#endif configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // Synchronize time @@ -443,56 +443,56 @@ void setup() { time(¤tTime); lastSyncMillis = millis(); - // Dimmer - #ifdef PIN_DIMMER_OUTPUT - server.on("/minus", minus); - server.on("/plus", plus); - server.on("/exact", exact); - server.on("/zero", stopPWM); - #endif - - #ifdef PIN_REGULATION - server.on("/minus_reg", minus_reg); - server.on("/plus_reg", plus_reg); - server.on("/exact_reg", exact_reg); - server.on("/zero_reg", stop_reg); - #endif - - //initialize variables__________________ - pwm = 0; - led = 0; - // Dimmer - Serial.println("Dimmer Program is starting..."); - delay(1000); - #ifdef PIN_DIMMER_OUTPUT - dimmer.begin(NORMAL_MODE, ON); //dimmer initialisation: name.begin(MODE, STATE) - Serial.println("Set value"); - dimmer.setState(ON_OFF_typedef::OFF); - dimmer.setPower(pwm); // setPower(0-100%); - #endif - - // Démarrer le serveur - server.begin(); - Serial.println("Serveur Web démarré"); - - #ifdef PIN_DALLAS - - sensors.begin (); // Initialize the sensor and set resolution level - sensors.setResolution(Probe, 10); - delay(1000); - Serial.println(); - - Serial.print ("Number of Devices found on bus = "); - Serial.println (sensors.getDeviceCount()); - Serial.print ("Getting temperatures... "); - Serial.println (); - #endif - - #ifdef PZEM - Serial.println("-------PZEM-----------"); // Start Print Test to Line 2 - pzem.resetEnergy(); - delay(1000); - #endif + // Dimmer +#ifdef PIN_DIMMER_OUTPUT + server.on("/minus", minus); + server.on("/plus", plus); + server.on("/exact", exact); + server.on("/zero", stopPWM); +#endif + +#ifdef PIN_REGULATION + server.on("/minus_reg", minus_reg); + server.on("/plus_reg", plus_reg); + server.on("/exact_reg", exact_reg); + server.on("/zero_reg", stop_reg); +#endif + + //initialize variables__________________ + pwm = 0; + led = 0; + // Dimmer + Serial.println("Dimmer Program is starting..."); + delay(1000); +#ifdef PIN_DIMMER_OUTPUT + dimmer.begin(NORMAL_MODE, ON); //dimmer initialisation: name.begin(MODE, STATE) + Serial.println("Set value"); + dimmer.setState(ON_OFF_typedef::OFF); + dimmer.setPower(pwm); // setPower(0-100%); +#endif + + // Démarrer le serveur + server.begin(); + Serial.println("Serveur Web démarré"); + +#ifdef PIN_DALLAS + + sensors.begin (); // Initialize the sensor and set resolution level + sensors.setResolution(Probe, 10); + delay(1000); + Serial.println(); + + Serial.print ("Number of Devices found on bus = "); + Serial.println (sensors.getDeviceCount()); + Serial.print ("Getting temperatures... "); + Serial.println (); +#endif + +#ifdef PZEM + Serial.println("-------PZEM-----------"); // Start Print Test to Line 2 + pzem.resetEnergy(); + delay(1000); +#endif /////////////////////////////////// // UPDATE OTA @@ -529,10 +529,10 @@ void setup() { else if (error == OTA_END_ERROR) Serial.println("End Failed"); }); ArduinoOTA.begin(); - - // timer.start(); - slider_on = false; + // timer.start(); + + slider_on = false; } void loop() { @@ -555,17 +555,17 @@ void loop() { #ifdef SERIAL_XY6020L xy.task(); -// if(xy.HRegUpdated()) { -// double vIn = xy.getInV(); -// xy.setCV(500); -// } + // if(xy.HRegUpdated()) { + // double vIn = xy.getInV(); + // xy.setCV(500); + // } #endif #ifdef SERIAL_XY6020L_2 xy2.task(); -// if(xy.HRegUpdated()) { -// double vIn = xy.getInV(); -// xy.setCV(500); -// } + // if(xy.HRegUpdated()) { + // double vIn = xy.getInV(); + // xy.setCV(500); + // } #endif if (millis() - lastTimeRead >= analogReadInterval)//read ldr periodically @@ -574,11 +574,11 @@ void loop() { lastTimeRead = millis(); } - + if (millis() - lastUpdateTime >= updateInterval || lastUpdateTime == 0) { -// digitalWrite(PIN_LED, HIGH); -// delay(500); + // digitalWrite(PIN_LED, HIGH); + // delay(500); unsigned long currentMillis = millis(); time_t elapsedTime = (currentMillis - lastSyncMillis) / 1000; localTime = currentTime + elapsedTime; @@ -599,60 +599,60 @@ void loop() { cleanValues(); #endif -//#ifdef SERIAL_XY6020L -// printMem(); -//#endif -//#ifdef SERIAL_XY6020L_2 -// printMem(); -//#endif + //#ifdef SERIAL_XY6020L + // printMem(); + //#endif + //#ifdef SERIAL_XY6020L_2 + // printMem(); + //#endif // Mettre à jour le temps de la dernière mise à jour lastUpdateTime = millis(); #ifdef PIN_TENSION getTension(); #endif -// digitalWrite(PIN_LED, LOW); -// delay(500); + // digitalWrite(PIN_LED, LOW); + // delay(500); } -// /////////////////////////////////////////////////////////////// + // /////////////////////////////////////////////////////////////// -#ifdef SERIAL_XY6020L +#ifdef SERIAL_XY6020L #endif - -// ////////////////////////////////////////////////////////////// + + // ////////////////////////////////////////////////////////////// } void handleRoot() { -// IPAddress clientIP = server.client().remoteIP(); -// Serial.println("Client IP: " + clientIP.toString()); -// -// if (!isLocalIP(clientIP)) { -// // Vérifie si le mot de passe est correct -// if (server.hasArg("password")) { -// String passwordParam = server.arg("password"); -// if (passwordParam == adminPassword) { -// server.send(200, "text/html", "

Accès autorisé

"); -// } else { -// server.send(401, "text/html", "

Mot de passe incorrect

"); -// } -// } else { -// server.send(401, "text/html", "
" -// "
" -// "
" -// "" -// "
"); -// } -// return; -// } + // IPAddress clientIP = server.client().remoteIP(); + // Serial.println("Client IP: " + clientIP.toString()); + // + // if (!isLocalIP(clientIP)) { + // // Vérifie si le mot de passe est correct + // if (server.hasArg("password")) { + // String passwordParam = server.arg("password"); + // if (passwordParam == adminPassword) { + // server.send(200, "text/html", "

Accès autorisé

"); + // } else { + // server.send(401, "text/html", "

Mot de passe incorrect

"); + // } + // } else { + // server.send(401, "text/html", "
" + // "
" + // "
" + // "" + // "
"); + // } + // return; + // } -// bool connectionStatus = testDomoticzConnection(); -// String connectionIcon = connectionStatus -// ? "" -// : ""; + // bool connectionStatus = testDomoticzConnection(); + // String connectionIcon = connectionStatus + // ? "" + // : ""; #ifdef PIN_HALL getHall(); @@ -670,7 +670,7 @@ void handleRoot() { // Générer la page HTML avec CSS String html = ""; - + html += ""; html += ""; @@ -780,14 +780,14 @@ void handleRoot() { #ifdef TUYA - to_add.replace("@@VALUE@@", String(String(conso_apparente).toFloat(),1) + " W"); + to_add.replace("@@VALUE@@", String(String(conso_apparente).toFloat(), 1) + " W"); to_add.replace("@@LABEL@@", "Conso apparente"); to_add.replace("@@KEY@@", "IND_CONSO"); indicators += to_add; to_add = indicator; - to_add.replace("@@VALUE@@", String(String(production).toFloat(),1) + " W"); + to_add.replace("@@VALUE@@", String(String(production).toFloat(), 1) + " W"); to_add.replace("@@LABEL@@", "Production"); to_add.replace("@@KEY@@", "IND_PROD"); @@ -879,7 +879,7 @@ void handleRoot() { html += ""; //String response_items = ""; - + html += webpage; // response_items = "
"; @@ -945,19 +945,19 @@ void handleRoot() { server.send(200, "text/html", html); } -void handleStop() { +void handleStop() { Serial.println("Arrêt"); digitalWrite(PIN_INJECTION, LOW); - cc2 = 0; + cc2 = 0; cc = 0; setCC(xy, 0); - #ifdef SERIAL_XY6020L_2 - setCC2(xy2, 0); - #endif +#ifdef SERIAL_XY6020L_2 + setCC2(xy2, 0); +#endif delay(200); digitalWrite(PIN_CHARGE, LOW); delay(200); @@ -1001,37 +1001,37 @@ void handleStart() { } void injection() { - #ifdef PIN_DIMMER_OUTPUT - dimmer.setState(ON_OFF_typedef::OFF); - #endif - #ifdef PIN_POWER - digitalWrite(PIN_POWER, HIGH); - delay(200); - #endif - - #ifdef PIN_BATTERIE - digitalWrite(PIN_BATTERIE, HIGH); - delay(200); - #endif - - digitalWrite(PIN_CHARGE, LOW); - delay(200); - - Serial.println("injection"); - digitalWrite(PIN_INJECTION, HIGH); - delay(200); - - #ifdef PIN_BATTERIE - digitalWrite(PIN_BATTERIE, HIGH); - delay(200); - #endif - - #ifdef PIN_REGULATION - setReg(0); - #endif +#ifdef PIN_DIMMER_OUTPUT + dimmer.setState(ON_OFF_typedef::OFF); +#endif +#ifdef PIN_POWER + digitalWrite(PIN_POWER, HIGH); + delay(200); +#endif + +#ifdef PIN_BATTERIE + digitalWrite(PIN_BATTERIE, HIGH); + delay(200); +#endif + + digitalWrite(PIN_CHARGE, LOW); + delay(200); + + Serial.println("injection"); + digitalWrite(PIN_INJECTION, HIGH); + delay(200); + +#ifdef PIN_BATTERIE + digitalWrite(PIN_BATTERIE, HIGH); + delay(200); +#endif + +#ifdef PIN_REGULATION + setReg(0); +#endif } void handleInjection() { - + injection(); // Rediriger vers la page principale après le traitement blink(); server.sendHeader("Location", "/"); @@ -1040,7 +1040,7 @@ void handleInjection() { void stopInjection() { - #ifdef PIN_BATTERIE +#ifdef PIN_BATTERIE digitalWrite(PIN_BATTERIE, LOW); delay(200); #endif @@ -1060,7 +1060,7 @@ void handleStopInjection() { void charge() { - #ifdef PIN_DIMMER_OUTPUT +#ifdef PIN_DIMMER_OUTPUT dimmer.setState(ON_OFF_typedef::ON); #endif Serial.println("charge"); @@ -1090,7 +1090,7 @@ void handleCharge() { void stopCharge() { slider_on = false; - Serial.println("stop charge"); + Serial.println("stop charge"); #ifdef PIN_BATTERIE digitalWrite(PIN_BATTERIE, LOW); delay(200); @@ -1102,9 +1102,9 @@ void stopCharge() #ifdef PIN_REGULATION setReg(0); #endif - #ifdef SERIAL_XY6020L - setCC(xy, 0); - #endif +#ifdef SERIAL_XY6020L + setCC(xy, 0); +#endif } void handleStopCharge() { @@ -1169,8 +1169,8 @@ void handleData() { #ifdef SERIAL_BLUE_SOLAR - - //doc["INJECT"] = value[IL] / 1000 * value[V] / 1000; + + //doc["INJECT"] = value[IL] / 1000 * value[V] / 1000; //doc["last_serial_string"] = last_serial_string; for (int i = 0; i < num_keywords - 1; i++) { @@ -1195,28 +1195,28 @@ void handleData() { #endif #ifdef SERIAL_XY6020L - printMem(); - doc["XY_V"] = xy.getCV(); + printMem(); + doc["XY_V"] = xy.getCV(); doc["XY_C"] = xy.getCC(); - doc["CC"] = cc; - doc["XY_T"] = xy.getTemp(); - doc["XY_ON"] = xy.getOutputOn(); + doc["CC"] = cc; + doc["XY_T"] = xy.getTemp(); + doc["XY_ON"] = xy.getOutputOn(); doc["XY_AV"] = xy.getActV(); doc["XY_AC"] = xy.getActC(); - doc["XY_AW"] = xy.getActP(); + doc["XY_AW"] = xy.getActP(); #endif #ifdef SERIAL_XY6020L_2 - printMem2(); - doc["XY2_V"] = xy2.getCV(); + printMem2(); + doc["XY2_V"] = xy2.getCV(); doc["XY2_C"] = xy2.getCC(); - doc["CC2"] = cc2; + doc["CC2"] = cc2; - doc["XY2_T"] = xy2.getTemp(); - doc["XY2_ON"] = xy2.getOutputOn(); + doc["XY2_T"] = xy2.getTemp(); + doc["XY2_ON"] = xy2.getOutputOn(); doc["XY2_AV"] = xy2.getActV(); doc["XY2_AC"] = xy2.getActC(); doc["XY2_AW"] = xy2.getActP(); - + #endif @@ -1240,12 +1240,12 @@ void handleData() { #endif #ifdef TUYA - doc["CONSO"] = conso_apparente; - doc["PROD"] = production; + doc["CONSO"] = conso_apparente; + doc["PROD"] = production; #endif - doc["Message"] = last_message; + doc["Message"] = last_message; // Convertir l'objet JSON en chaîne String jsonData; serializeJson(doc, jsonData); diff --git a/ESP8266_BATTERIE_INJECTION/html.h b/ESP8266_BATTERIE_INJECTION/html.h index c5cfe5d..c642f8e 100644 --- a/ESP8266_BATTERIE_INJECTION/html.h +++ b/ESP8266_BATTERIE_INJECTION/html.h @@ -140,8 +140,6 @@ String to_include = R"=( table.deleteRow(-1); // Supprime la dernière ligne } - - if (field_chart && !chart) { var ctx = field_chart.getContext('2d'); chart = new Chart(ctx, { diff --git a/ESP8266_DIMMER/ESP8266_DIMMER.ino b/ESP8266_DIMMER/ESP8266_DIMMER.ino index 3e4921c..3f35ea2 100644 --- a/ESP8266_DIMMER/ESP8266_DIMMER.ino +++ b/ESP8266_DIMMER/ESP8266_DIMMER.ino @@ -22,6 +22,8 @@ ESP8266WebServer server(80); void ICACHE_RAM_ATTR handleInterrupt(); +#define HOSTNAME "ESP8266_RADIATEUR" + // Dimmer #include // @@ -30,11 +32,13 @@ void ICACHE_RAM_ATTR handleInterrupt(); #define zerocross 12 // D6 for boards with CHANGEBLE input pins #define pas 5 +bool led; +int pwm; +int pwmCount; + dimmerLamp dimmer(outputPin, zerocross); //initialase port for dimmer for ESP8266, ESP32, Arduino due boards //dimmerLamp dimmer(outputPin); //initialase port for dimmer for MEGA, Leonardo, UNO, Arduino M0, Arduino Zero -int outVal = 0; - String webpage = R"=( @@ -42,22 +46,61 @@ String webpage = R"=( LED Control + + - + +
+
+

Surplux solaire

+
+

@@IP@@

+ +
+ +
@@ -124,7 +221,6 @@ String webpage = R"=(
Minus -
@@ -132,28 +228,27 @@ String webpage = R"=(
-
@@pwmCount@@
+
@@pwmCount@@
+
)="; -bool led; -int pwm; -int pwmCount; -// -//void ledON(){ -// led=1; -// digitalWrite(LEDn, led); -// handleRoot(); -// -//} -// -//void ledOFF(){ -// led=0; -// digitalWrite(LEDn, led); -// handleRoot(); -//} + + +void ledON(){ + led=1; + digitalWrite(LEDn, led); + handleRoot(); + +} + +void ledOFF(){ + led=0; + digitalWrite(LEDn, led); + handleRoot(); +} //pwm functions - if pwm is set to 1/-1 it will in-/decrease pwmCounter in loop() @@ -222,6 +317,7 @@ void setPwm(int pwm) void handleRoot(void){ String page = webpage; page.replace("@@pwmCount@@", String(pwmCount)); + page.replace("@@IP@@", String(WiFi.localIP().toString())); //Serial.println(page); server.send(200, "text/html", page); } @@ -319,18 +415,27 @@ String generateKey() IPAddress getIP(String macId) { - IPAddress ip; //(192, 168, 1, 222); - - String fst = macId.substring(0, 2); - String sec = macId.substring(2); - - char fstc[fst.length() + 1]; - fst.toCharArray(fstc, fst.length() + 1); - - char secc[sec.length() + 1]; - sec.toCharArray(secc, fst.length() + 1); +// IPAddress ip (192, 168, 1, 222); +// +// String fst = macId.substring(0, 2); +// String sec = macId.substring(2); +// +// char fstc[fst.length() + 1]; +// fst.toCharArray(fstc, fst.length() + 1); +// +// char secc[sec.length() + 1]; +// sec.toCharArray(secc, fst.length() + 1); - return IPAddress(192, 168, strtol(fstc, 0, 16), strtol(secc, 0, 16)); + return IPAddress (192, 168, 1, 222); //IPAddress(192, 168, strtol(fstc, 0, 16), strtol(secc, 0, 16)); + +} + +void handleData() +{ + String JSON = F(""); + JSON += "{\"id\":\"current\", \"value\":" + String(pwmCount) + "}"; + JSON += ""; + server.send(200, "application/json", JSON); } @@ -355,6 +460,7 @@ void setup() server.on("/plus", plus); server.on("/exact", exact); server.on("/stop", stopPWM); + server.on("/getData", handleData); //initialize variables__________________ pwm = 0; pwmCount= 0; @@ -378,7 +484,7 @@ void setup() ArduinoOTA.setPort(8266); // Hostname defaults to esp8266-[ChipID] - // ArduinoOTA.setHostname("myesp8266"); + ArduinoOTA.setHostname(HOSTNAME); // No authentication by default // ArduinoOTA.setPassword("admin");