#include long AskServerinterval = 10000; unsigned long AskServerpreviousMillis = 0; void getJSONfromServer(){ if(WiFi.status() != WL_CONNECTED) return; esp_task_wdt_reset(); String payload = ""; String requestBody = ""; HTTPClient http; // lokal - Destruktor räumt TLS-Kontext sauber auf bool httpInitResult = http.begin("https://ab.xyz-domain.eu/json.php"); if( httpInitResult == false ) { Serial.println("SV http.begin() failed!"); http.end(); return; } http.setConnectTimeout(5000); http.setTimeout(5000); http.addHeader("Content-Type", "application/json"); esp_task_wdt_reset(); { JsonDocument requestDoc; if (ChargingType == Solar_Charging) { requestDoc["Modus"] = "Solar"; } if (ChargingType == Night_Charging) { requestDoc["Modus"] = "Full"; } if (ChargingType == Charging_Disabled) { requestDoc["Modus"] = "Off"; } if (Timer_Charging == true) { requestDoc["Timer_Charging"] = "Enabled"; } else { requestDoc["Timer_Charging"] = "Disabled"; } requestDoc["uptime"] = (millis() / 1000) / 60; requestDoc["acivePhase"] = UsedChargingPhase; requestDoc["PowerToCharger"] = PowerToCharger; requestDoc["PowerFromCharger"] = LadeleistungFromCharger; requestDoc["PowerUseable"] = VorhandeneLeistung; requestDoc["Ladefreigabe"] = Ladefreigabe; requestDoc["Solar"] = TooMutch; requestDoc["DebugMSG"] = DebugMSG; requestDoc["ResetReason"] = lastResetReason; requestDoc["FreeHeap"] = ESP.getFreeHeap(); requestDoc["EVCCenable"] = EVCCenable; requestDoc["EVCCcurrent"] = EVCCcurrent; requestDoc["EVCCphases"] = EVCCphases; requestDoc["version"] = version_internal; requestDoc["compile_date"] = compile_date; if (OrnoWE517_active == 0) { requestDoc["ZaehlerStatus"] = "fehlt"; ZaehlerPower = -1; } else { requestDoc["ZaehlerStatus"] = "vorhanden"; requestDoc["ZaehlerstandStart"] = String(ZaehlerstandStart); requestDoc["ZaehlerstandAktuell"] = String(ZaehlerstandAktuell); requestDoc["ZaehlerLeistung"] = ZaehlerPower; requestDoc["kWhGeladen"] = String(ZaehlerstandAktuell - ZaehlerstandStart); } requestDoc["total_power_em"] = total_power.toInt(); requestDoc["lat"] = "null"; requestDoc["lon"] = "null"; serializeJson(requestDoc, requestBody); } // requestDoc wird hier freigegeben esp_task_wdt_reset(); int httpResponseCode = http.POST(requestBody); if (httpResponseCode > 0) { payload = http.getString(); } else { Serial.print("Server Error: "); Serial.println(httpResponseCode); http.end(); return; } http.end(); // lokaler HTTPClient - Destruktor gibt TLS-Kontext frei JsonDocument responseDoc; DeserializationError error = deserializeJson(responseDoc, payload); if (error) return; if (responseDoc["AskServerInterval"].as() != "null") { AskServerinterval = (responseDoc["AskServerInterval"].as()).toInt() * 1000; } if (responseDoc["Modus"].as() != "null") { if (responseDoc["Modus"].as() == "Solar") { ChargingType = Solar_Charging; Timer_Charging = false; } if (responseDoc["Modus"].as() == "Full") { ChargingType = Night_Charging; Timer_Charging = false; } if (responseDoc["Modus"].as() == "Timer") { Timer_Charging = true; } if (responseDoc["Modus"].as() == "Off") { ChargingType = Charging_Disabled; Timer_Charging = false; } } if (responseDoc["AskServerInterval"].as() != "null") { AskServerinterval = (responseDoc["AskServerInterval"].as()).toInt() * 1000; } if (responseDoc["Time"].as() != "null") { if (Timer_Charging == true) { if ((responseDoc["Time"].as() >= conf.getString("day_time")) && (responseDoc["Time"].as() < conf.getString("night_time"))) { ChargingType = Solar_Charging; } if ((responseDoc["Time"].as() < conf.getString("day_time")) || (responseDoc["Time"].as() >= conf.getString("night_time"))) { ChargingType = Night_Charging; SwitchTo3Ph(); FullChrgPower = 11000; } } } } void MyWebsiteHandler() { server.on("/my", HTTP_GET, []() { if (!server.authenticate(admin_username, admin_password)) { server.requestAuthentication(); return; } streamFileSafe("/my_wallterbox.html", "text/html"); }); } void AskServer() { if (ota_running) return; if (WiFi.status() != WL_CONNECTED) return; if (AskServerinterval < 3000) { AskServerinterval = 3000; } if (millis() - AskServerpreviousMillis >= AskServerinterval) { AskServerpreviousMillis = millis(); getJSONfromServer(); } }