Compare commits
13 Commits
6.3.4
...
5c382257e9
Author | SHA1 | Date | |
---|---|---|---|
5c382257e9 | |||
3f433aedc8 | |||
1106aa060a | |||
b608d36096 | |||
6f845e1e45 | |||
170af78f28 | |||
dd4204c7a1 | |||
4cdce88ca5 | |||
6f1dd6a7ba | |||
11aaf8450f | |||
2353bfa617 | |||
7ea5b222ad | |||
f42c8a1bf3 |
@ -8,11 +8,8 @@
|
||||
# include <NetBIOS.h>
|
||||
#endif
|
||||
#include <ArduinoOTA.h>
|
||||
#include <EEPROM.h>
|
||||
#include <WiFiConfig.h>
|
||||
#include <encipheredEEPROMStrings.h>
|
||||
|
||||
#define EEPROM_MAGIC 0xdeadbeef
|
||||
#include <sysvars.hpp>
|
||||
|
||||
// Plati pro desticku Witty s modulem ESP-12E
|
||||
#define PIN_FORCE_CONFIG 4
|
||||
@ -20,34 +17,24 @@
|
||||
//#define DEBUG_OUT(a) {}
|
||||
#define DEBUG_OUT(a) Serial.print(a)
|
||||
|
||||
// Definice obsazeni EEPROM
|
||||
#define elementSize(type, element) sizeof(((type *)0)->element)
|
||||
#define countof(a) (sizeof(a) / sizeof(a[0]))
|
||||
typedef struct {
|
||||
uint32_t magic; // kontrola spravneho obsahu EEPROM
|
||||
char devname[32 + 2]; // jmeno zarizeni (pro NBNS plati jen 16 znaku)
|
||||
} eepromconfig_t;
|
||||
|
||||
#define EEPROM_SIZE (sizeof(wificonfigarea_t) + sizeof(eepromconfig_t) + 10) // velikost EEPROM oblasti (POZOR!!! zbytecnym zvetsovanim se zaroven zmensuje velikost RAM kvuli zrcadlu!!!)
|
||||
#define EEPROM_WIFICONFIG_ORIGIN (EEPROM_SIZE - sizeof(wificonfigarea_t)) // pocatek oblasti, pouzivane WiFiConfig (alokovano odzadu)
|
||||
#define EEPROM_CONFIG_ORIGIN (0)
|
||||
|
||||
char WiFiDeviceName[elementSize(eepromconfig_t, devname)]; // misto pro jmeno zarizeni (dodane do DNS, DHCP NBNS apod...)
|
||||
char WiFiDeviceName[32]; // misto pro jmeno zarizeni (dodane do DNS, DHCP NBNS apod...)
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
ESP8266WebServer wwwserver(80); // webovy server
|
||||
#else
|
||||
WebServer wwwserver(80); // webovy server
|
||||
#endif
|
||||
String content;
|
||||
|
||||
static char MAINPAGE[] PROGMEM = R"=====(<!DOCTYPE HTML>
|
||||
<html>
|
||||
Hello world from ESP8266
|
||||
<p>
|
||||
</html>
|
||||
)=====";
|
||||
|
||||
static void handleRoot(void)
|
||||
{
|
||||
|
||||
content = F("<!DOCTYPE HTML>\n<html>Hello world from ESP8266");
|
||||
content += F("<p>");
|
||||
content += F("</html>");
|
||||
|
||||
wwwserver.send(200, "text/html", content);
|
||||
wwwserver.send_P(200, "text/html", MAINPAGE);
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR wcb(wificonfigstate_t state)
|
||||
@ -82,7 +69,7 @@ void ICACHE_FLASH_ATTR saveDevname(const char *param)
|
||||
{
|
||||
String p = param;
|
||||
|
||||
EES_storeString(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, devname), elementSize(eepromconfig_t, devname), p);
|
||||
svSetV(F("devname"), p);
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR setup()
|
||||
@ -90,28 +77,16 @@ void ICACHE_FLASH_ATTR setup()
|
||||
WiFiConfig wifi; // konfigurace ESP modulu
|
||||
WiFiConfigUsrParameter devname("devname", "Jméno zařízení", (const char *)WiFiDeviceName, 32, saveDevname);
|
||||
|
||||
EEPROM.begin(EEPROM_SIZE); // zahajujeme praci s EEPROM
|
||||
|
||||
uint32_t magic;
|
||||
|
||||
EEPROM.get(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, magic), magic);
|
||||
if (EEPROM_MAGIC != magic) {
|
||||
// EEPROM ma spatny obsah
|
||||
for (unsigned int i = 0; i < EEPROM_SIZE; i++)
|
||||
EEPROM.write(i, 0);
|
||||
magic = EEPROM_MAGIC;
|
||||
EEPROM.put(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, magic), magic);
|
||||
EEPROM.commit();
|
||||
}
|
||||
LittleFS.begin();
|
||||
|
||||
pinMode(PIN_FORCE_CONFIG, INPUT_PULLUP); // pin, co slouzi jako vstup tlacitka
|
||||
int fc = digitalRead(PIN_FORCE_CONFIG); // pozadavek na vynucene vyvolani konfigurace
|
||||
Serial.begin(115200);
|
||||
String dn = EES_readString(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, devname), elementSize(eepromconfig_t, devname));
|
||||
String dn = svGetV<String>(F("devname"));
|
||||
strcpy(WiFiDeviceName, dn.c_str());
|
||||
wifi.addParameter(&devname);
|
||||
|
||||
if (WCR_OK != wifi.begin(EEPROM_WIFICONFIG_ORIGIN, fc, wcb)) // startujeme pripojeni
|
||||
if (WCR_OK != wifi.begin(fc, wcb)) // startujeme pripojeni
|
||||
ESP.restart();
|
||||
|
||||
wwwserver.on("/", handleRoot);
|
||||
|
@ -10,9 +10,9 @@
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "http://git.xpablo.cz/pablo2048/WiFiConfig.git"
|
||||
"url": "https://git.xpablo.cz/pablo2048/WiFiConfig.git"
|
||||
},
|
||||
"version": "6.3.4",
|
||||
"version": "7.0.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": ["espressif8266", "espressif32"],
|
||||
|
@ -1,9 +1,9 @@
|
||||
name=WiFiConfig
|
||||
version=6.3.4
|
||||
version=7.0.0
|
||||
author=Pavel Brychta
|
||||
maintainer=Pavel Brychta <Pablo@xpablo.cz>
|
||||
maintainer=Pavel Brychta <pablo@xpablo.cz>
|
||||
sentence=Enables seamless module configuration.
|
||||
paragraph=With this library you can enable your ESP8266 or ESP32 module to be configured over WiFi. Includes Captive Portal for easy configuration.
|
||||
category=Other
|
||||
url=http://www.xpablo.cz
|
||||
url=https://www.xpablo.cz
|
||||
architectures=esp8266,esp32
|
||||
|
@ -1,4 +1,10 @@
|
||||
/*
|
||||
* v7.0.0- 4.3.2021 - verze s konfiguraci v JSON na souborovem systemu
|
||||
*
|
||||
* v6.4.0- 27.2.2021 - funkcni inicializace konfigurace
|
||||
*
|
||||
* v6.3.5-28.11.2020 - moznost nadefinovat titulek webove stranky a popisek okna v prohlizeci pomoci WIFICONFIG_TITLE a WIFICONFIG_WEBTITLE
|
||||
*
|
||||
* v6.3.4-23.3.2020 - staticka konfigurace v AP rezimu funkcni
|
||||
*
|
||||
* v6.3.3-27.10.2019 - volani WS_CONNECTED i v pripade, ze bezi AP
|
||||
@ -94,11 +100,22 @@
|
||||
# include <rom/rtc.h> // duvod resetu (https://github.com/espressif/arduino-esp32/issues/449)
|
||||
#endif
|
||||
#include "WiFiConfig.h"
|
||||
#include <EEPROM.h>
|
||||
#include <Ticker.h>
|
||||
#include <encipheredEEPROMStrings.h>
|
||||
#include <sysvars.hpp>
|
||||
#include "embHTML.h"
|
||||
|
||||
#if not defined(WIFICFG_FILE)
|
||||
# define WIFICFG_FILE "/wifi.json"
|
||||
#endif
|
||||
|
||||
#if defined(ESP8266)
|
||||
// ESP8266
|
||||
# define SETHOSTNAME(a) WiFi.hostname(a)
|
||||
#else
|
||||
// ESP32
|
||||
# define SETHOSTNAME(a) WiFi.setHostname(a)
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_ESP_PORT
|
||||
# define DEBUG_MSG(_1, ...) DEBUG_ESP_PORT.printf_P(PSTR(_1), ##__VA_ARGS__)
|
||||
#else
|
||||
@ -119,19 +136,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;
|
||||
#if defined(ESP8266)
|
||||
static std::unique_ptr<ESP8266WebServer> server;
|
||||
@ -167,64 +171,12 @@ IPAddress getOurIP(void)
|
||||
uint8_t * getOurMAC(uint8_t *mac)
|
||||
{
|
||||
|
||||
if (WIFIMODE_STA == EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)))
|
||||
if (WIFIMODE_STA == svGetV<int>(F("mode"), nullptr, F(WIFICFG_FILE)))
|
||||
return WiFi.macAddress(mac);
|
||||
else
|
||||
return WiFi.softAPmacAddress(mac);
|
||||
}
|
||||
|
||||
uint32_t getEEPROMuint32(unsigned int start)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
for (uint32_t i = 0; i < 4; ++i) {
|
||||
result <<= 8;
|
||||
result += EEPROM.read(start);
|
||||
++start;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void setEEPROMuint32(unsigned int start, uint32_t val)
|
||||
{
|
||||
|
||||
for (unsigned int i = 0; i < 4; ++i) {
|
||||
EEPROM.write(start + 3 - i, (uint8_t)val);
|
||||
val >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
String getEEPROMString(unsigned int start, size_t len)
|
||||
{
|
||||
String string = "";
|
||||
|
||||
for (unsigned int i = start; i < + start + len; ++i) {
|
||||
uint8_t b = EEPROM.read(i);
|
||||
|
||||
if ((0xff == b) || (0 == b))
|
||||
break;
|
||||
string += char(b);
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
void setEEPROMString(unsigned int start, size_t len, String &string)
|
||||
{
|
||||
unsigned int si = 0;
|
||||
|
||||
for (unsigned int i = start; i < start + len; ++i) {
|
||||
char c;
|
||||
|
||||
if (si < string.length()) {
|
||||
c = string[si];
|
||||
} else {
|
||||
c = 0;
|
||||
}
|
||||
EEPROM.write(i, c);
|
||||
++si;
|
||||
}
|
||||
}
|
||||
|
||||
WiFiConfigUsrParameter::WiFiConfigUsrParameter(const char *id, const char *label, const char *defaultValue, unsigned int length, storeparam_cb cb)
|
||||
{
|
||||
_next = NULL;
|
||||
@ -436,7 +388,7 @@ void WiFiConfig::_handleRoot(void)
|
||||
break;
|
||||
|
||||
case 0xfe:
|
||||
content.concat(F("Špatná EEPROM"));
|
||||
content.concat(F("Špatná konfigurace"));
|
||||
break;
|
||||
|
||||
case 0xff:
|
||||
@ -507,30 +459,31 @@ void WiFiConfig::_handleDisplayAP(void)
|
||||
}
|
||||
}
|
||||
s = FPSTR(PAGE_INDEX2);
|
||||
v = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
||||
v = svGetV<String>(F("ssid"), nullptr, F(WIFICFG_FILE));
|
||||
strDecode(v);
|
||||
if (v.length())
|
||||
s.replace(F("{s}"), String(FPSTR(VALUE)) + v + F("'"));
|
||||
else
|
||||
s.replace(F("{s}"), F(""));
|
||||
v = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
||||
v = svGetV<String>(F("pass"), nullptr, F(WIFICFG_FILE));
|
||||
if (v.length())
|
||||
s.replace(F("{p}"), String(FPSTR(VALUE)) + v + F("'"));
|
||||
else
|
||||
s.replace(F("{p}"), F(""));
|
||||
if (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)) == WIFIMODE_AP)
|
||||
if (svGetV<int>(F("mode"), nullptr, F(WIFICFG_FILE)) == WIFIMODE_AP)
|
||||
s.replace(F("{a}"), FPSTR(CHECKED));
|
||||
else
|
||||
s.replace(F("{a}"), F(""));
|
||||
if (EEPROM.read(configBase + offsetof(wificonfigarea_t, ip)) == IPCONFIG_STATIC)
|
||||
if (svGetV<int>(F("ipmode"), nullptr, F(WIFICFG_FILE)) == IPCONFIG_STATIC)
|
||||
s.replace(F("{c}"), FPSTR(CHECKED));
|
||||
else
|
||||
s.replace(F("{c}"), F(""));
|
||||
s.replace(F("{i}"), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr))).toString());
|
||||
s.replace(F("{m}"), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask))).toString());
|
||||
s.replace(F("{g}"), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway))).toString());
|
||||
s.replace(F("{d}"), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, dns))).toString());
|
||||
s.replace(F("{i}"), IPAddress(svGetV<uint32_t>(F("ip"), nullptr, F(WIFICFG_FILE))).toString());
|
||||
s.replace(F("{m}"), IPAddress(svGetV<uint32_t>(F("mask"), nullptr, F(WIFICFG_FILE))).toString());
|
||||
s.replace(F("{g}"), IPAddress(svGetV<uint32_t>(F("gate"), nullptr, F(WIFICFG_FILE))).toString());
|
||||
s.replace(F("{d}"), IPAddress(svGetV<uint32_t>(F("dns"), nullptr, F(WIFICFG_FILE))).toString());
|
||||
|
||||
uint8_t chan = EEPROM.read(configBase + offsetof(wificonfigarea_t, apchannel));
|
||||
uint8_t chan = svGetV<int>(F("channel"), nullptr, F(WIFICFG_FILE));
|
||||
if ((chan < 1) || (chan > 13))
|
||||
chan = 1; // neplatne cislo kanalu nahradime nejnizsim
|
||||
s.replace(F("{ch}"), String(chan));
|
||||
@ -566,43 +519,45 @@ void WiFiConfig::_handleSetAP(void)
|
||||
str.reserve(128);
|
||||
str = server->arg(F("_s"));
|
||||
if (str.length() > 0) {
|
||||
EES_storeString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid), str);
|
||||
|
||||
strEncode(str);
|
||||
svSetV(F("ssid"), str, F(WIFICFG_FILE));
|
||||
str = server->arg(F("_p"));
|
||||
EES_storeString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass), str);
|
||||
strEncode(str);
|
||||
svSetV(F("pass"), str, F(WIFICFG_FILE));
|
||||
|
||||
str = server->arg(F("_a"));
|
||||
if (str.length() > 0) {
|
||||
mode = WIFIMODE_AP; // rezim AP
|
||||
str = server->arg(F("_ch")); // kanal AP
|
||||
EEPROM.write(configBase + offsetof(wificonfigarea_t, apchannel), (uint8_t)str.toInt());
|
||||
svSetV<int>(F("channel"), str.toInt(), F(WIFICFG_FILE));
|
||||
} else
|
||||
mode = WIFIMODE_STA; // rezim STA
|
||||
EEPROM.write(configBase + offsetof(wificonfigarea_t, mode), mode);
|
||||
svSetV(F("mode"), mode, F(WIFICFG_FILE));
|
||||
|
||||
str = server->arg(F("_st"));
|
||||
if (0 == str.length())
|
||||
EEPROM.write(configBase + offsetof(wificonfigarea_t, ip), IPCONFIG_DHCP); // mame DHCP dynamickou konfiguraci
|
||||
svSetV<int>(F("ipmode"), IPCONFIG_DHCP, F(WIFICFG_FILE)); // mame DHCP dynamickou konfiguraci
|
||||
else {
|
||||
// staticka ip konfigurace
|
||||
IPAddress ipa;
|
||||
|
||||
EEPROM.write(configBase + offsetof(wificonfigarea_t, ip), IPCONFIG_STATIC);
|
||||
svSetV<int>(F("ipmode"), IPCONFIG_STATIC, F(WIFICFG_FILE)); // mame statickou konfiguraci
|
||||
str = server->arg(F("_i"));
|
||||
ipa.fromString(str);
|
||||
setEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr), (uint32_t) ipa);
|
||||
svSetV<uint32_t>(F("ip"), (uint32_t)ipa, F(WIFICFG_FILE));
|
||||
|
||||
str = server->arg(F("_m"));
|
||||
ipa.fromString(str);
|
||||
setEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask), (uint32_t) ipa);
|
||||
svSetV<uint32_t>(F("mask"), (uint32_t)ipa, F(WIFICFG_FILE));
|
||||
|
||||
str = server->arg(F("_g"));
|
||||
ipa.fromString(str);
|
||||
setEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway), (uint32_t) ipa);
|
||||
svSetV<uint32_t>(F("gw"), (uint32_t)ipa, F(WIFICFG_FILE));
|
||||
|
||||
str = server->arg(F("_d"));
|
||||
ipa.fromString(str);
|
||||
setEEPROMuint32(configBase + offsetof(wificonfigarea_t, dns), (uint32_t) ipa);
|
||||
svSetV<uint32_t>(F("dns"), (uint32_t)ipa, F(WIFICFG_FILE));
|
||||
}
|
||||
|
||||
// Uzivatelske parametry
|
||||
@ -613,70 +568,11 @@ void WiFiConfig::_handleSetAP(void)
|
||||
up->setNewValue(server->arg(i).c_str());
|
||||
}
|
||||
}
|
||||
EEPROM.commit(); // skutecne ulozime data
|
||||
}
|
||||
server->send_P(200, TEXTHTML, PAGE_SAVED);
|
||||
delay(2000); // cekame na odeslani dat
|
||||
// nakonfigurujeme ESP dle nove nastavenych parametru
|
||||
WiFi.persistent(true); // chceme, aby si modul zapamatoval konfiguraci
|
||||
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 defined(ESP8266)
|
||||
if (strlen(WiFiDeviceName)) {
|
||||
WiFi.hostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||
}
|
||||
#endif
|
||||
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());
|
||||
#if !defined(ESP8266)
|
||||
if (strlen(WiFiDeviceName)) {
|
||||
WiFi.setHostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||
}
|
||||
#endif
|
||||
#if defined(ESP8266)
|
||||
wifi_station_set_auto_connect(true);
|
||||
#else
|
||||
//esp_wifi_set_auto_connect(true);
|
||||
#endif
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
break;
|
||||
|
||||
case WIFIMODE_AP:
|
||||
DEBUG_MSG("AP mode.\r\n");
|
||||
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))) {
|
||||
WiFi.softAPConfig(IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway))),
|
||||
IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask))));
|
||||
}
|
||||
break;
|
||||
|
||||
default: // jakykoliv neznamy rezim (mozna zavada na EEPROM???)
|
||||
DEBUG_MSG("Mode Error!!\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
delay(1000); // cekame XX sekund na ulozeni atd...
|
||||
_prepareWifi();
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
@ -720,6 +616,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);
|
||||
@ -794,16 +691,20 @@ bool WiFiConfig::_testWifi(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));
|
||||
encString s = svGetV<String>(F("ssid"), nullptr, F(WIFICFG_FILE));
|
||||
s.decode();
|
||||
encString pass = svGetV<String>(F("pass"), nullptr, F(WIFICFG_FILE));
|
||||
pass.decode();
|
||||
|
||||
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode))) {
|
||||
switch (svGetV<int>(F("mode"), nullptr, F(WIFICFG_FILE))) {
|
||||
case WIFIMODE_STA: {
|
||||
|
||||
DEBUG_MSG("STA mode.\r\n");
|
||||
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip))) {
|
||||
if (IPCONFIG_STATIC == svGetV<int>(F("ipmode"), nullptr, F(WIFICFG_FILE))) {
|
||||
|
||||
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))));
|
||||
WiFi.config(IPAddress(svGetV<uint32_t>(F("ip"), nullptr, F(WIFICFG_FILE))), IPAddress(svGetV<uint32_t>(F("gw"), nullptr, F(WIFICFG_FILE))),
|
||||
IPAddress(svGetV<uint32_t>(F("mask"), nullptr, F(WIFICFG_FILE))), IPAddress(svGetV<uint32_t>(F("dns"), nullptr, F(WIFICFG_FILE))));
|
||||
delay(100);
|
||||
}
|
||||
WiFi.mode(WIFI_STA); // startujeme WiFi v rezimu klienta
|
||||
@ -817,17 +718,25 @@ bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
||||
|
||||
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
|
||||
int chan = svGetV<int>(F("channel"), nullptr, F(WIFICFG_FILE));
|
||||
if (pass.length()) {
|
||||
// je zadane heslo do AP
|
||||
WiFi.softAP(s.c_str(), pass.c_str(), EEPROM.read(configBase + offsetof(wificonfigarea_t, apchannel)));
|
||||
WiFi.softAP(s.c_str(), pass.c_str(), chan);
|
||||
} else {
|
||||
// otevreny AP
|
||||
WiFi.softAP(s.c_str(), NULL, EEPROM.read(configBase + offsetof(wificonfigarea_t, apchannel)));
|
||||
WiFi.softAP(s.c_str(), NULL, chan);
|
||||
}
|
||||
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip))) {
|
||||
WiFi.softAPConfig(IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway))),
|
||||
IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask))));
|
||||
if (IPCONFIG_STATIC == svGetV<int>(F("ipmode"), nullptr, F(WIFICFG_FILE))) {
|
||||
delay(100); // kvuli ESP32 - cekame na start AP
|
||||
WiFi.softAPConfig(IPAddress(svGetV<uint32_t>(F("ip"), nullptr, F(WIFICFG_FILE))), IPAddress(svGetV<uint32_t>(F("gw"), nullptr, F(WIFICFG_FILE))),
|
||||
IPAddress(svGetV<uint32_t>(F("mask"), nullptr, F(WIFICFG_FILE))));
|
||||
}
|
||||
if (cb)
|
||||
cb(WCS_CONNECTED);
|
||||
@ -860,40 +769,38 @@ bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
||||
return false; // pripojeni se nezdarilo
|
||||
}
|
||||
|
||||
wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, wificonfig_cb cb)
|
||||
wificonfigresult_t WiFiConfig::begin(int forceConfigure, wificonfig_cb cb)
|
||||
{
|
||||
wificonfigresult_t result = WCR_OK; // predpokladame, ze se pripojeni podari
|
||||
|
||||
DEBUG_MSG("\r\n\r\n"); // oddeleni vypisu
|
||||
|
||||
configBase = configarea; // pocatek konfigurace v EEPROM
|
||||
if (0 == forceConfigure) {
|
||||
DEBUG_MSG("Force config.\r\n");
|
||||
_status = 0xff;
|
||||
result = _setupAP(cb);
|
||||
} else {
|
||||
#if defined(ESP8266)
|
||||
if (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)) != WiFi.getMode()) {
|
||||
if (svGetV<int>(F("mode"), nullptr, F(WIFICFG_FILE)) != WiFi.getMode()) {
|
||||
// neshoduje se rezim - musime spustit konfiguracni AP (poskozena konfigurace)
|
||||
DEBUG_MSG("Wrong config (%d, %d)\r\n", EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)), WiFi.getMode());
|
||||
DEBUG_MSG("Wrong config (%d, %d)\r\n", svGetV<int>(F("mode"), nullptr, F(WIFICFG_FILE)), WiFi.getMode());
|
||||
_status = 0xfe;
|
||||
result = _setupAP(cb);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode))) {
|
||||
switch (svGetV<int>(F("mode"), nullptr, F(WIFICFG_FILE))) {
|
||||
case WIFIMODE_STA: {
|
||||
#if defined(ESP8266)
|
||||
WiFi.hostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||
#else
|
||||
WiFi.setHostname(WiFiDeviceName);
|
||||
#endif
|
||||
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip))) {
|
||||
DEBUG_MSG("Static configuration SET.\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))));
|
||||
}
|
||||
|
||||
DEBUG_MSG("STA mode.\r\n");
|
||||
SETHOSTNAME(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||
if (IPCONFIG_STATIC == svGetV<int>(F("ipmode"), nullptr, F(WIFICFG_FILE))) {
|
||||
|
||||
DEBUG_MSG("Static configuration SET.\r\n");
|
||||
WiFi.config(IPAddress(svGetV<uint32_t>(F("ip"), nullptr, F(WIFICFG_FILE))), IPAddress(svGetV<uint32_t>(F("gw"), nullptr, F(WIFICFG_FILE))),
|
||||
IPAddress(svGetV<uint32_t>(F("mask"), nullptr, F(WIFICFG_FILE))), IPAddress(svGetV<uint32_t>(F("dns"), nullptr, F(WIFICFG_FILE))));
|
||||
delay(100);
|
||||
}
|
||||
if (WC_DONT_RUN_CONFIGAP == _timeout)
|
||||
result = WCR_CONFIGAP_NOT_STARTED; // nemame spoustet konfiguracni AP - vracime se hned
|
||||
else {
|
||||
@ -907,10 +814,11 @@ wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, wificon
|
||||
break;
|
||||
|
||||
case WIFIMODE_AP:
|
||||
|
||||
DEBUG_MSG("AP mode.\r\n");
|
||||
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip))) {
|
||||
WiFi.softAPConfig(IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway))),
|
||||
IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask))));
|
||||
if (IPCONFIG_STATIC == svGetV<int>(F("ipmode"), nullptr, F(WIFICFG_FILE))) {
|
||||
WiFi.softAPConfig(IPAddress(svGetV<uint32_t>(F("ip"), nullptr, F(WIFICFG_FILE))), IPAddress(svGetV<uint32_t>(F("gw"), nullptr, F(WIFICFG_FILE))),
|
||||
IPAddress(svGetV<uint32_t>(F("mask"), nullptr, F(WIFICFG_FILE))));
|
||||
}
|
||||
if (cb)
|
||||
cb(WCS_CONNECTED); // signalizujeme pripojeni (zde se nic jineho stejne nestane...)
|
||||
@ -918,7 +826,8 @@ wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, wificon
|
||||
|
||||
#if !defined(ESP8266)
|
||||
default:
|
||||
DEBUG_MSG("Wrong config (%d)\r\n", EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)));
|
||||
|
||||
DEBUG_MSG("Wrong config (%d)\r\n", svGetV<int>(F("mode"), nullptr, F(WIFICFG_FILE)));
|
||||
_status = 0xfe;
|
||||
result = _setupAP(cb);
|
||||
break;
|
||||
@ -929,7 +838,7 @@ wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, wificon
|
||||
return result; // mame vyreseno
|
||||
}
|
||||
|
||||
wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, int timeout, wificonfig_cb cb = NULL)
|
||||
wificonfigresult_t WiFiConfig::begin(int forceConfigure, int timeout, wificonfig_cb cb = NULL)
|
||||
{
|
||||
|
||||
if ((timeout > 0) && (40 > timeout))
|
||||
@ -939,6 +848,109 @@ wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, int tim
|
||||
_timeout = timeout;
|
||||
if (_timeout > 0)
|
||||
_time = millis() + (_timeout * 1000); // spocitame si novy cas, kdy budeme modul restartovat
|
||||
return begin(configarea, forceConfigure, cb); // spustime WiFi
|
||||
return begin(forceConfigure, cb); // spustime WiFi
|
||||
}
|
||||
|
||||
void WiFiConfig::initConfig(const String &ssid, const String &pass, const int mode, const int ipcfg, const IPAddress &ip, const IPAddress &mask, const IPAddress &gw, const IPAddress &dns)
|
||||
{
|
||||
String es;
|
||||
|
||||
DEBUG_MSG("initConfig %d\r\n", mode);
|
||||
es = ssid;
|
||||
strEncode(es);
|
||||
svSetV<String>(F("ssid"), es, F(WIFICFG_FILE));
|
||||
es = pass;
|
||||
strEncode(es);
|
||||
svSetV<String>(F("pass"), es, F(WIFICFG_FILE));
|
||||
svSetV(F("mode"), mode, F(WIFICFG_FILE));
|
||||
svSetV(F("ipmode"), ipcfg, F(WIFICFG_FILE));
|
||||
svSetV<int>(F("channel"), 3, F(WIFICFG_FILE));
|
||||
svSetV<uint32_t>(F("ip"), (uint32_t)ip, F(WIFICFG_FILE));
|
||||
svSetV<uint32_t>(F("mask"), (uint32_t)mask, F(WIFICFG_FILE));
|
||||
svSetV<uint32_t>(F("gw"), (uint32_t)gw, F(WIFICFG_FILE));
|
||||
svSetV<uint32_t>(F("dns"), (uint32_t)dns, F(WIFICFG_FILE));
|
||||
_prepareWifi(); // nastavime novou WiFi konfiguraci
|
||||
}
|
||||
|
||||
void WiFiConfig::_prepareWifi(void)
|
||||
{
|
||||
|
||||
WiFi.persistent(true); // chceme, aby si modul zapamatoval konfiguraci
|
||||
WiFi.disconnect(); // vsechno odpojime
|
||||
delay(100);
|
||||
|
||||
String s = svGetV<String>(F("ssid"), nullptr, F(WIFICFG_FILE));
|
||||
strDecode(s);
|
||||
String pass = svGetV<String>(F("pass"), nullptr, F(WIFICFG_FILE));
|
||||
strDecode(pass);
|
||||
int mode = svGetV<int>(F("mode"), nullptr, F(WIFICFG_FILE));
|
||||
|
||||
switch (mode) {
|
||||
case WIFIMODE_STA: {
|
||||
|
||||
DEBUG_MSG("STA mode.\r\n");
|
||||
#if defined(ESP8266)
|
||||
if (strlen(WiFiDeviceName)) {
|
||||
SETHOSTNAME(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||
}
|
||||
#endif
|
||||
if (IPCONFIG_STATIC == svGetV<int>(F("ipmode"), nullptr, F(WIFICFG_FILE))) {
|
||||
|
||||
DEBUG_MSG("Static configuration.\r\n");
|
||||
WiFi.config(IPAddress(svGetV<uint32_t>(F("ip"), nullptr, F(WIFICFG_FILE))), IPAddress(svGetV<uint32_t>(F("gw"), nullptr, F(WIFICFG_FILE))),
|
||||
IPAddress(svGetV<uint32_t>(F("mask"), nullptr, F(WIFICFG_FILE))), IPAddress(svGetV<uint32_t>(F("dns"), nullptr, F(WIFICFG_FILE))));
|
||||
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(ESP8266)
|
||||
if (strlen(WiFiDeviceName)) {
|
||||
SETHOSTNAME(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||
}
|
||||
#endif
|
||||
#if defined(ESP8266)
|
||||
WiFi.setAutoConnect(true);
|
||||
WiFi.setAutoReconnect(true);
|
||||
// wifi_station_set_auto_connect(true);
|
||||
#else
|
||||
//esp_wifi_set_auto_connect(true);
|
||||
#endif
|
||||
delay(1000);
|
||||
}
|
||||
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
|
||||
int chan = svGetV<int>(F("channel"), nullptr, F(WIFICFG_FILE));
|
||||
if (pass.length()) {
|
||||
// je zadane heslo do AP
|
||||
WiFi.softAP(s.c_str(), pass.c_str(), chan);
|
||||
} else {
|
||||
// otevreny AP
|
||||
WiFi.softAP(s.c_str(), NULL, chan);
|
||||
}
|
||||
if (IPCONFIG_STATIC == svGetV<int>(F("ipmode"), nullptr, F(WIFICFG_FILE))) {
|
||||
delay(100); // kvuli ESP32 - cekame na start AP
|
||||
WiFi.softAPConfig(IPAddress(svGetV<uint32_t>(F("ip"), nullptr, F(WIFICFG_FILE))), IPAddress(svGetV<uint32_t>(F("gw"), nullptr, F(WIFICFG_FILE))),
|
||||
IPAddress(svGetV<uint32_t>(F("mask"), nullptr, F(WIFICFG_FILE))));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: // jakykoliv neznamy rezim (mozna zavada na EEPROM???)
|
||||
|
||||
DEBUG_MSG("Mode Error (%d)!!\r\n", (int)mode);
|
||||
break;
|
||||
}
|
||||
delay(1000); // cekame XX sekund na ulozeni atd...
|
||||
}
|
||||
// EOF
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file WiFiConfig.h
|
||||
* @author Pavel Brychta, http://www.xpablo.cz
|
||||
*
|
||||
* Copyright (c) 2015-20 Pavel Brychta. All rights reserved.
|
||||
* Copyright (c) 2015-21 Pavel Brychta. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@ -31,29 +31,14 @@
|
||||
#define __WiFiConfig_h__
|
||||
|
||||
#if defined(ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
# include <ESP8266WiFi.h>
|
||||
#else
|
||||
#include <WiFi.h>
|
||||
# include <WiFi.h>
|
||||
#endif
|
||||
#include <memory>
|
||||
|
||||
#define elementSize(type, element) sizeof(((type *)0)->element)
|
||||
|
||||
#define WC_DONT_RUN_CONFIGAP -1 // priznak, ze si neprejeme spoustet konfiguracni AP (uziva se misto parametru timeout). Urceno pro bateriove napajene pristroje
|
||||
|
||||
// Struktura konfigurace, ulozena v EEPROM
|
||||
typedef struct {
|
||||
uint8_t mode; // rezim prace AP/STA
|
||||
uint8_t ip; // konfigurace ip (staticka/DHCP)
|
||||
char ssid[32 + 2]; // SSID site
|
||||
char pass[64 + 2]; // heslo
|
||||
uint32_t ipaddr; // ip adresa v pripade staticke konfigurace
|
||||
uint32_t netmask; // sitova maska v pripade staticke konfigurace
|
||||
uint32_t gateway; // sitova brana v pripade staticke konfigurace
|
||||
uint32_t dns; // ip adresa DNS serveru v pripade staticke konfigurace
|
||||
uint8_t apchannel; // kanal, na kterem pracuje AP (pokud je zapnuty rezim AP)
|
||||
} wificonfigarea_t;
|
||||
|
||||
// Parametr, predany uzivatelske callback funkci, urceny pro aplikacni vizualizaci stavu konfigurace a pripojeni
|
||||
typedef enum {
|
||||
WCS_CONNECTSTART = 0, // zacatek pokusu o pripojeni k ulozene konfiguraci
|
||||
@ -71,6 +56,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
|
||||
@ -87,24 +85,6 @@ typedef void (*storeparam_cb)(const char *newvalue); // callback pro ulozeni uzi
|
||||
# define SETUP_CHANNEL 3
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Ziskani retezce z EEPROM ze zadaneho offsetu
|
||||
*
|
||||
* \param [in] start Ofset zacatku retezce
|
||||
* \param [in] len Delka retezce
|
||||
* \return Vycteny retezec
|
||||
*/
|
||||
String getEEPROMString(unsigned int start, size_t len);
|
||||
|
||||
/**
|
||||
* \brief Ulozeni retezce do EEPROM
|
||||
*
|
||||
* \param [in] start Ofset zacatku ukladani
|
||||
* \param [in] len Maximalni delka ulozeneho retezce
|
||||
* \param [in] string Ukladany retezec
|
||||
*/
|
||||
void setEEPROMString(unsigned int start, size_t len, String &string);
|
||||
|
||||
/**
|
||||
* \brief Ziskani nasi ip adresy
|
||||
*
|
||||
@ -122,23 +102,6 @@ IPAddress getOurIP(void);
|
||||
*/
|
||||
uint8_t * getOurMAC(uint8_t *mac);
|
||||
|
||||
/**
|
||||
* @brief Ziskani 32 bitoveho cisla z EEPROM
|
||||
*
|
||||
* @param[in] start Pocatecni adresa, ze ktere se ziskava cislo.
|
||||
*
|
||||
* @return Ziskane cislo.
|
||||
*/
|
||||
uint32_t getEEPROMuint32(int start);
|
||||
|
||||
/**
|
||||
* @brief Ulozeni 32 bitoveho cisla do EEPROM
|
||||
*
|
||||
* @param[in] start Pocatecni adresa, kam cislo ukladame.
|
||||
* @param[in] val Ukladana hodnota
|
||||
*/
|
||||
void setEEPROMuint32(int start, uint32_t val);
|
||||
|
||||
class WiFiConfigUsrParameter
|
||||
{
|
||||
public:
|
||||
@ -167,10 +130,13 @@ class WiFiConfig
|
||||
{
|
||||
public:
|
||||
WiFiConfig(): _params(NULL), _timeout(0) {}
|
||||
wificonfigresult_t begin(int configarea, int forceConfigure, wificonfig_cb cb);
|
||||
wificonfigresult_t begin(int configarea, int forceConfigure, int timeout, wificonfig_cb cb);
|
||||
wificonfigresult_t begin(int forceConfigure, wificonfig_cb cb);
|
||||
wificonfigresult_t begin(int forceConfigure, int timeout, wificonfig_cb cb);
|
||||
void addParameter(WiFiConfigUsrParameter *p);
|
||||
void initConfig(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:
|
||||
void _prepareWifi(void);
|
||||
wificonfigresult_t _setupAP(wificonfig_cb cb);
|
||||
void _handleDisplayAP(void);
|
||||
void _handleSetAP(void);
|
||||
@ -179,8 +145,6 @@ private:
|
||||
void _handleNotFound(); // CaptivePortal redirector
|
||||
void _handleRoot(); // jen jednoducha stranka kvuli CaptivePortalu umoznuje prejit na spravnou stranku (ale nedela to...)
|
||||
bool _testWifi(wificonfig_cb cb);
|
||||
bool _storeString(unsigned int start, size_t maxlen, String &string); // sifrovany retezec, max 255 znaku
|
||||
String _readString(unsigned int start, size_t maxlen); // sifrovany retezec, max. 255 znaku
|
||||
WiFiConfigUsrParameter *_searchUsrParameter(const char *name);
|
||||
|
||||
WiFiConfigUsrParameter *_params; // ukazatel na posledni zadany uzivatelsky parametr
|
||||
@ -188,4 +152,5 @@ 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
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,10 +1,18 @@
|
||||
// HTML data
|
||||
#ifndef WIFICONFIG_WEBTITLE
|
||||
# define WIFICONFIG_WEBTITLE "xPablo.cz Setup"
|
||||
#endif
|
||||
|
||||
#ifndef WIFICONFIG_TITLE
|
||||
# define WIFICONFIG_TITLE "ESP WiFiConfig"
|
||||
#endif
|
||||
|
||||
static const char TEXTHTML[] PROGMEM = "text/html";
|
||||
static const char TEXTPLAIN[] PROGMEM = "text/plain";
|
||||
|
||||
static const char PAGE_INDEX1[] PROGMEM = R"=====(
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset= "utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
<title>xPablo.cz Setup</title>
|
||||
<title>)=====" WIFICONFIG_WEBTITLE R"=====(</title>
|
||||
<style>
|
||||
.c{text-align: center;}
|
||||
div,input{padding:5px;font-size:1em;}
|
||||
@ -21,7 +29,7 @@ function c(l){document.getElementById('_s').value=l.innerText||l.textContent;doc
|
||||
function hAP(){if (document.getElementById('_a').checked){document.getElementById('apconfig').style.display = 'block';}else{document.getElementById('apconfig').style.display = 'none';}}
|
||||
function hSC(){if (document.getElementById('_st').checked){document.getElementById('staticip').style.display = 'block';}else{document.getElementById('staticip').style.display = 'none';}}
|
||||
</script>
|
||||
</head><body><h1>ESP WiFiConfig</h1><div style='text-align:left;display:inline-block;min-width:260px;'>
|
||||
</head><body><h1>)=====" WIFICONFIG_TITLE R"=====(</h1><div style='text-align:left;display:inline-block;min-width:260px;'>
|
||||
)=====";
|
||||
|
||||
/* Polozky nalezenych SSID
|
||||
|
Reference in New Issue
Block a user