Priprava na ukladani predpripravene/default konfigurace

This commit is contained in:
Pavel Brychta 2020-10-17 12:50:42 +02:00
parent 2353bfa617
commit 11aaf8450f
2 changed files with 33 additions and 13 deletions

View File

@ -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> 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)
{

View File

@ -31,9 +31,9 @@
#define __WiFiConfig_h__
#if defined(ESP8266)
#include <ESP8266WiFi.h>
# include <ESP8266WiFi.h>
#else
#include <WiFi.h>
# include <WiFi.h>
#endif
#include <memory>
@ -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);