diff --git a/src/WiFiConfig.cpp b/src/WiFiConfig.cpp index 3e687b8..5e51db7 100644 --- a/src/WiFiConfig.cpp +++ b/src/WiFiConfig.cpp @@ -119,17 +119,6 @@ extern "C" { extern char WiFiDeviceName[]; -enum { - WIFIMODE_AP = WIFI_AP, // rezim prace jako pristupovy bod (AP) - WIFIMODE_STA = WIFI_STA, // rezim prace jako klient - WIFIMODE_AP_STA = WIFI_AP_STA // rezim prace jako klient i pristupovy bod -}; - -enum { - IPCONFIG_DHCP = 0x55, // DHCP konfigurace ip adres (default) - IPCONFIG_STATIC = 0xaa // staticka konfigurace ip adres -}; - static int configBase; // musi byt trvale ulozene, aby fungovaly metody pro ziskani retezcu z EEPROM static std::unique_ptr dnsServer; @@ -944,6 +933,22 @@ wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, int tim return begin(configarea, forceConfigure, cb); // spustime WiFi } +void WiFiConfig::initConfig(int configBase, const String& ssid, const String& pass, const int mode, const int ipcfg, const IPAddress& ip, const IPAddress& mask, const IPAddress& gw, const IPAddress& dns) +{ + + EES_storeString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid), (String &)ssid); + EES_storeString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass), (String &)pass); + EEPROM.write(configBase + offsetof(wificonfigarea_t, mode), mode); + EEPROM.write(configBase + offsetof(wificonfigarea_t, ip), ipcfg); + if (IPCONFIG_STATIC == ipcfg) { + setEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr), (uint32_t) ip); + setEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask), (uint32_t) mask); + setEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway), (uint32_t) gw); + setEEPROMuint32(configBase + offsetof(wificonfigarea_t, dns), (uint32_t) dns); + } + EEPROM.commit(); // ulozime zmeny v EEPROM +} + void WiFiConfigPrepare(int configBase, String ssid, String pass) { diff --git a/src/WiFiConfig.h b/src/WiFiConfig.h index 061b33d..7accc91 100644 --- a/src/WiFiConfig.h +++ b/src/WiFiConfig.h @@ -31,9 +31,9 @@ #define __WiFiConfig_h__ #if defined(ESP8266) -#include +# include #else -#include +# include #endif #include @@ -71,6 +71,19 @@ typedef enum { WCR_CONFIGAP_NOT_STARTED = 2, // wifi neni pripojena a spusteni konfiguracniho AP bylo zakazane parametrem timeout (WC_DONT_RUN_CONFIGAP) } wificonfigresult_t; +// Interni reprezentace konfigurace WiFi +enum { + WIFIMODE_AP = WIFI_AP, // rezim prace jako pristupovy bod (AP) + WIFIMODE_STA = WIFI_STA, // rezim prace jako klient + WIFIMODE_AP_STA = WIFI_AP_STA // rezim prace jako klient i pristupovy bod +}; + +// Interni reprezentace konfigurace ip +enum { + IPCONFIG_DHCP = 0x55, // DHCP konfigurace ip adres (default) + IPCONFIG_STATIC = 0xaa // staticka konfigurace ip adres +}; + typedef void (*wificonfig_cb)(wificonfigstate_t state); // definice callbacku typedef void (*storeparam_cb)(const char *newvalue); // callback pro ulozeni uzivatelskeho parametru @@ -170,6 +183,8 @@ public: wificonfigresult_t begin(int configarea, int forceConfigure, wificonfig_cb cb); wificonfigresult_t begin(int configarea, int forceConfigure, int timeout, wificonfig_cb cb); void addParameter(WiFiConfigUsrParameter *p); + 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: wificonfigresult_t _setupAP(wificonfig_cb cb); void _handleDisplayAP(void);