mDNS und wifi stuff
This commit is contained in:
@@ -161,6 +161,46 @@ void setupRoutes(){
|
||||
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
|
||||
server.serveStatic("/", SPIFFS, "/");
|
||||
server.begin();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <PrettyOTA.h>
|
||||
#include <esp_now.h>
|
||||
#include <WiFi.h>
|
||||
#include <ESPmDNS.h> // <-- mDNS hinzufügen
|
||||
|
||||
#include "master.h"
|
||||
#include "licenceing.h"
|
||||
@@ -36,7 +37,13 @@ void setupWifi() {
|
||||
Serial.print("IP Adresse: ");
|
||||
Serial.println(WiFi.softAPIP());
|
||||
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) {
|
||||
@@ -56,4 +63,3 @@ void setupOTA(AsyncWebServer *server) {
|
||||
|
||||
|
||||
// WiFi als Access Point
|
||||
|
||||
Reference in New Issue
Block a user