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_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 <OneWire.h>
#include <DallasTemperature.h>
#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 <OneWire.h>
#include <DallasTemperature.h>
#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 <PZEM004Tv30.h>
#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 <PZEM004Tv30.h>
#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(&currentTime);
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", "<h1>Accès autorisé</h1>");
// } else {
// server.send(401, "text/html", "<h1>Mot de passe incorrect</h1>");
// }
// } else {
// server.send(401, "text/html", "<form action='/' method='get'>"
// "<label for='password'>Mot de passe:</label><br>"
// "<input type='password' id='password' name='password'><br>"
// "<input type='submit' value='Se connecter'>"
// "</form>");
// }
// 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", "<h1>Accès autorisé</h1>");
// } else {
// server.send(401, "text/html", "<h1>Mot de passe incorrect</h1>");
// }
// } else {
// server.send(401, "text/html", "<form action='/' method='get'>"
// "<label for='password'>Mot de passe:</label><br>"
// "<input type='password' id='password' name='password'><br>"
// "<input type='submit' value='Se connecter'>"
// "</form>");
// }
// return;
// }
// bool connectionStatus = testDomoticzConnection();
// String connectionIcon = connectionStatus
// ? "<i class='fas fa-check-circle' style='color: green;'></i>"
// : "<i class='fas fa-times-circle' style='color: red;'></i>";
// bool connectionStatus = testDomoticzConnection();
// String connectionIcon = connectionStatus
// ? "<i class='fas fa-check-circle' style='color: green;'></i>"
// : "<i class='fas fa-times-circle' style='color: red;'></i>";
#ifdef PIN_HALL
getHall();
@@ -670,7 +670,7 @@ void handleRoot() {
// Générer la page HTML avec CSS
String html = "<!DOCTYPE html><html><head>";
html += "<link rel='icon' type='image/svg+xml' href='data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj4KICAgIDxyZWN0IHgxPSIyMCIgeTE9IjMwIiB3aWR0aD0iNjAiIGhlaWdodD0iNDAiIHJ4PSI1IiByeT0iNSIgZmlsbD0iIzRBQ0Y1MCIgc3Ryb2tlPSIjMzMzIiBzdHJva2Utd2lkdGg9IjMiLz4KICAgIDxyZWN0IHgxPSI0NSIgeTE9IjIwIiB3aWR0aD0iMTAiIGhlaWdodD0iMTAiIGZpbGw9IiMzMzMiLz4KICAgIDxjaXJjbGUgY3g9IjUwIiBjeT0iNTAiIHI9IjEwIiBmaWxsPSIjRkZENzAwIiBzdHJva2U9IiMzMzMiIHN0cm9rZS13aWR0aD0iMiIvPgo8L3N2Zz4=' />";
html += "<meta charset='UTF-8'>";
@@ -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 += "</ul>";
//String response_items = "";
html += webpage;
// 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);
}
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);

View File

@@ -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, {

View File

@@ -22,6 +22,8 @@ ESP8266WebServer server(80);
void ICACHE_RAM_ATTR handleInterrupt();
#define HOSTNAME "ESP8266_RADIATEUR"
// Dimmer
#include <RBDdimmer.h>//
@@ -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"=(
<!DOCTYPE html>
<html lang="en">
@@ -42,22 +46,61 @@ String webpage = R"=(
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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>
body {
align-content: center;
background-color: #3498db;
color: white;
display: flex;
font-family: 'Arial', sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
align-items: center;
height: 100vh;
width: 300px;
}
.control-container {
background: #C0C0C0;
width: 128px;
background: #66cc66;
width: 256px;
height: 64px;
margin: 10px;
display: flex;
@@ -90,7 +133,7 @@ String webpage = R"=(
position: relative;
width: 150px;
height: 150px;
background-color: #3498db;
background-color: #005599;
border: 10px solid #2c3e50;
border-radius: 50%;
overflow: hidden;
@@ -102,6 +145,29 @@ String webpage = R"=(
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 {
position: absolute;
top: 50%;
@@ -111,9 +177,40 @@ String webpage = R"=(
font-size: 1.5rem;
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>
</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">
<button onclick="alert('on');">ON</button>
</div>
@@ -124,7 +221,6 @@ String webpage = R"=(
<div class="control-container" id="pwmminus">
<a href="/minus?value=10">Minus</a>
</div>
<div class="control-container" id="pwmstop">
@@ -132,28 +228,27 @@ String webpage = R"=(
</div>
<div class="arcade-button">
<div class="button-content">@@pwmCount@@</div>
<div class="button-content" id='current_value'>@@pwmCount@@</div>
</div>
</div>
</body>
</html>
)=";
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");