mDNS und wifi stuff
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>
|
<head>
|
||||||
@@ -135,6 +134,36 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="section" d="wifiSection" style="display: none;">
|
||||||
|
<h2>📡 WLAN-Konfiguration</h2>
|
||||||
|
<form id="wifiForm">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="wifi-ssid">WLAN Name (SSID):</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="wifi-ssid"
|
||||||
|
name="ssid"
|
||||||
|
placeholder="WLAN-Name eingeben"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="wifi-password">WLAN Passwort:</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="wifi-password"
|
||||||
|
name="password"
|
||||||
|
placeholder="WLAN-Passwort eingeben"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="button-group">
|
||||||
|
<button type="submit" class="btn btn-primary">
|
||||||
|
💾 WLAN-Einstellungen speichern
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h2>🔄 OTA Update</h2>
|
<h2>🔄 OTA Update</h2>
|
||||||
<div id="otaRestrictionNotice" class="restriction-notice" style="display: none;">
|
<div id="otaRestrictionNotice" class="restriction-notice" style="display: none;">
|
||||||
@@ -205,7 +234,8 @@
|
|||||||
loadSystemInfo();
|
loadSystemInfo();
|
||||||
loadCurrentTime();
|
loadCurrentTime();
|
||||||
updateCurrentTimeDisplay();
|
updateCurrentTimeDisplay();
|
||||||
loadLicence()
|
loadLicence();
|
||||||
|
loadWifiSettings();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Aktuelle Zeit anzeigen (Live-Update)
|
// Aktuelle Zeit anzeigen (Live-Update)
|
||||||
@@ -423,6 +453,51 @@
|
|||||||
.catch((error) => showMessage("Verbindungsfehler", "error"));
|
.catch((error) => showMessage("Verbindungsfehler", "error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WLAN-Einstellungen laden
|
||||||
|
function loadWifiSettings() {
|
||||||
|
fetch("/api/get-wifi")
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
document.getElementById("wifi-ssid").value = data.ssid || "";
|
||||||
|
document.getElementById("wifi-password").value = data.password || "";
|
||||||
|
})
|
||||||
|
.catch(error => showMessage("Fehler beim Laden der WLAN-Einstellungen", "error"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// WLAN-Einstellungen beim Laden der Seite abrufen
|
||||||
|
window.addEventListener('load', loadWifiSettings);
|
||||||
|
|
||||||
|
// WLAN-Formular Handler
|
||||||
|
document.getElementById("wifiForm").addEventListener("submit", function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const ssid = document.getElementById("wifi-ssid").value;
|
||||||
|
const password = document.getElementById("wifi-password").value;
|
||||||
|
|
||||||
|
if (!ssid) {
|
||||||
|
showMessage("Bitte WLAN-Namen eingeben", "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch("/api/set-wifi", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
},
|
||||||
|
body: `ssid=${encodeURIComponent(ssid)}&password=${encodeURIComponent(password)}`,
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
showMessage("WLAN-Einstellungen erfolgreich gespeichert!", "success");
|
||||||
|
} else {
|
||||||
|
showMessage(data.error || "Fehler beim Speichern der WLAN-Einstellungen", "error");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => showMessage("Verbindungsfehler", "error"));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Update OTA button access based on license level
|
// Update OTA button access based on license level
|
||||||
function updateOTAButtonAccess(licenseLevel) {
|
function updateOTAButtonAccess(licenseLevel) {
|
||||||
const otaButton = document.getElementById("otaUpdateBtn");
|
const otaButton = document.getElementById("otaUpdateBtn");
|
||||||
|
|||||||
@@ -161,6 +161,46 @@ void setupRoutes(){
|
|||||||
request->send(200, "application/json", result);
|
request->send(200, "application/json", result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Setze WLAN-Name und Passwort (POST)
|
||||||
|
server.on("/api/set-wifi", HTTP_POST, [](AsyncWebServerRequest *request){
|
||||||
|
Serial.println("/api/set-wifi called");
|
||||||
|
String ssid, password;
|
||||||
|
if (request->hasParam("ssid", true)) {
|
||||||
|
ssid = request->getParam("ssid", true)->value();
|
||||||
|
}
|
||||||
|
if (request->hasParam("password", true)) {
|
||||||
|
password = request->getParam("password", true)->value();
|
||||||
|
}
|
||||||
|
if (ssid.length() > 0) {
|
||||||
|
// Hier speichern wir die neuen Werte (z.B. in Preferences oder global)
|
||||||
|
// Beispiel: strcpy(ssidSTA, ssid.c_str());
|
||||||
|
// Beispiel: strcpy(passwordSTA, password.c_str());
|
||||||
|
// In deinem Projekt ggf. persistent speichern!
|
||||||
|
// Hier als global (unsicher, nach Neustart verloren!):
|
||||||
|
ssidSTA = strdup(ssid.c_str());
|
||||||
|
passwordSTA = strdup(password.c_str());
|
||||||
|
// Rückmeldung
|
||||||
|
DynamicJsonDocument doc(64);
|
||||||
|
doc["success"] = true;
|
||||||
|
String result;
|
||||||
|
serializeJson(doc, result);
|
||||||
|
request->send(200, "application/json", result);
|
||||||
|
Serial.println("WiFi-Settings updated (nur bis zum Neustart aktiv!)");
|
||||||
|
} else {
|
||||||
|
request->send(400, "application/json", "{\"success\":false,\"error\":\"SSID fehlt\"}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Liefert aktuelle WLAN-Einstellungen (GET)
|
||||||
|
server.on("/api/get-wifi", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
|
DynamicJsonDocument doc(128);
|
||||||
|
doc["ssid"] = ssidSTA ? ssidSTA : "";
|
||||||
|
doc["password"] = passwordSTA ? passwordSTA : "";
|
||||||
|
String result;
|
||||||
|
serializeJson(doc, result);
|
||||||
|
request->send(200, "application/json", result);
|
||||||
|
});
|
||||||
|
|
||||||
// Statische Dateien
|
// Statische Dateien
|
||||||
server.serveStatic("/", SPIFFS, "/");
|
server.serveStatic("/", SPIFFS, "/");
|
||||||
server.begin();
|
server.begin();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <PrettyOTA.h>
|
#include <PrettyOTA.h>
|
||||||
#include <esp_now.h>
|
#include <esp_now.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include <ESPmDNS.h> // <-- mDNS hinzufügen
|
||||||
|
|
||||||
#include "master.h"
|
#include "master.h"
|
||||||
#include "licenceing.h"
|
#include "licenceing.h"
|
||||||
@@ -37,6 +38,12 @@ void setupWifi() {
|
|||||||
Serial.println(WiFi.softAPIP());
|
Serial.println(WiFi.softAPIP());
|
||||||
Serial.println("PrettyOTA can be accessed at: http://" + WiFi.softAPIP().toString() + "/update");
|
Serial.println("PrettyOTA can be accessed at: http://" + WiFi.softAPIP().toString() + "/update");
|
||||||
|
|
||||||
|
// mDNS starten
|
||||||
|
if (MDNS.begin("aquacross-timer")) { // z.B. http://aquacross-timer.local/
|
||||||
|
Serial.println("mDNS responder gestartet: http://aquacross-timer.local/");
|
||||||
|
} else {
|
||||||
|
Serial.println("Fehler beim Starten von mDNS!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupOTA(AsyncWebServer *server) {
|
void setupOTA(AsyncWebServer *server) {
|
||||||
@@ -56,4 +63,3 @@ void setupOTA(AsyncWebServer *server) {
|
|||||||
|
|
||||||
|
|
||||||
// WiFi als Access Point
|
// WiFi als Access Point
|
||||||
|
|
||||||
Reference in New Issue
Block a user