test commit après reinstall

This commit is contained in:
Jérôme Delacotte
2025-07-01 18:25:48 +02:00
parent 7b30d6e298
commit e3f9d88c42
3 changed files with 501 additions and 397 deletions

View File

@@ -38,26 +38,26 @@ const char* adminPassword = "setaou"; // Mot de passe pour la connexion
//#define PIN_DIMMER_OUTPUT 18 // D8 //#define PIN_DIMMER_OUTPUT 18 // D8
//#define PIN_DIMMER_ZEROCROSS 19 // 12 // D6 for boards with CHANGEBLE input pins //#define PIN_DIMMER_ZEROCROSS 19 // 12 // D6 for boards with CHANGEBLE input pins
#ifdef ESP8266 #ifdef ESP8266
#define PIN_SOFTWARE_SERIAL_RX D4 // GPIO2 #define PIN_SOFTWARE_SERIAL_RX D4 // GPIO2
#define PIN_SOFTWARE_SERIAL_TX D2 // GPIO4 #define PIN_SOFTWARE_SERIAL_TX D2 // GPIO4
#elif defined(ESP32) #elif defined(ESP32)
//#define PZEM true //#define PZEM true
#define PIN_LED 2 #define PIN_LED 2
#define SERIAL_BLUE_SOLAR true #define SERIAL_BLUE_SOLAR true
#define SERIAL_XY6020L true #define SERIAL_XY6020L true
//#define SERIAL_XY6020L_2 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 PIN_REGULATION 21
// #define PIN_DALLAS 26 // D5 #define PIN_SOFTWARE_SERIAL_RX 4
//#define PIN_HALL 33 #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 #endif
@@ -146,21 +146,21 @@ dimmerLamp dimmer(PIN_DIMMER_OUTPUT, PIN_DIMMER_ZEROCROSS); //initialase port fo
// DALLAS // DALLAS
///////////////////////////////////////// /////////////////////////////////////////
#ifdef PIN_DALLAS #ifdef PIN_DALLAS
float temperature = 0; float temperature = 0;
#include <OneWire.h> #include <OneWire.h>
#include <DallasTemperature.h> #include <DallasTemperature.h>
#define onewirepin PIN_DALLAS // DATA pin of DS18B20 wired to pin DALLAS of Arduino #define onewirepin PIN_DALLAS // DATA pin of DS18B20 wired to pin DALLAS of Arduino
OneWire oneWire(onewirepin); OneWire oneWire(onewirepin);
DallasTemperature sensors(&oneWire); DallasTemperature sensors(&oneWire);
// find the DeviceAddress of your DS18B20 with the sketch DS18B20_address_reporter // find the DeviceAddress of your DS18B20 with the sketch DS18B20_address_reporter
// then replace the 8-byte ID below with the reported one // then replace the 8-byte ID below with the reported one
DeviceAddress Probe = { 0x28, 0xFF, 0x61, 0x1D, 0x76, 0x04, 0x00, 0x34 }; DeviceAddress Probe = { 0x28, 0xFF, 0x61, 0x1D, 0x76, 0x04, 0x00, 0x34 };
float printTemperature(DeviceAddress deviceAddress); float printTemperature(DeviceAddress deviceAddress);
#endif #endif
void blink(); void blink();
@@ -216,26 +216,26 @@ unsigned long lastTimeRead = millis();
// PZEM for arduino // PZEM for arduino
// ----------------- // -----------------
#ifdef PZEM #ifdef PZEM
#include <PZEM004Tv30.h> #include <PZEM004Tv30.h>
#ifdef ESP8266 #ifdef ESP8266
#define PIN_PZEM_1 D5 #define PIN_PZEM_1 D5
#define PIN_PZEM_2 D6 #define PIN_PZEM_2 D6
PZEM004Tv30 pzem(PIN_PZEM_1, PIN_PZEM_2); PZEM004Tv30 pzem(PIN_PZEM_1, PIN_PZEM_2);
#elif defined(ESP32) #elif defined(ESP32)
#define RXD2 16 #define RXD2 16
#define TXD2 17 #define TXD2 17
PZEM004Tv30 pzem(&Serial2); PZEM004Tv30 pzem(&Serial2);
#endif #endif
double voltage; double voltage;
double current; double current;
double pf; double pf;
double power; double power;
double energy; double energy;
double frequency; double frequency;
#endif #endif
@@ -245,130 +245,130 @@ void setup() {
// initialize digital pin LED_BUILTIN as an output. // initialize digital pin LED_BUILTIN as an output.
Serial.begin(115200); Serial.begin(115200);
#ifdef PZEM #ifdef PZEM
#ifdef ESP32 #ifdef ESP32
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2); Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
#endif #endif
#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 SERIAL_XY6020L #ifdef PIN_TENSION
#ifdef ESP32 pinMode(PIN_TENSION, INPUT);
xy6020l xy(Serial2, 0x01, 50, XY6020_OPT_SKIP_SAME_HREG_VALUE | XY6020_OPT_NO_HREG_UPDATE); #endif
#ifdef PIN_HALL
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 pinMode(PIN_HALL, INPUT);
Serial.println("HardwareSerial (Serial) initialisé"); delay(200);
getHall();
#endif
#ifdef PIN_POWER
pinMode(PIN_POWER, OUTPUT);
#endif
#ifdef PIN_LED
pinMode(PIN_LED, OUTPUT);
#endif
// 12 V supply pinMode(PIN_INJECTION, OUTPUT);
Mem.Nr = MemIdx; pinMode(PIN_CHARGE, OUTPUT);
Mem.VSet = 0; // 10v #ifdef PIN_BATTERIE
Mem.ISet = 500; pinMode(PIN_BATTERIE, OUTPUT);
Mem.sLVP = 1000; #endif
Mem.sOVP = 1300; #ifdef PIN_REGULATION
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() ); #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); Serial.print(tmpBuf);
#endif #endif
#endif #endif
#ifdef SERIAL_XY6020L_2 #ifdef SERIAL_XY6020L_2
#ifdef ESP32 #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);
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); Serial.print(tmpBuf);
#endif #endif
#endif #endif
delay(10); delay(10);
@@ -377,7 +377,7 @@ void setup() {
// Connectez-vous au réseau WiFi // Connectez-vous au réseau WiFi
WiFi.begin(ssid, pass); WiFi.begin(ssid, pass);
Serial.println("Connexion au WiFi en cours."); Serial.println("Connexion au WiFi en cours.");
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
digitalWrite(PIN_LED, LOW); digitalWrite(PIN_LED, LOW);
delay(500); delay(500);
@@ -410,30 +410,30 @@ void setup() {
server.on("/save", HTTP_POST, handleSave); server.on("/save", HTTP_POST, handleSave);
//server.on("/test", HTTP_GET, handleTestConnection); //server.on("/test", HTTP_GET, handleTestConnection);
server.on("/slider", HTTP_POST, handleUpdate); server.on("/slider", HTTP_POST, handleUpdate);
#ifdef SERIAL_BLUE_SOLAR #ifdef SERIAL_BLUE_SOLAR
// Initialisation de l'EEPROM // Initialisation de l'EEPROM
EEPROM.begin(EEPROM_SIZE); //sizeof(To_Store) + sizeof(config)); EEPROM.begin(EEPROM_SIZE); //sizeof(To_Store) + sizeof(config));
// Lire la valeur stockée dans l'EEPROM // Lire la valeur stockée dans l'EEPROM
EEPROM.get(TO_STORE_ADDRESS, to_store); EEPROM.get(TO_STORE_ADDRESS, to_store);
// Lire la configuration // Lire la configuration
readConfiguration(); readConfiguration();
// initialize_arrays(); // initialize_arrays();
for (int i = 0; i < maxSize; i++) { for (int i = 0; i < maxSize; i++) {
if (to_store.tensions[i] > 30000 || to_store.tensions[i] < 10) { if (to_store.tensions[i] > 30000 || to_store.tensions[i] < 10) {
to_store.tensions[i] = 26000; to_store.tensions[i] = 26000;
}
// to_store.hour[i] = 0;
// to_store.min[i] = 0;
} }
if (to_store.total_elements > maxSize) { // to_store.hour[i] = 0;
to_store.total_elements = 0; // to_store.min[i] = 0;
} }
if (to_store.total_elements > maxSize) {
#endif to_store.total_elements = 0;
}
#endif
configTime(0, 0, "pool.ntp.org", "time.nist.gov"); configTime(0, 0, "pool.ntp.org", "time.nist.gov");
// Synchronize time // Synchronize time
@@ -443,56 +443,56 @@ void setup() {
time(&currentTime); time(&currentTime);
lastSyncMillis = millis(); lastSyncMillis = millis();
// Dimmer // Dimmer
#ifdef PIN_DIMMER_OUTPUT #ifdef PIN_DIMMER_OUTPUT
server.on("/minus", minus); server.on("/minus", minus);
server.on("/plus", plus); server.on("/plus", plus);
server.on("/exact", exact); server.on("/exact", exact);
server.on("/zero", stopPWM); server.on("/zero", stopPWM);
#endif #endif
#ifdef PIN_REGULATION #ifdef PIN_REGULATION
server.on("/minus_reg", minus_reg); server.on("/minus_reg", minus_reg);
server.on("/plus_reg", plus_reg); server.on("/plus_reg", plus_reg);
server.on("/exact_reg", exact_reg); server.on("/exact_reg", exact_reg);
server.on("/zero_reg", stop_reg); server.on("/zero_reg", stop_reg);
#endif #endif
//initialize variables__________________ //initialize variables__________________
pwm = 0; pwm = 0;
led = 0; led = 0;
// Dimmer // Dimmer
Serial.println("Dimmer Program is starting..."); Serial.println("Dimmer Program is starting...");
delay(1000); delay(1000);
#ifdef PIN_DIMMER_OUTPUT #ifdef PIN_DIMMER_OUTPUT
dimmer.begin(NORMAL_MODE, ON); //dimmer initialisation: name.begin(MODE, STATE) dimmer.begin(NORMAL_MODE, ON); //dimmer initialisation: name.begin(MODE, STATE)
Serial.println("Set value"); Serial.println("Set value");
dimmer.setState(ON_OFF_typedef::OFF); dimmer.setState(ON_OFF_typedef::OFF);
dimmer.setPower(pwm); // setPower(0-100%); dimmer.setPower(pwm); // setPower(0-100%);
#endif #endif
// Démarrer le serveur // Démarrer le serveur
server.begin(); server.begin();
Serial.println("Serveur Web démarré"); Serial.println("Serveur Web démarré");
#ifdef PIN_DALLAS #ifdef PIN_DALLAS
sensors.begin (); // Initialize the sensor and set resolution level sensors.begin (); // Initialize the sensor and set resolution level
sensors.setResolution(Probe, 10); sensors.setResolution(Probe, 10);
delay(1000); delay(1000);
Serial.println(); Serial.println();
Serial.print ("Number of Devices found on bus = "); Serial.print ("Number of Devices found on bus = ");
Serial.println (sensors.getDeviceCount()); Serial.println (sensors.getDeviceCount());
Serial.print ("Getting temperatures... "); Serial.print ("Getting temperatures... ");
Serial.println (); Serial.println ();
#endif #endif
#ifdef PZEM #ifdef PZEM
Serial.println("-------PZEM-----------"); // Start Print Test to Line 2 Serial.println("-------PZEM-----------"); // Start Print Test to Line 2
pzem.resetEnergy(); pzem.resetEnergy();
delay(1000); delay(1000);
#endif #endif
/////////////////////////////////// ///////////////////////////////////
// UPDATE OTA // UPDATE OTA
@@ -529,10 +529,10 @@ void setup() {
else if (error == OTA_END_ERROR) Serial.println("End Failed"); else if (error == OTA_END_ERROR) Serial.println("End Failed");
}); });
ArduinoOTA.begin(); ArduinoOTA.begin();
// timer.start();
slider_on = false; // timer.start();
slider_on = false;
} }
void loop() { void loop() {
@@ -555,17 +555,17 @@ void loop() {
#ifdef SERIAL_XY6020L #ifdef SERIAL_XY6020L
xy.task(); xy.task();
// if(xy.HRegUpdated()) { // if(xy.HRegUpdated()) {
// double vIn = xy.getInV(); // double vIn = xy.getInV();
// xy.setCV(500); // xy.setCV(500);
// } // }
#endif #endif
#ifdef SERIAL_XY6020L_2 #ifdef SERIAL_XY6020L_2
xy2.task(); xy2.task();
// if(xy.HRegUpdated()) { // if(xy.HRegUpdated()) {
// double vIn = xy.getInV(); // double vIn = xy.getInV();
// xy.setCV(500); // xy.setCV(500);
// } // }
#endif #endif
if (millis() - lastTimeRead >= analogReadInterval)//read ldr periodically if (millis() - lastTimeRead >= analogReadInterval)//read ldr periodically
@@ -574,11 +574,11 @@ void loop() {
lastTimeRead = millis(); lastTimeRead = millis();
} }
if (millis() - lastUpdateTime >= updateInterval || lastUpdateTime == 0) { if (millis() - lastUpdateTime >= updateInterval || lastUpdateTime == 0) {
// digitalWrite(PIN_LED, HIGH); // digitalWrite(PIN_LED, HIGH);
// delay(500); // delay(500);
unsigned long currentMillis = millis(); unsigned long currentMillis = millis();
time_t elapsedTime = (currentMillis - lastSyncMillis) / 1000; time_t elapsedTime = (currentMillis - lastSyncMillis) / 1000;
localTime = currentTime + elapsedTime; localTime = currentTime + elapsedTime;
@@ -599,60 +599,60 @@ void loop() {
cleanValues(); cleanValues();
#endif #endif
//#ifdef SERIAL_XY6020L //#ifdef SERIAL_XY6020L
// printMem(); // printMem();
//#endif //#endif
//#ifdef SERIAL_XY6020L_2 //#ifdef SERIAL_XY6020L_2
// printMem(); // printMem();
//#endif //#endif
// Mettre à jour le temps de la dernière mise à jour // Mettre à jour le temps de la dernière mise à jour
lastUpdateTime = millis(); lastUpdateTime = millis();
#ifdef PIN_TENSION #ifdef PIN_TENSION
getTension(); getTension();
#endif #endif
// digitalWrite(PIN_LED, LOW); // digitalWrite(PIN_LED, LOW);
// delay(500); // delay(500);
} }
// /////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////
#ifdef SERIAL_XY6020L #ifdef SERIAL_XY6020L
#endif #endif
// ////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////
} }
void handleRoot() { void handleRoot() {
// IPAddress clientIP = server.client().remoteIP(); // IPAddress clientIP = server.client().remoteIP();
// Serial.println("Client IP: " + clientIP.toString()); // Serial.println("Client IP: " + clientIP.toString());
// //
// if (!isLocalIP(clientIP)) { // if (!isLocalIP(clientIP)) {
// // Vérifie si le mot de passe est correct // // Vérifie si le mot de passe est correct
// if (server.hasArg("password")) { // if (server.hasArg("password")) {
// String passwordParam = server.arg("password"); // String passwordParam = server.arg("password");
// if (passwordParam == adminPassword) { // if (passwordParam == adminPassword) {
// server.send(200, "text/html", "<h1>Accès autorisé</h1>"); // server.send(200, "text/html", "<h1>Accès autorisé</h1>");
// } else { // } else {
// server.send(401, "text/html", "<h1>Mot de passe incorrect</h1>"); // server.send(401, "text/html", "<h1>Mot de passe incorrect</h1>");
// } // }
// } else { // } else {
// server.send(401, "text/html", "<form action='/' method='get'>" // server.send(401, "text/html", "<form action='/' method='get'>"
// "<label for='password'>Mot de passe:</label><br>" // "<label for='password'>Mot de passe:</label><br>"
// "<input type='password' id='password' name='password'><br>" // "<input type='password' id='password' name='password'><br>"
// "<input type='submit' value='Se connecter'>" // "<input type='submit' value='Se connecter'>"
// "</form>"); // "</form>");
// } // }
// return; // return;
// } // }
// bool connectionStatus = testDomoticzConnection(); // bool connectionStatus = testDomoticzConnection();
// String connectionIcon = connectionStatus // String connectionIcon = connectionStatus
// ? "<i class='fas fa-check-circle' style='color: green;'></i>" // ? "<i class='fas fa-check-circle' style='color: green;'></i>"
// : "<i class='fas fa-times-circle' style='color: red;'></i>"; // : "<i class='fas fa-times-circle' style='color: red;'></i>";
#ifdef PIN_HALL #ifdef PIN_HALL
getHall(); getHall();
@@ -670,7 +670,7 @@ void handleRoot() {
// Générer la page HTML avec CSS // Générer la page HTML avec CSS
String html = "<!DOCTYPE html><html><head>"; String html = "<!DOCTYPE html><html><head>";
html += "<link rel='icon' type='image/svg+xml' href='data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj4KICAgIDxyZWN0IHgxPSIyMCIgeTE9IjMwIiB3aWR0aD0iNjAiIGhlaWdodD0iNDAiIHJ4PSI1IiByeT0iNSIgZmlsbD0iIzRBQ0Y1MCIgc3Ryb2tlPSIjMzMzIiBzdHJva2Utd2lkdGg9IjMiLz4KICAgIDxyZWN0IHgxPSI0NSIgeTE9IjIwIiB3aWR0aD0iMTAiIGhlaWdodD0iMTAiIGZpbGw9IiMzMzMiLz4KICAgIDxjaXJjbGUgY3g9IjUwIiBjeT0iNTAiIHI9IjEwIiBmaWxsPSIjRkZENzAwIiBzdHJva2U9IiMzMzMiIHN0cm9rZS13aWR0aD0iMiIvPgo8L3N2Zz4=' />"; html += "<link rel='icon' type='image/svg+xml' href='data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj4KICAgIDxyZWN0IHgxPSIyMCIgeTE9IjMwIiB3aWR0aD0iNjAiIGhlaWdodD0iNDAiIHJ4PSI1IiByeT0iNSIgZmlsbD0iIzRBQ0Y1MCIgc3Ryb2tlPSIjMzMzIiBzdHJva2Utd2lkdGg9IjMiLz4KICAgIDxyZWN0IHgxPSI0NSIgeTE9IjIwIiB3aWR0aD0iMTAiIGhlaWdodD0iMTAiIGZpbGw9IiMzMzMiLz4KICAgIDxjaXJjbGUgY3g9IjUwIiBjeT0iNTAiIHI9IjEwIiBmaWxsPSIjRkZENzAwIiBzdHJva2U9IiMzMzMiIHN0cm9rZS13aWR0aD0iMiIvPgo8L3N2Zz4=' />";
html += "<meta charset='UTF-8'>"; html += "<meta charset='UTF-8'>";
@@ -780,14 +780,14 @@ void handleRoot() {
#ifdef TUYA #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("@@LABEL@@", "Conso apparente");
to_add.replace("@@KEY@@", "IND_CONSO"); to_add.replace("@@KEY@@", "IND_CONSO");
indicators += to_add; indicators += to_add;
to_add = indicator; 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("@@LABEL@@", "Production");
to_add.replace("@@KEY@@", "IND_PROD"); to_add.replace("@@KEY@@", "IND_PROD");
@@ -879,7 +879,7 @@ void handleRoot() {
html += "</ul>"; html += "</ul>";
//String response_items = ""; //String response_items = "";
html += webpage; html += webpage;
// response_items = "<div class='victron_data'><span><A id='response_items'></A></span></div>"; // response_items = "<div class='victron_data'><span><A id='response_items'></A></span></div>";
@@ -945,19 +945,19 @@ void handleRoot() {
server.send(200, "text/html", html); server.send(200, "text/html", html);
} }
void handleStop() { void handleStop() {
Serial.println("Arrêt"); Serial.println("Arrêt");
digitalWrite(PIN_INJECTION, LOW); digitalWrite(PIN_INJECTION, LOW);
cc2 = 0; cc2 = 0;
cc = 0; cc = 0;
setCC(xy, 0); setCC(xy, 0);
#ifdef SERIAL_XY6020L_2 #ifdef SERIAL_XY6020L_2
setCC2(xy2, 0); setCC2(xy2, 0);
#endif #endif
delay(200); delay(200);
digitalWrite(PIN_CHARGE, LOW); digitalWrite(PIN_CHARGE, LOW);
delay(200); delay(200);
@@ -1001,37 +1001,37 @@ void handleStart() {
} }
void injection() { void injection() {
#ifdef PIN_DIMMER_OUTPUT #ifdef PIN_DIMMER_OUTPUT
dimmer.setState(ON_OFF_typedef::OFF); dimmer.setState(ON_OFF_typedef::OFF);
#endif #endif
#ifdef PIN_POWER #ifdef PIN_POWER
digitalWrite(PIN_POWER, HIGH); digitalWrite(PIN_POWER, HIGH);
delay(200); delay(200);
#endif #endif
#ifdef PIN_BATTERIE #ifdef PIN_BATTERIE
digitalWrite(PIN_BATTERIE, HIGH); digitalWrite(PIN_BATTERIE, HIGH);
delay(200); delay(200);
#endif #endif
digitalWrite(PIN_CHARGE, LOW); digitalWrite(PIN_CHARGE, LOW);
delay(200); delay(200);
Serial.println("injection"); Serial.println("injection");
digitalWrite(PIN_INJECTION, HIGH); digitalWrite(PIN_INJECTION, HIGH);
delay(200); delay(200);
#ifdef PIN_BATTERIE #ifdef PIN_BATTERIE
digitalWrite(PIN_BATTERIE, HIGH); digitalWrite(PIN_BATTERIE, HIGH);
delay(200); delay(200);
#endif #endif
#ifdef PIN_REGULATION #ifdef PIN_REGULATION
setReg(0); setReg(0);
#endif #endif
} }
void handleInjection() { void handleInjection() {
injection(); injection();
// Rediriger vers la page principale après le traitement // Rediriger vers la page principale après le traitement
blink(); server.sendHeader("Location", "/"); blink(); server.sendHeader("Location", "/");
@@ -1040,7 +1040,7 @@ void handleInjection() {
void stopInjection() void stopInjection()
{ {
#ifdef PIN_BATTERIE #ifdef PIN_BATTERIE
digitalWrite(PIN_BATTERIE, LOW); digitalWrite(PIN_BATTERIE, LOW);
delay(200); delay(200);
#endif #endif
@@ -1060,7 +1060,7 @@ void handleStopInjection() {
void charge() void charge()
{ {
#ifdef PIN_DIMMER_OUTPUT #ifdef PIN_DIMMER_OUTPUT
dimmer.setState(ON_OFF_typedef::ON); dimmer.setState(ON_OFF_typedef::ON);
#endif #endif
Serial.println("charge"); Serial.println("charge");
@@ -1090,7 +1090,7 @@ void handleCharge() {
void stopCharge() void stopCharge()
{ {
slider_on = false; slider_on = false;
Serial.println("stop charge"); Serial.println("stop charge");
#ifdef PIN_BATTERIE #ifdef PIN_BATTERIE
digitalWrite(PIN_BATTERIE, LOW); digitalWrite(PIN_BATTERIE, LOW);
delay(200); delay(200);
@@ -1102,9 +1102,9 @@ void stopCharge()
#ifdef PIN_REGULATION #ifdef PIN_REGULATION
setReg(0); setReg(0);
#endif #endif
#ifdef SERIAL_XY6020L #ifdef SERIAL_XY6020L
setCC(xy, 0); setCC(xy, 0);
#endif #endif
} }
void handleStopCharge() { void handleStopCharge() {
@@ -1169,8 +1169,8 @@ void handleData() {
#ifdef SERIAL_BLUE_SOLAR #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; //doc["last_serial_string"] = last_serial_string;
for (int i = 0; i < num_keywords - 1; i++) { for (int i = 0; i < num_keywords - 1; i++) {
@@ -1195,28 +1195,28 @@ void handleData() {
#endif #endif
#ifdef SERIAL_XY6020L #ifdef SERIAL_XY6020L
printMem(); printMem();
doc["XY_V"] = xy.getCV(); doc["XY_V"] = xy.getCV();
doc["XY_C"] = xy.getCC(); doc["XY_C"] = xy.getCC();
doc["CC"] = cc; doc["CC"] = cc;
doc["XY_T"] = xy.getTemp(); doc["XY_T"] = xy.getTemp();
doc["XY_ON"] = xy.getOutputOn(); doc["XY_ON"] = xy.getOutputOn();
doc["XY_AV"] = xy.getActV(); doc["XY_AV"] = xy.getActV();
doc["XY_AC"] = xy.getActC(); doc["XY_AC"] = xy.getActC();
doc["XY_AW"] = xy.getActP(); doc["XY_AW"] = xy.getActP();
#endif #endif
#ifdef SERIAL_XY6020L_2 #ifdef SERIAL_XY6020L_2
printMem2(); printMem2();
doc["XY2_V"] = xy2.getCV(); doc["XY2_V"] = xy2.getCV();
doc["XY2_C"] = xy2.getCC(); doc["XY2_C"] = xy2.getCC();
doc["CC2"] = cc2; doc["CC2"] = cc2;
doc["XY2_T"] = xy2.getTemp(); doc["XY2_T"] = xy2.getTemp();
doc["XY2_ON"] = xy2.getOutputOn(); doc["XY2_ON"] = xy2.getOutputOn();
doc["XY2_AV"] = xy2.getActV(); doc["XY2_AV"] = xy2.getActV();
doc["XY2_AC"] = xy2.getActC(); doc["XY2_AC"] = xy2.getActC();
doc["XY2_AW"] = xy2.getActP(); doc["XY2_AW"] = xy2.getActP();
#endif #endif
@@ -1240,12 +1240,12 @@ void handleData() {
#endif #endif
#ifdef TUYA #ifdef TUYA
doc["CONSO"] = conso_apparente; doc["CONSO"] = conso_apparente;
doc["PROD"] = production; doc["PROD"] = production;
#endif #endif
doc["Message"] = last_message; doc["Message"] = last_message;
// Convertir l'objet JSON en chaîne // Convertir l'objet JSON en chaîne
String jsonData; String jsonData;
serializeJson(doc, jsonData); serializeJson(doc, jsonData);

View File

@@ -140,8 +140,6 @@ String to_include = R"=(
table.deleteRow(-1); // Supprime la dernière ligne table.deleteRow(-1); // Supprime la dernière ligne
} }
if (field_chart && !chart) { if (field_chart && !chart) {
var ctx = field_chart.getContext('2d'); var ctx = field_chart.getContext('2d');
chart = new Chart(ctx, { chart = new Chart(ctx, {

View File

@@ -22,6 +22,8 @@ ESP8266WebServer server(80);
void ICACHE_RAM_ATTR handleInterrupt(); void ICACHE_RAM_ATTR handleInterrupt();
#define HOSTNAME "ESP8266_RADIATEUR"
// Dimmer // Dimmer
#include <RBDdimmer.h>// #include <RBDdimmer.h>//
@@ -30,11 +32,13 @@ void ICACHE_RAM_ATTR handleInterrupt();
#define zerocross 12 // D6 for boards with CHANGEBLE input pins #define zerocross 12 // D6 for boards with CHANGEBLE input pins
#define pas 5 #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, 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 //dimmerLamp dimmer(outputPin); //initialase port for dimmer for MEGA, Leonardo, UNO, Arduino M0, Arduino Zero
int outVal = 0;
String webpage = R"=( String webpage = R"=(
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
@@ -42,22 +46,61 @@ String webpage = R"=(
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LED Control</title> <title>LED Control</title>
<link type='text/css' rel='stylesheet' href='http://192.168.1.3:81/velux/style.css'>
<script>
var xmlHttp01=createXmlHttpObject();
var previous_value = 10;
function createXmlHttpObject(){
if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}else{
xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
}
return xmlHttp;
}
function process(){
if(xmlHttp01.readyState==0 || xmlHttp01.readyState==4){
xmlHttp01.open('GET','getData',true);
xmlHttp01.onreadystatechange=handleServerResponse;
xmlHttp01.send(null);
}
setTimeout('process()', 30000);
}
function handleServerResponse(){
var field = document.getElementById('current_value');
if(field && xmlHttp01.readyState == 4 && xmlHttp01.status == 200){
const json_obj = JSON.parse(xmlHttp01.response);
// console.log(xmlHttp01.response);
const values = Object.values(json_obj);
var value = values[1]
if (value != previous_value) {
let button = document.querySelector('.arcade-button');
button.classList.add('gradient'); // Ajoute l'effet
setTimeout(() => button.classList.remove('gradient'), 3000);
previous_value = value;
}
field.textContent = value
}
}
</script>
<style> <style>
body { body {
align-content: center;
background-color: #3498db;
color: white;
display: flex;
font-family: 'Arial', sans-serif; font-family: 'Arial', sans-serif;
background-color: #f2f2f2;
margin: 0; margin: 0;
padding: 0; padding: 0;
display: flex;
flex-wrap: wrap; flex-wrap: wrap;
justify-content: space-around; justify-content: space-around;
align-items: center; align-items: center;
height: 100vh; width: 300px;
} }
.control-container { .control-container {
background: #C0C0C0; background: #66cc66;
width: 128px; width: 256px;
height: 64px; height: 64px;
margin: 10px; margin: 10px;
display: flex; display: flex;
@@ -90,7 +133,7 @@ String webpage = R"=(
position: relative; position: relative;
width: 150px; width: 150px;
height: 150px; height: 150px;
background-color: #3498db; background-color: #005599;
border: 10px solid #2c3e50; border: 10px solid #2c3e50;
border-radius: 50%; border-radius: 50%;
overflow: hidden; overflow: hidden;
@@ -102,6 +145,29 @@ String webpage = R"=(
background-color: #2980b9; background-color: #2980b9;
} }
.container {
display: flex;
flex-direction: column;
width: 100%;
align-content: center;
align-items: center;
}
header {
background-color: #003366;
padding: 1rem;
text-align: center;
}
.header_info {
display: flex;
}
.header_info h2 {
margin: 0 10px;
}
h1, h2 {
color: white;
margin: 0;
}
.button-content { .button-content {
position: absolute; position: absolute;
top: 50%; top: 50%;
@@ -111,9 +177,40 @@ String webpage = R"=(
font-size: 1.5rem; font-size: 1.5rem;
text-align: center; text-align: center;
} }
/* Effet Flash */
.arcade-button.flash {
animation: flash 0.3s;
}
@keyframes flash {
0% { background-color: #005599; }
50% { background-color: red; }
100% { background-color: #005599; }
}
/* Animation fluide entre rouge et orange */
@keyframes smoothGradient {
0% { background-color: #005599; }
50% { background-color: orange; }
100% { background-color: #005599; }
}
.arcade-button.gradient {
animation: smoothGradient 3s ease-in-out; /* Durée ajustable */
}
</style> </style>
</head> </head>
<body> <body onload='process()'>
<div class="container">
<header>
<h1>Surplux solaire</h1>
<div class="header_info">
<h2>@@IP@@</h2>
</div>
</header>
<div class="control-container" id="LEDn"> <div class="control-container" id="LEDn">
<button onclick="alert('on');">ON</button> <button onclick="alert('on');">ON</button>
</div> </div>
@@ -124,7 +221,6 @@ String webpage = R"=(
<div class="control-container" id="pwmminus"> <div class="control-container" id="pwmminus">
<a href="/minus?value=10">Minus</a> <a href="/minus?value=10">Minus</a>
</div> </div>
<div class="control-container" id="pwmstop"> <div class="control-container" id="pwmstop">
@@ -132,28 +228,27 @@ String webpage = R"=(
</div> </div>
<div class="arcade-button"> <div class="arcade-button">
<div class="button-content">@@pwmCount@@</div> <div class="button-content" id='current_value'>@@pwmCount@@</div>
</div> </div>
</div>
</body> </body>
</html> </html>
)="; )=";
bool led;
int pwm;
int pwmCount; void ledON(){
// led=1;
//void ledON(){ digitalWrite(LEDn, led);
// led=1; handleRoot();
// digitalWrite(LEDn, led);
// handleRoot(); }
//
//} void ledOFF(){
// led=0;
//void ledOFF(){ digitalWrite(LEDn, led);
// led=0; handleRoot();
// digitalWrite(LEDn, led); }
// handleRoot();
//}
//pwm functions - if pwm is set to 1/-1 it will in-/decrease pwmCounter in loop() //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){ void handleRoot(void){
String page = webpage; String page = webpage;
page.replace("@@pwmCount@@", String(pwmCount)); page.replace("@@pwmCount@@", String(pwmCount));
page.replace("@@IP@@", String(WiFi.localIP().toString()));
//Serial.println(page); //Serial.println(page);
server.send(200, "text/html", page); server.send(200, "text/html", page);
} }
@@ -319,18 +415,27 @@ String generateKey()
IPAddress getIP(String macId) IPAddress getIP(String macId)
{ {
IPAddress ip; //(192, 168, 1, 222); // IPAddress ip (192, 168, 1, 222);
//
String fst = macId.substring(0, 2); // String fst = macId.substring(0, 2);
String sec = macId.substring(2); // String sec = macId.substring(2);
//
char fstc[fst.length() + 1]; // char fstc[fst.length() + 1];
fst.toCharArray(fstc, fst.length() + 1); // fst.toCharArray(fstc, fst.length() + 1);
//
char secc[sec.length() + 1]; // char secc[sec.length() + 1];
sec.toCharArray(secc, fst.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("/plus", plus);
server.on("/exact", exact); server.on("/exact", exact);
server.on("/stop", stopPWM); server.on("/stop", stopPWM);
server.on("/getData", handleData);
//initialize variables__________________ //initialize variables__________________
pwm = 0; pwm = 0;
pwmCount= 0; pwmCount= 0;
@@ -378,7 +484,7 @@ void setup()
ArduinoOTA.setPort(8266); ArduinoOTA.setPort(8266);
// Hostname defaults to esp8266-[ChipID] // Hostname defaults to esp8266-[ChipID]
// ArduinoOTA.setHostname("myesp8266"); ArduinoOTA.setHostname(HOSTNAME);
// No authentication by default // No authentication by default
// ArduinoOTA.setPassword("admin"); // ArduinoOTA.setPassword("admin");