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 = "\ \

Domoticz Configuration

\
\
\
\
\
\
\
\
\

\ \
\ \ "; 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¶m=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¶m=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 = "\ // \ //

Domoticz Configuration

\ //
\ //
\ //
\ //
\ //
\ //
\ //
\ //
\ //

\ // \ //
\ // \ // "; // // 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"); // } //}