Jina aktivace noveho nastaveni. TODO: prekontrolovat, zda neni mozne metodu vyuzit i pri ukladani nove konfigurace z webu
This commit is contained in:
parent
4cdce88ca5
commit
dd4204c7a1
@ -775,6 +775,65 @@ wificonfigresult_t WiFiConfig::_setupAP(wificonfig_cb cb)
|
|||||||
return WCR_TIMEOUT; // nepripojeno, vyprsel timeout konfiguracniho AP
|
return WCR_TIMEOUT; // nepripojeno, vyprsel timeout konfiguracniho AP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WiFiConfig::_prepareWifi(wificonfig_cb cb)
|
||||||
|
{
|
||||||
|
// nakonfigurujeme ESP dle nove nastavenych parametru
|
||||||
|
WiFi.disconnect(); // vsechno odpojime
|
||||||
|
|
||||||
|
String s = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
||||||
|
String pass = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
||||||
|
|
||||||
|
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode))) {
|
||||||
|
case WIFIMODE_STA: {
|
||||||
|
DEBUG_MSG("STA mode.\r\n");
|
||||||
|
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip))) {
|
||||||
|
DEBUG_MSG("Static configuration.\r\n");
|
||||||
|
WiFi.config(IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway))),
|
||||||
|
IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, dns))));
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
WiFi.mode(WIFI_STA); // startujeme WiFi v rezimu klienta
|
||||||
|
WiFi.begin(s.c_str(), pass.c_str());
|
||||||
|
DEBUG_MSG("STA params: %s, %s\r\n", s.c_str(), pass.c_str());
|
||||||
|
#if defined(ESP32)
|
||||||
|
if (strlen(WiFiDeviceName)) {
|
||||||
|
WiFi.setHostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WIFIMODE_AP:
|
||||||
|
DEBUG_MSG("AP mode.\r\n");
|
||||||
|
if (s.endsWith(F("?"))) {
|
||||||
|
char lmac[16];
|
||||||
|
|
||||||
|
sprintf_P(lmac, PSTR("%06X"), ESP_getChipId());
|
||||||
|
s.replace(F("?"), String(lmac));
|
||||||
|
}
|
||||||
|
WiFi.mode(WIFI_AP); // startujeme AP
|
||||||
|
if (pass.length()) {
|
||||||
|
// je zadane heslo do AP
|
||||||
|
WiFi.softAP(s.c_str(), pass.c_str(), EEPROM.read(configBase + offsetof(wificonfigarea_t, apchannel)));
|
||||||
|
} else {
|
||||||
|
// otevreny AP
|
||||||
|
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))));
|
||||||
|
}
|
||||||
|
if (cb)
|
||||||
|
cb(WCS_CONNECTED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: // jakykoliv neznamy rezim (mozna zavada na EEPROM???)
|
||||||
|
DEBUG_MSG("Mode Error!!\r\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Testovani, zda se modul pripojil k AP
|
// Testovani, zda se modul pripojil k AP
|
||||||
bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
||||||
{
|
{
|
||||||
@ -954,7 +1013,7 @@ void WiFiConfig::initConfig(int configBase, const String& ssid, const String& pa
|
|||||||
setEEPROMuint32(configBase + offsetof(wificonfigarea_t, dns), (uint32_t) dns);
|
setEEPROMuint32(configBase + offsetof(wificonfigarea_t, dns), (uint32_t) dns);
|
||||||
}
|
}
|
||||||
EEPROM.commit(); // ulozime zmeny v EEPROM
|
EEPROM.commit(); // ulozime zmeny v EEPROM
|
||||||
_testWifi(nullptr); // nastavime novou WiFi konfiguraci
|
_prepareWifi(nullptr); // nastavime novou WiFi konfiguraci
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zastarale - bude brzy odstraneno!!!
|
// Zastarale - bude brzy odstraneno!!!
|
||||||
|
@ -186,6 +186,7 @@ public:
|
|||||||
void initConfig(int configBase, const String& ssid, const String&pass, const int mode = WIFIMODE_STA, const int ipcfg = IPCONFIG_DHCP, const IPAddress& ip = 0, const IPAddress& mask = 0, const IPAddress& gw = 0, const IPAddress& dns = 0);
|
void initConfig(int configBase, const String& ssid, const String&pass, const int mode = WIFIMODE_STA, const int ipcfg = IPCONFIG_DHCP, const IPAddress& ip = 0, const IPAddress& mask = 0, const IPAddress& gw = 0, const IPAddress& dns = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _prepareWifi(wificonfig_cb cb);
|
||||||
wificonfigresult_t _setupAP(wificonfig_cb cb);
|
wificonfigresult_t _setupAP(wificonfig_cb cb);
|
||||||
void _handleDisplayAP(void);
|
void _handleDisplayAP(void);
|
||||||
void _handleSetAP(void);
|
void _handleSetAP(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user