increase AP limit, rename WIfi to NinjaCross for buttons and master
This commit is contained in:
@@ -18,22 +18,32 @@ String getUniqueSSID();
|
||||
bool isInternetAvailable();
|
||||
void loopOTA();
|
||||
void setupOTA();
|
||||
void onWiFiAPClientConnected(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||
|
||||
// Initialisiert das WLAN als Access Point oder Station und startet mDNS/OTA.
|
||||
void setupWifi() {
|
||||
|
||||
IPAddress local_ip(192, 168, 10, 1);
|
||||
IPAddress gateway(192, 168, 10, 1);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
WiFi.softAPConfig(local_ip, gateway, subnet); // Set AP IP and DHCP range
|
||||
|
||||
uniqueSSID = getUniqueSSID();
|
||||
ssidAP = uniqueSSID.c_str();
|
||||
if (ssidSTA == nullptr || passwordSTA == nullptr ||
|
||||
String(ssidSTA).isEmpty() || String(passwordSTA).isEmpty()) {
|
||||
Serial.println("Fehler: ssidSTA oder passwordSTA ist null!");
|
||||
WiFi.mode(WIFI_MODE_AP);
|
||||
WiFi.softAP(ssidAP, passwordAP);
|
||||
WiFi.softAP(ssidAP, passwordAP, 1, 0, 8);
|
||||
// Call this in setupWifi() after WiFi.softAP(...)
|
||||
WiFi.onEvent(onWiFiAPClientConnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_AP_STACONNECTED);
|
||||
} else {
|
||||
|
||||
WiFi.mode(WIFI_MODE_APSTA);
|
||||
WiFi.begin(ssidSTA, passwordSTA);
|
||||
WiFi.softAP(ssidAP, passwordAP);
|
||||
WiFi.softAP(ssidAP, passwordAP, 1, 0, 8);
|
||||
// Call this in setupWifi() after WiFi.softAP(...)
|
||||
WiFi.onEvent(onWiFiAPClientConnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_AP_STACONNECTED);
|
||||
|
||||
// Add timeout for WiFi connection
|
||||
unsigned long startAttemptTime = millis();
|
||||
@@ -47,7 +57,7 @@ void setupWifi() {
|
||||
Serial.println("Fehler: Verbindung zum WLAN fehlgeschlagen!");
|
||||
Serial.println("Starte Access Point...");
|
||||
WiFi.mode(WIFI_MODE_AP);
|
||||
WiFi.softAP(ssidAP, passwordAP);
|
||||
WiFi.softAP(ssidAP, passwordAP, 1, 0, 8);
|
||||
} else {
|
||||
Serial.println("Erfolgreich mit WLAN verbunden!");
|
||||
Serial.print("IP Adresse: ");
|
||||
@@ -104,7 +114,7 @@ String getUniqueSSID() {
|
||||
char uniqueId[6];
|
||||
snprintf(uniqueId, sizeof(uniqueId), "%02X%03X", mac[4], mac[5]);
|
||||
|
||||
return String("AquaCross-") + String(uniqueId);
|
||||
return String("NinjaCross-") + String(uniqueId);
|
||||
}
|
||||
|
||||
// Prüft, ob das Internet erreichbar ist (z.B. durch Ping auf 8.8.8.8)
|
||||
@@ -113,3 +123,14 @@ bool isInternetAvailable() {
|
||||
// Versuche, eine Verbindung zu Googles DNS auf Port 53 herzustellen
|
||||
return client.connect("8.8.8.8", 53);
|
||||
}
|
||||
|
||||
void onWiFiAPClientConnected(WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
Serial.print("Client connected! MAC: ");
|
||||
for (int i = 0; i < 6; i++) {
|
||||
Serial.printf("%02X", info.wifi_ap_staconnected.mac[i]);
|
||||
if (i < 5) Serial.print(":");
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user