|
|
|
@ -217,6 +217,10 @@ bool loadAuthConfig() { |
|
|
|
if (doc["system"]["night_end_hour"]) { |
|
|
|
if (doc["system"]["night_end_hour"]) { |
|
|
|
nightEndHour = doc["system"]["night_end_hour"].as<int>(); |
|
|
|
nightEndHour = doc["system"]["night_end_hour"].as<int>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (doc["system"]["operating_mode"]) { |
|
|
|
|
|
|
|
operatingMode = doc["system"]["operating_mode"].as<int>(); |
|
|
|
|
|
|
|
Serial.printf("[CONFIG] Mode de fonctionnement chargé: %d\n", operatingMode); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Charger les paramètres Enphase si disponibles
|
|
|
|
// Charger les paramètres Enphase si disponibles
|
|
|
|
@ -496,8 +500,9 @@ void calculateHeaterPower() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Calculer l'excédent solaire et ajuster le pourcentage de chauffe
|
|
|
|
// Calculer l'excédent solaire et ajuster le pourcentage de chauffe
|
|
|
|
float solarExcess = solarProduction - powerConsumption; |
|
|
|
float solarExcess = 0; |
|
|
|
int calculatedHeaterPowerJour, calculatedHeaterPowerSoleil = 0; |
|
|
|
int calculatedHeaterPowerJour = 0; |
|
|
|
|
|
|
|
int calculatedHeaterPowerSoleil = 0; |
|
|
|
int calculatedHeaterPower = heaterPower; |
|
|
|
int calculatedHeaterPower = heaterPower; |
|
|
|
|
|
|
|
|
|
|
|
// Extraire les bits du mode
|
|
|
|
// Extraire les bits du mode
|
|
|
|
@ -572,6 +577,10 @@ void calculateHeaterPower() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (modeSOLEIL) { |
|
|
|
if (modeSOLEIL) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Calculer l'excédent solaire
|
|
|
|
|
|
|
|
solarExcess = solarProduction - powerConsumption; |
|
|
|
|
|
|
|
|
|
|
|
// Mode SOLEIL: ajuster selon l'excédent solaire
|
|
|
|
// Mode SOLEIL: ajuster selon l'excédent solaire
|
|
|
|
if (solarExcess > 0) { |
|
|
|
if (solarExcess > 0) { |
|
|
|
// Convertir l'excédent solaire en pourcentage (max = puissance max du chauffe-eau)
|
|
|
|
// Convertir l'excédent solaire en pourcentage (max = puissance max du chauffe-eau)
|
|
|
|
@ -785,6 +794,7 @@ void setup() { |
|
|
|
doc["system"]["longitude"] = longitude; |
|
|
|
doc["system"]["longitude"] = longitude; |
|
|
|
doc["system"]["night_start_hour"] = nightStartHour; |
|
|
|
doc["system"]["night_start_hour"] = nightStartHour; |
|
|
|
doc["system"]["night_end_hour"] = nightEndHour; |
|
|
|
doc["system"]["night_end_hour"] = nightEndHour; |
|
|
|
|
|
|
|
doc["system"]["operating_mode"] = operatingMode; |
|
|
|
doc["enphase"]["gateway_ip"] = enphaseGatewayIP; |
|
|
|
doc["enphase"]["gateway_ip"] = enphaseGatewayIP; |
|
|
|
doc["enphase"]["token"] = enphaseToken; |
|
|
|
doc["enphase"]["token"] = enphaseToken; |
|
|
|
doc["enphase"]["update_interval"] = enphaseUpdateInterval; |
|
|
|
doc["enphase"]["update_interval"] = enphaseUpdateInterval; |
|
|
|
@ -1088,6 +1098,11 @@ void setup() { |
|
|
|
doc["sunset_time"] = sunsetTime; |
|
|
|
doc["sunset_time"] = sunsetTime; |
|
|
|
doc["timestamp"] = millis(); |
|
|
|
doc["timestamp"] = millis(); |
|
|
|
doc["enphase_connection_error"] = enphaseConnectionError; |
|
|
|
doc["enphase_connection_error"] = enphaseConnectionError; |
|
|
|
|
|
|
|
doc["max_temp_reached_today"] = maxTempReachedToday; |
|
|
|
|
|
|
|
doc["night_start_hour"] = nightStartHour; |
|
|
|
|
|
|
|
doc["night_end_hour"] = nightEndHour; |
|
|
|
|
|
|
|
doc["min_water_temp"] = minWaterTemp; |
|
|
|
|
|
|
|
doc["max_water_temp"] = maxWaterTemp; |
|
|
|
String response; |
|
|
|
String response; |
|
|
|
serializeJson(doc, response); |
|
|
|
serializeJson(doc, response); |
|
|
|
request->send(200, "application/json", response); |
|
|
|
request->send(200, "application/json", response); |
|
|
|
@ -1220,6 +1235,25 @@ void setup() { |
|
|
|
if (newMode >= 0 && newMode <= 31) { |
|
|
|
if (newMode >= 0 && newMode <= 31) { |
|
|
|
operatingMode = newMode; |
|
|
|
operatingMode = newMode; |
|
|
|
Serial.printf("[MODE] Mode changé via GET: %d\n", operatingMode); |
|
|
|
Serial.printf("[MODE] Mode changé via GET: %d\n", operatingMode); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sauvegarder le mode dans la configuration
|
|
|
|
|
|
|
|
File configFile = LittleFS.open("/config.json", "r"); |
|
|
|
|
|
|
|
if (configFile) { |
|
|
|
|
|
|
|
JsonDocument configDoc; |
|
|
|
|
|
|
|
DeserializationError error = deserializeJson(configDoc, configFile); |
|
|
|
|
|
|
|
configFile.close(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!error) { |
|
|
|
|
|
|
|
configDoc["system"]["operating_mode"] = operatingMode; |
|
|
|
|
|
|
|
configFile = LittleFS.open("/config.json", "w"); |
|
|
|
|
|
|
|
if (configFile) { |
|
|
|
|
|
|
|
serializeJsonPretty(configDoc, configFile); |
|
|
|
|
|
|
|
configFile.close(); |
|
|
|
|
|
|
|
Serial.println("[MODE] Mode sauvegardé dans la configuration"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
request->send(200, "text/plain", "OK"); |
|
|
|
request->send(200, "text/plain", "OK"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
request->send(400, "text/plain", "Mode invalide (0-31)"); |
|
|
|
request->send(400, "text/plain", "Mode invalide (0-31)"); |
|
|
|
@ -1275,6 +1309,24 @@ void setup() { |
|
|
|
operatingMode = newMode; |
|
|
|
operatingMode = newMode; |
|
|
|
Serial.printf("[MODE] Mode changé: %d\n", operatingMode); |
|
|
|
Serial.printf("[MODE] Mode changé: %d\n", operatingMode); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sauvegarder le mode dans la configuration
|
|
|
|
|
|
|
|
File configFile = LittleFS.open("/config.json", "r"); |
|
|
|
|
|
|
|
if (configFile) { |
|
|
|
|
|
|
|
JsonDocument configDoc; |
|
|
|
|
|
|
|
DeserializationError error = deserializeJson(configDoc, configFile); |
|
|
|
|
|
|
|
configFile.close(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!error) { |
|
|
|
|
|
|
|
configDoc["system"]["operating_mode"] = operatingMode; |
|
|
|
|
|
|
|
configFile = LittleFS.open("/config.json", "w"); |
|
|
|
|
|
|
|
if (configFile) { |
|
|
|
|
|
|
|
serializeJsonPretty(configDoc, configFile); |
|
|
|
|
|
|
|
configFile.close(); |
|
|
|
|
|
|
|
Serial.println("[MODE] Mode sauvegardé dans la configuration"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
JsonDocument responseDoc; |
|
|
|
JsonDocument responseDoc; |
|
|
|
responseDoc["success"] = true; |
|
|
|
responseDoc["success"] = true; |
|
|
|
responseDoc["mode"] = operatingMode; |
|
|
|
responseDoc["mode"] = operatingMode; |
|
|
|
|