From f42c8a1bf3b08de1765861f2b025aa5d6fa6dee3 Mon Sep 17 00:00:00 2001 From: Pavel Brychta Date: Tue, 23 Jun 2020 10:15:28 +0200 Subject: [PATCH 1/2] Priprava pro rezim APSTA (bezi jak STA, tak AP) --- src/WiFiConfig.cpp | 12 ++++++++++++ src/WiFiConfig.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/WiFiConfig.cpp b/src/WiFiConfig.cpp index e2ecb0b..9ebc78e 100644 --- a/src/WiFiConfig.cpp +++ b/src/WiFiConfig.cpp @@ -941,4 +941,16 @@ wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, int tim _time = millis() + (_timeout * 1000); // spocitame si novy cas, kdy budeme modul restartovat return begin(configarea, forceConfigure, cb); // spustime WiFi } + +void WiFiConfigPrepare(int configBase, String ssid, String pass) +{ + + EES_storeString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid), ssid); + EES_storeString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass), pass); + EEPROM.write(configBase + offsetof(wificonfigarea_t, mode), WIFIMODE_STA); + EEPROM.write(configBase + offsetof(wificonfigarea_t, ip), IPCONFIG_DHCP); // mame DHCP dynamickou konfiguraci + EEPROM.commit(); // ulozime zmeny v EEPROM + WiFi.mode(WIFI_STA); // startujeme WiFi v rezimu klienta + WiFi.begin(ssid.c_str(), pass.c_str()); +} // EOF diff --git a/src/WiFiConfig.h b/src/WiFiConfig.h index da93e24..061b33d 100644 --- a/src/WiFiConfig.h +++ b/src/WiFiConfig.h @@ -188,4 +188,8 @@ private: uint32_t _time; // hodnota, po ktere bude ESP restartovano (pokud je _timeout != 0) uint8_t _status; // stav pripojeni - je pouzity pro signalizaci duvodu, proc se nepripoji k AP }; + +// Priprava (inicializace) EEPROM oblasti napr. u zcela noveho zarizeni +// EEPROM je inicializovana pro rezim jen STA!!! +void WiFiConfigPrepare(int configBase, String ssid, String pass); #endif -- 2.45.2 From 7ea5b222ad3bd6919cda5a1612a2cae088d2d698 Mon Sep 17 00:00:00 2001 From: Pavel Brychta Date: Fri, 21 Aug 2020 14:03:36 +0200 Subject: [PATCH 2/2] Cekani na start AP pro ESP32 --- src/WiFiConfig.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/WiFiConfig.cpp b/src/WiFiConfig.cpp index 9ebc78e..3e687b8 100644 --- a/src/WiFiConfig.cpp +++ b/src/WiFiConfig.cpp @@ -720,6 +720,7 @@ wificonfigresult_t WiFiConfig::_setupAP(wificonfig_cb cb) ssid.replace(F("?"), String(lmac)); } WiFi.softAP(ssid.c_str(), NULL, SETUP_CHANNEL); + delay(100); // kvuli ESP32 - cekame na start AP WiFi.softAPConfig(apIP, apIP, netMsk); #endif dnsServer->setErrorReplyCode(DNSReplyCode::NoError); @@ -826,6 +827,7 @@ bool WiFiConfig::_testWifi(wificonfig_cb cb) WiFi.softAP(s.c_str(), NULL, EEPROM.read(configBase + offsetof(wificonfigarea_t, apchannel))); } if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip))) { + delay(100); // kvuli ESP32 - cekame na start AP WiFi.softAPConfig(IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask)))); } -- 2.45.2