first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

View File

@@ -0,0 +1,174 @@
struct DomoticzConfig {
char domoticz_ip[40];
char domoticz_port[6]; // 5 Caractères + \0
char domoticz_user[32];
char domoticz_password[32];
};
DomoticzConfig config;
struct To_Store {
int total_elements;
int hour[maxSize];
int min[maxSize];
int tensions[maxSize];
};
To_Store to_store;
void handleSettings() {
String html = "<html>\
<body>\
<h2>Domoticz Configuration</h2>\
<form action=\"/save\" method=\"POST\">\
<label for=\"domoticz_ip\">Domoticz IP:</label><br>\
<input type=\"text\" id=\"domoticz_ip\" name=\"domoticz_ip\" value=\"" + String(config.domoticz_ip) + "\"><br>\
<label for=\"domoticz_port\">Domoticz Port:</label><br>\
<input type=\"text\" id=\"domoticz_port\" name=\"domoticz_port\" value=\"" + String(config.domoticz_port) + "\"><br>\
<label for=\"domoticz_user\">Domoticz User:</label><br>\
<input type=\"text\" id=\"domoticz_user\" name=\"domoticz_user\" value=\"" + String(config.domoticz_user) + "\"><br>\
<label for=\"domoticz_password\">Domoticz Password:</label><br>\
<input type=\"password\" id=\"domoticz_password\" name=\"domoticz_password\" value=\"" + String(config.domoticz_password) + "\"><br><br>\
<input type=\"submit\" value=\"Save\">\
</form>\
</body>\
</html>";
server.send(200, "text/html", html);
}
void readConfig() {
EEPROM.get(DOMOTICZ_CONFIG_START, config);
Serial.println("Configuration Loaded:");
Serial.println("IP: " + String(config.domoticz_ip));
Serial.println("Port: " + String(config.domoticz_port));
Serial.println("User: " + String(config.domoticz_user));
Serial.println("Password: " + String(config.domoticz_password));
}
bool testDomoticzConnection() {
if (WiFi.status() != WL_CONNECTED) {
return false;
}
String url = String("http://") + config.domoticz_ip + ":" + config.domoticz_port + "/json.htm?type=command&param=getversion";
#ifdef ESP8266
HTTPClient http;
http.begin(url);
#else
HTTPClient http;
http.begin(url.c_str());
#endif
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
Serial.println(payload);
http.end();
return true;
} else {
Serial.println("Error on HTTP request");
http.end();
return false;
}
}
void handleTestConnection() {
String result = testDomoticzConnection() ? "Connection successful" : "Connection failed";
server.send(200, "text/plain", result);
}
void handleSave() {
if (server.hasArg("domoticz_ip") && server.hasArg("domoticz_port") && server.hasArg("domoticz_user") && server.hasArg("domoticz_password")) {
strcpy(config.domoticz_ip, server.arg("domoticz_ip").c_str());
strcpy(config.domoticz_port, server.arg("domoticz_port").c_str());
strcpy(config.domoticz_user, server.arg("domoticz_user").c_str());
strcpy(config.domoticz_password, server.arg("domoticz_password").c_str());
// Sauvegarde des paramètres dans l'EEPROM
EEPROM.put(DOMOTICZ_CONFIG_START, config);
EEPROM.commit();
readConfig();
server.send(200, "text/plain", "Configuration saved");
} else {
server.send(400, "text/plain", "Invalid request");
}
}
void handleTestConnection() {
String result = testDomoticzConnection() ? "Connection successful" : "Connection failed";
server.send(200, "text/plain", result);
}
bool testDomoticzConnection() {
if (WiFi.status() != WL_CONNECTED && String(config.domoticz_port).toInt() > 0) {
return false;
}
String url = String("http://") + config.domoticz_ip + ":" + config.domoticz_port + "/json.htm?type=command&param=getversion";
#ifdef ESP8266
HTTPClient http;
http.begin(url);
#else
HTTPClient http;
http.begin(url.c_str());
#endif
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
Serial.println(payload);
http.end();
return true;
} else {
Serial.println("Error on HTTP request");
http.end();
return false;
}
}
//void handleSettings() {
// String html = "<html>\
// <body>\
// <h2>Domoticz Configuration</h2>\
// <form action=\"/save\" method=\"POST\">\
// <label for=\"domoticz_ip\">Domoticz IP:</label><br>\
// <input type=\"text\" id=\"domoticz_ip\" name=\"domoticz_ip\" value=\"" + String(config.domoticz_ip) + "\"><br>\
// <label for=\"domoticz_port\">Domoticz Port:</label><br>\
// <input type=\"text\" id=\"domoticz_port\" name=\"domoticz_port\" value=\"" + String(config.domoticz_port) + "\"><br>\
// <label for=\"domoticz_user\">Domoticz User:</label><br>\
// <input type=\"text\" id=\"domoticz_user\" name=\"domoticz_user\" value=\"" + String(config.domoticz_user) + "\"><br>\
// <label for=\"domoticz_password\">Domoticz Password:</label><br>\
// <input type=\"password\" id=\"domoticz_password\" name=\"domoticz_password\" value=\"" + String(config.domoticz_password) + "\"><br><br>\
// <input type=\"submit\" value=\"Save\">\
// </form>\
// </body>\
// </html>";
//
// server.send(200, "text/html", html);
//}
//
//
//void handleSave() {
// if (server.hasArg("domoticz_ip") && server.hasArg("domoticz_port") && server.hasArg("domoticz_user") && server.hasArg("domoticz_password")) {
// strcpy(config.domoticz_ip, server.arg("domoticz_ip").c_str());
// strcpy(config.domoticz_port, server.arg("domoticz_port").c_str());
// strcpy(config.domoticz_user, server.arg("domoticz_user").c_str());
// strcpy(config.domoticz_password, server.arg("domoticz_password").c_str());
//
// // Sauvegarde des paramètres dans l'EEPROM
// EEPROM.put(DOMOTICZ_CONFIG_START, config);
// EEPROM.commit();
// readConfig();
// server.send(200, "text/plain", "Configuration saved");
// } else {
// server.send(400, "text/plain", "Invalid request");
// }
//}