Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
6f845e1e45 | |||
170af78f28 | |||
dd4204c7a1 | |||
4cdce88ca5 | |||
6f1dd6a7ba | |||
11aaf8450f | |||
2353bfa617 | |||
7ea5b222ad | |||
f42c8a1bf3 | |||
8d709429e0 | |||
e83160d3d2 | |||
baef6c322e | |||
349bc68180 | |||
8a95f6d69b | |||
26a65f00ac | |||
48f3d58f7e | |||
304618c722 | |||
c6f3e3371c |
@ -1,16 +1,21 @@
|
|||||||
#include <ESP8266WiFi.h>
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
#include <ESP8266WebServer.h>
|
# include <ESP8266WiFi.h>
|
||||||
|
# include <ESP8266WebServer.h>
|
||||||
|
# include <ESP8266NetBIOS.h>
|
||||||
|
#else
|
||||||
|
# include <WiFi.h>
|
||||||
|
# include <WebServer.h>
|
||||||
|
# include <NetBIOS.h>
|
||||||
|
#endif
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include <ESP8266NetBIOS.h>
|
|
||||||
#include <WiFiConfig.h>
|
#include <WiFiConfig.h>
|
||||||
#include <encipheredEEPROMStrings.h>
|
#include <encipheredEEPROMStrings.h>
|
||||||
|
|
||||||
|
#define EEPROM_MAGIC 0xdeadbeef
|
||||||
|
|
||||||
// Plati pro desticku Witty s modulem ESP-12E
|
// Plati pro desticku Witty s modulem ESP-12E
|
||||||
#define PIN_FORCE_CONFIG 4
|
#define PIN_FORCE_CONFIG 4
|
||||||
#define PIN_LED_RED 15
|
|
||||||
#define PIN_LED_GREEN 12
|
|
||||||
#define PIN_LED_BLUE 13
|
|
||||||
|
|
||||||
//#define DEBUG_OUT(a) {}
|
//#define DEBUG_OUT(a) {}
|
||||||
#define DEBUG_OUT(a) Serial.print(a)
|
#define DEBUG_OUT(a) Serial.print(a)
|
||||||
@ -18,8 +23,8 @@
|
|||||||
// Definice obsazeni EEPROM
|
// Definice obsazeni EEPROM
|
||||||
#define elementSize(type, element) sizeof(((type *)0)->element)
|
#define elementSize(type, element) sizeof(((type *)0)->element)
|
||||||
#define countof(a) (sizeof(a) / sizeof(a[0]))
|
#define countof(a) (sizeof(a) / sizeof(a[0]))
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
uint32_t magic; // kontrola spravneho obsahu EEPROM
|
||||||
char devname[32 + 2]; // jmeno zarizeni (pro NBNS plati jen 16 znaku)
|
char devname[32 + 2]; // jmeno zarizeni (pro NBNS plati jen 16 znaku)
|
||||||
} eepromconfig_t;
|
} eepromconfig_t;
|
||||||
|
|
||||||
@ -28,7 +33,11 @@ typedef struct
|
|||||||
#define EEPROM_CONFIG_ORIGIN (0)
|
#define EEPROM_CONFIG_ORIGIN (0)
|
||||||
|
|
||||||
char WiFiDeviceName[elementSize(eepromconfig_t, devname)]; // misto pro jmeno zarizeni (dodane do DNS, DHCP NBNS apod...)
|
char WiFiDeviceName[elementSize(eepromconfig_t, devname)]; // misto pro jmeno zarizeni (dodane do DNS, DHCP NBNS apod...)
|
||||||
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
ESP8266WebServer wwwserver(80); // webovy server
|
ESP8266WebServer wwwserver(80); // webovy server
|
||||||
|
#else
|
||||||
|
WebServer wwwserver(80); // webovy server
|
||||||
|
#endif
|
||||||
String content;
|
String content;
|
||||||
|
|
||||||
static void handleRoot(void)
|
static void handleRoot(void)
|
||||||
@ -44,8 +53,7 @@ static void handleRoot(void)
|
|||||||
void ICACHE_FLASH_ATTR wcb(wificonfigstate_t state)
|
void ICACHE_FLASH_ATTR wcb(wificonfigstate_t state)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (state)
|
switch (state) {
|
||||||
{
|
|
||||||
case WCS_CONNECTSTART:
|
case WCS_CONNECTSTART:
|
||||||
DEBUG_OUT(F("Starting connect...\r\n"));
|
DEBUG_OUT(F("Starting connect...\r\n"));
|
||||||
break;
|
break;
|
||||||
@ -63,6 +71,10 @@ void ICACHE_FLASH_ATTR wcb(wificonfigstate_t state)
|
|||||||
|
|
||||||
case WCS_CONFIGWAIT:
|
case WCS_CONFIGWAIT:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WCS_CONFIGTIMEOUT:
|
||||||
|
DEBUG_OUT(F("Config timeout...\r\n"));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,9 +91,22 @@ void ICACHE_FLASH_ATTR setup()
|
|||||||
WiFiConfigUsrParameter devname("devname", "Jméno zařízení", (const char *)WiFiDeviceName, 32, saveDevname);
|
WiFiConfigUsrParameter devname("devname", "Jméno zařízení", (const char *)WiFiDeviceName, 32, saveDevname);
|
||||||
|
|
||||||
EEPROM.begin(EEPROM_SIZE); // zahajujeme praci s EEPROM
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
pinMode(PIN_FORCE_CONFIG, INPUT_PULLUP); // pin, co slouzi jako vstup tlacitka
|
pinMode(PIN_FORCE_CONFIG, INPUT_PULLUP); // pin, co slouzi jako vstup tlacitka
|
||||||
int fc = digitalRead(PIN_FORCE_CONFIG); // pozadavek na vynucene vyvolani konfigurace
|
int fc = digitalRead(PIN_FORCE_CONFIG); // pozadavek na vynucene vyvolani konfigurace
|
||||||
Serial.begin(9600);
|
Serial.begin(115200);
|
||||||
String dn = EES_readString(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, devname), elementSize(eepromconfig_t, devname));
|
String dn = EES_readString(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, devname), elementSize(eepromconfig_t, devname));
|
||||||
strcpy(WiFiDeviceName, dn.c_str());
|
strcpy(WiFiDeviceName, dn.c_str());
|
||||||
wifi.addParameter(&devname);
|
wifi.addParameter(&devname);
|
||||||
@ -92,8 +117,7 @@ void ICACHE_FLASH_ATTR setup()
|
|||||||
wwwserver.on("/", handleRoot);
|
wwwserver.on("/", handleRoot);
|
||||||
wwwserver.begin(); // startujeme webovy server
|
wwwserver.begin(); // startujeme webovy server
|
||||||
|
|
||||||
if (strlen(WiFiDeviceName) > 0)
|
if (strlen(WiFiDeviceName) > 0) {
|
||||||
{
|
|
||||||
NBNS.begin(WiFiDeviceName);
|
NBNS.begin(WiFiDeviceName);
|
||||||
ArduinoOTA.setHostname(WiFiDeviceName);
|
ArduinoOTA.setHostname(WiFiDeviceName);
|
||||||
}
|
}
|
||||||
@ -108,8 +132,7 @@ void ICACHE_FLASH_ATTR setup()
|
|||||||
DEBUG_OUT(F("Error["));
|
DEBUG_OUT(F("Error["));
|
||||||
DEBUG_OUT(error);
|
DEBUG_OUT(error);
|
||||||
DEBUG_OUT(F("]: "));
|
DEBUG_OUT(F("]: "));
|
||||||
switch (error)
|
switch (error) {
|
||||||
{
|
|
||||||
case OTA_AUTH_ERROR:
|
case OTA_AUTH_ERROR:
|
||||||
DEBUG_OUT(F("Auth Failed\r\n"));
|
DEBUG_OUT(F("Auth Failed\r\n"));
|
||||||
break;
|
break;
|
||||||
|
@ -10,9 +10,9 @@
|
|||||||
"repository":
|
"repository":
|
||||||
{
|
{
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://git.xpablo.cz/pablo2048/WiFiConfig.git"
|
"url": "https://git.xpablo.cz/pablo2048/WiFiConfig.git"
|
||||||
},
|
},
|
||||||
"version": "6.3.1",
|
"version": "6.4.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": ["espressif8266", "espressif32"],
|
"platforms": ["espressif8266", "espressif32"],
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
name=WiFiConfig
|
name=WiFiConfig
|
||||||
version=6.3.1
|
version=6.4.0
|
||||||
author=Pavel Brychta
|
author=Pavel Brychta
|
||||||
maintainer=Pavel Brychta <Pablo@xpablo.cz>
|
maintainer=Pavel Brychta <pablo@xpablo.cz>
|
||||||
sentence=Enables seamless module configuration.
|
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.
|
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
|
category=Other
|
||||||
url=http://www.xpablo.cz
|
url=https://www.xpablo.cz
|
||||||
architectures=esp8266,esp32
|
architectures=esp8266,esp32
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
* v6.3.2- 4.10.2019 - Informace o aplikaci a jeji verzi do footeru, zrychlen restart z 10 na 5 sekund, vylepsena stranka pro reset
|
* v6.3.2- 4.10.2019 - Informace o aplikaci a jeji verzi do footeru, zrychlen restart z 10 na 5 sekund, vylepsena stranka pro reset
|
||||||
* verze pro ESP32 zobrazuje neco malo informaci o stavu pripojeni a duvodu vstupu do WifiConfig
|
* verze pro ESP32 zobrazuje neco malo informaci o stavu pripojeni a duvodu vstupu do WifiConfig
|
||||||
*
|
*
|
||||||
@ -84,10 +92,10 @@
|
|||||||
|
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
#include <ESP8266WebServer.h>
|
# include <ESP8266WebServer.h>
|
||||||
#else
|
#else
|
||||||
#include <WebServer.h>
|
# include <WebServer.h>
|
||||||
#include <rom/rtc.h> // duvod resetu (https://github.com/espressif/arduino-esp32/issues/449)
|
# include <rom/rtc.h> // duvod resetu (https://github.com/espressif/arduino-esp32/issues/449)
|
||||||
#endif
|
#endif
|
||||||
#include "WiFiConfig.h"
|
#include "WiFiConfig.h"
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
@ -95,39 +103,34 @@
|
|||||||
#include <encipheredEEPROMStrings.h>
|
#include <encipheredEEPROMStrings.h>
|
||||||
#include "embHTML.h"
|
#include "embHTML.h"
|
||||||
|
|
||||||
#ifdef DEBUG_ESP_PORT
|
#if defined(ESP8266)
|
||||||
#define DEBUG_MSG(_1, ...) DEBUG_ESP_PORT.printf_P(PSTR(_1), ##__VA_ARGS__)
|
// ESP8266
|
||||||
|
# define SETHOSTNAME(a) WiFi.hostname(a)
|
||||||
#else
|
#else
|
||||||
#define DEBUG_MSG(...)
|
// 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
|
||||||
|
# define DEBUG_MSG(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "user_interface.h"
|
# include "user_interface.h"
|
||||||
}
|
}
|
||||||
#define ESP_getChipId() (ESP.getChipId())
|
# define ESP_getChipId() (ESP.getChipId())
|
||||||
#else
|
#else
|
||||||
#include <esp_wifi.h>
|
# include <esp_wifi.h>
|
||||||
#define ESP_getChipId() ((uint32_t)ESP.getEfuseMac())
|
# define ESP_getChipId() ((uint32_t)ESP.getEfuseMac())
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DNS_PORT 53
|
#define DNS_PORT 53
|
||||||
|
|
||||||
extern char WiFiDeviceName[];
|
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 int configBase; // musi byt trvale ulozene, aby fungovaly metody pro ziskani retezcu z EEPROM
|
||||||
|
|
||||||
static std::unique_ptr<DNSServer> dnsServer;
|
static std::unique_ptr<DNSServer> dnsServer;
|
||||||
@ -146,8 +149,7 @@ IPAddress getOurIP(void)
|
|||||||
IPAddress ipa;
|
IPAddress ipa;
|
||||||
WiFiMode_t wm = WiFi.getMode();
|
WiFiMode_t wm = WiFi.getMode();
|
||||||
|
|
||||||
switch (wm)
|
switch (wm) {
|
||||||
{
|
|
||||||
case WIFI_STA:
|
case WIFI_STA:
|
||||||
ipa = WiFi.localIP();
|
ipa = WiFi.localIP();
|
||||||
break;
|
break;
|
||||||
@ -176,8 +178,7 @@ uint32_t getEEPROMuint32(unsigned int start)
|
|||||||
{
|
{
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 4; ++i)
|
for (uint32_t i = 0; i < 4; ++i) {
|
||||||
{
|
|
||||||
result <<= 8;
|
result <<= 8;
|
||||||
result += EEPROM.read(start);
|
result += EEPROM.read(start);
|
||||||
++start;
|
++start;
|
||||||
@ -188,8 +189,7 @@ uint32_t getEEPROMuint32(unsigned int start)
|
|||||||
void setEEPROMuint32(unsigned int start, uint32_t val)
|
void setEEPROMuint32(unsigned int start, uint32_t val)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 4; ++i)
|
for (unsigned int i = 0; i < 4; ++i) {
|
||||||
{
|
|
||||||
EEPROM.write(start + 3 - i, (uint8_t)val);
|
EEPROM.write(start + 3 - i, (uint8_t)val);
|
||||||
val >>= 8;
|
val >>= 8;
|
||||||
}
|
}
|
||||||
@ -199,8 +199,7 @@ String getEEPROMString(unsigned int start, size_t len)
|
|||||||
{
|
{
|
||||||
String string = "";
|
String string = "";
|
||||||
|
|
||||||
for (unsigned int i = start; i < + start + len; ++i)
|
for (unsigned int i = start; i < + start + len; ++i) {
|
||||||
{
|
|
||||||
uint8_t b = EEPROM.read(i);
|
uint8_t b = EEPROM.read(i);
|
||||||
|
|
||||||
if ((0xff == b) || (0 == b))
|
if ((0xff == b) || (0 == b))
|
||||||
@ -214,16 +213,12 @@ void setEEPROMString(unsigned int start, size_t len, String &string)
|
|||||||
{
|
{
|
||||||
unsigned int si = 0;
|
unsigned int si = 0;
|
||||||
|
|
||||||
for (unsigned int i = start; i < start + len; ++i)
|
for (unsigned int i = start; i < start + len; ++i) {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
if (si < string.length())
|
if (si < string.length()) {
|
||||||
{
|
|
||||||
c = string[si];
|
c = string[si];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
c = 0;
|
c = 0;
|
||||||
}
|
}
|
||||||
EEPROM.write(i, c);
|
EEPROM.write(i, c);
|
||||||
@ -239,12 +234,10 @@ WiFiConfigUsrParameter::WiFiConfigUsrParameter(const char *id, const char *label
|
|||||||
_label = label;
|
_label = label;
|
||||||
_length = length;
|
_length = length;
|
||||||
_value = new char[length + 1];
|
_value = new char[length + 1];
|
||||||
for (unsigned int i = 0; i < length; i++)
|
for (unsigned int i = 0; i < length; i++) {
|
||||||
{
|
|
||||||
_value[i] = 0;
|
_value[i] = 0;
|
||||||
}
|
}
|
||||||
if (defaultValue != NULL)
|
if (defaultValue != NULL) {
|
||||||
{
|
|
||||||
strncpy(_value, defaultValue, length);
|
strncpy(_value, defaultValue, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,8 +289,7 @@ WiFiConfigUsrParameter *WiFiConfig::_searchUsrParameter(const char *name)
|
|||||||
{
|
{
|
||||||
WiFiConfigUsrParameter *ptr = _params;
|
WiFiConfigUsrParameter *ptr = _params;
|
||||||
|
|
||||||
while (NULL != ptr)
|
while (NULL != ptr) {
|
||||||
{
|
|
||||||
if (0 == strcmp(name, ptr->getID()))
|
if (0 == strcmp(name, ptr->getID()))
|
||||||
break;
|
break;
|
||||||
ptr = ptr->getNext();
|
ptr = ptr->getNext();
|
||||||
@ -316,12 +308,9 @@ void WiFiConfig::_handleNotFound(void)
|
|||||||
|
|
||||||
DEBUG_MSG("Requested URI: %s\r\n", server->uri().c_str());
|
DEBUG_MSG("Requested URI: %s\r\n", server->uri().c_str());
|
||||||
|
|
||||||
if (server->uri().endsWith(String(F("favicon.ico"))))
|
if (server->uri().endsWith(String(F("favicon.ico")))) {
|
||||||
{
|
|
||||||
server->send_P(404, TEXTPLAIN, PSTR("Err"));
|
server->send_P(404, TEXTPLAIN, PSTR("Err"));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
String redirect;
|
String redirect;
|
||||||
redirect.reserve(256);
|
redirect.reserve(256);
|
||||||
redirect = F("http://");
|
redirect = F("http://");
|
||||||
@ -338,8 +327,7 @@ void WiFiConfig::_handleReset(void)
|
|||||||
|
|
||||||
rsttick.reset(new(Ticker));
|
rsttick.reset(new(Ticker));
|
||||||
|
|
||||||
rsttick->once_ms(700, []()
|
rsttick->once_ms(700, []() {
|
||||||
{
|
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -423,8 +411,7 @@ void WiFiConfig::_handleRoot(void)
|
|||||||
// pridame informaci o stavu pokusu o pripojeni
|
// pridame informaci o stavu pokusu o pripojeni
|
||||||
content.concat(F("<div class=\"vl-info\">Pokus o připojení: "));
|
content.concat(F("<div class=\"vl-info\">Pokus o připojení: "));
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
switch (_status)
|
switch (_status) {
|
||||||
{
|
|
||||||
case STATION_IDLE:
|
case STATION_IDLE:
|
||||||
content.concat(F("Klid"));
|
content.concat(F("Klid"));
|
||||||
break;
|
break;
|
||||||
@ -462,8 +449,7 @@ void WiFiConfig::_handleRoot(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
switch (_status)
|
switch (_status) {
|
||||||
{
|
|
||||||
case WL_CONNECT_FAILED:
|
case WL_CONNECT_FAILED:
|
||||||
content.concat(F("Připojení selhalo"));
|
content.concat(F("Připojení selhalo"));
|
||||||
break;
|
break;
|
||||||
@ -497,14 +483,10 @@ void WiFiConfig::_handleDisplayAP(void)
|
|||||||
content.reserve(3000);
|
content.reserve(3000);
|
||||||
content = FPSTR(PAGE_INDEX1);
|
content = FPSTR(PAGE_INDEX1);
|
||||||
int n = WiFi.scanNetworks();
|
int n = WiFi.scanNetworks();
|
||||||
if (0 == n)
|
if (0 == n) {
|
||||||
{
|
|
||||||
content.concat(FPSTR(PAGE_NO_SSID));
|
content.concat(FPSTR(PAGE_NO_SSID));
|
||||||
}
|
} else {
|
||||||
else
|
for (int i = 0; i < n; ++i) {
|
||||||
{
|
|
||||||
for (int i = 0; i < n; ++i)
|
|
||||||
{
|
|
||||||
int quality;
|
int quality;
|
||||||
|
|
||||||
if (WiFi.RSSI(i) <= -100)
|
if (WiFi.RSSI(i) <= -100)
|
||||||
@ -557,15 +539,13 @@ void WiFiConfig::_handleDisplayAP(void)
|
|||||||
content.concat(s);
|
content.concat(s);
|
||||||
|
|
||||||
// Uzivatelske parametry
|
// Uzivatelske parametry
|
||||||
if (_params)
|
if (_params) {
|
||||||
{
|
|
||||||
content.concat(FPSTR(PAGE_PARAM_HDR));
|
content.concat(FPSTR(PAGE_PARAM_HDR));
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFiConfigUsrParameter *up = _params;
|
WiFiConfigUsrParameter *up = _params;
|
||||||
|
|
||||||
while (NULL != up)
|
while (NULL != up) {
|
||||||
{
|
|
||||||
s = FPSTR(PAGE_PARAM);
|
s = FPSTR(PAGE_PARAM);
|
||||||
s.replace(F("{t}"), up->getLabel());
|
s.replace(F("{t}"), up->getLabel());
|
||||||
s.replace(F("{n}"), up->getID());
|
s.replace(F("{n}"), up->getID());
|
||||||
@ -586,29 +566,26 @@ void WiFiConfig::_handleSetAP(void)
|
|||||||
|
|
||||||
str.reserve(128);
|
str.reserve(128);
|
||||||
str = server->arg(F("_s"));
|
str = server->arg(F("_s"));
|
||||||
if (str.length() > 0)
|
if (str.length() > 0) {
|
||||||
{
|
|
||||||
EES_storeString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid), str);
|
EES_storeString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid), str);
|
||||||
|
|
||||||
str = server->arg(F("_p"));
|
str = server->arg(F("_p"));
|
||||||
EES_storeString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass), str);
|
EES_storeString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass), str);
|
||||||
|
|
||||||
str = server->arg(F("_a"));
|
str = server->arg(F("_a"));
|
||||||
if (str.length() > 0)
|
if (str.length() > 0) {
|
||||||
{
|
|
||||||
mode = WIFIMODE_AP; // rezim AP
|
mode = WIFIMODE_AP; // rezim AP
|
||||||
str = server->arg(F("_ch")); // kanal AP
|
str = server->arg(F("_ch")); // kanal AP
|
||||||
EEPROM.write(configBase + offsetof(wificonfigarea_t, apchannel), (uint8_t)str.toInt());
|
EEPROM.write(configBase + offsetof(wificonfigarea_t, apchannel), (uint8_t)str.toInt());
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
mode = WIFIMODE_STA; // rezim STA
|
mode = WIFIMODE_STA; // rezim STA
|
||||||
EEPROM.write(configBase + offsetof(wificonfigarea_t, mode), mode);
|
EEPROM.write(configBase + offsetof(wificonfigarea_t, mode), mode);
|
||||||
|
|
||||||
str = server->arg(F("_st"));
|
str = server->arg(F("_st"));
|
||||||
if (0 == str.length())
|
if (0 == str.length())
|
||||||
EEPROM.write(configBase + offsetof(wificonfigarea_t, ip), IPCONFIG_DHCP); // mame DHCP dynamickou konfiguraci
|
EEPROM.write(configBase + offsetof(wificonfigarea_t, ip), IPCONFIG_DHCP); // mame DHCP dynamickou konfiguraci
|
||||||
else
|
else {
|
||||||
{ // staticka ip konfigurace
|
// staticka ip konfigurace
|
||||||
IPAddress ipa;
|
IPAddress ipa;
|
||||||
|
|
||||||
EEPROM.write(configBase + offsetof(wificonfigarea_t, ip), IPCONFIG_STATIC);
|
EEPROM.write(configBase + offsetof(wificonfigarea_t, ip), IPCONFIG_STATIC);
|
||||||
@ -630,10 +607,8 @@ void WiFiConfig::_handleSetAP(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Uzivatelske parametry
|
// Uzivatelske parametry
|
||||||
for (int i = 0; i < server->args(); i++)
|
for (int i = 0; i < server->args(); i++) {
|
||||||
{
|
if (!server->argName(i).startsWith(F("_"))) { // vnitrni parametry WiFiConfig modulu zacinaji _, takze ty muzeme ignorovat
|
||||||
if (!server->argName(i).startsWith(F("_"))) // vnitrni parametry WiFiConfig modulu zacinaji _, takze ty muzeme ignorovat
|
|
||||||
{
|
|
||||||
WiFiConfigUsrParameter *up = _searchUsrParameter(server->argName(i).c_str());
|
WiFiConfigUsrParameter *up = _searchUsrParameter(server->argName(i).c_str());
|
||||||
if (NULL != up)
|
if (NULL != up)
|
||||||
up->setNewValue(server->arg(i).c_str());
|
up->setNewValue(server->arg(i).c_str());
|
||||||
@ -644,74 +619,7 @@ void WiFiConfig::_handleSetAP(void)
|
|||||||
server->send_P(200, TEXTHTML, PAGE_SAVED);
|
server->send_P(200, TEXTHTML, PAGE_SAVED);
|
||||||
delay(2000); // cekame na odeslani dat
|
delay(2000); // cekame na odeslani dat
|
||||||
// nakonfigurujeme ESP dle nove nastavenych parametru
|
// nakonfigurujeme ESP dle nove nastavenych parametru
|
||||||
WiFi.disconnect(); // vsechno odpojime
|
_prepareWifi();
|
||||||
WiFi.persistent(true); // chceme, aby si modul zapamatoval konfiguraci
|
|
||||||
|
|
||||||
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...
|
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -733,19 +641,31 @@ wificonfigresult_t WiFiConfig::_setupAP(wificonfig_cb cb)
|
|||||||
IPAddress netMsk(255, 255, 255, 0);
|
IPAddress netMsk(255, 255, 255, 0);
|
||||||
|
|
||||||
WiFi.disconnect(); // pro jistotu se odpojime
|
WiFi.disconnect(); // pro jistotu se odpojime
|
||||||
WiFi.mode(WIFI_AP);
|
// WiFi.mode(WIFI_AP);
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
WiFi.softAPConfig(apIP, apIP, netMsk);
|
WiFi.softAPConfig(apIP, apIP, netMsk);
|
||||||
if (ssid.endsWith(F("?")))
|
if (ssid.endsWith(F("?"))) {
|
||||||
{
|
|
||||||
char lmac[16];
|
char lmac[16];
|
||||||
|
|
||||||
sprintf_P(lmac, PSTR("%06X"), ESP_getChipId());
|
sprintf_P(lmac, PSTR("%06X"), ESP_getChipId());
|
||||||
ssid.replace(F("?"), String(lmac));
|
ssid.replace(F("?"), String(lmac));
|
||||||
}
|
}
|
||||||
WiFi.softAP(ssid.c_str(), NULL, SETUP_CHANNEL);
|
WiFi.softAP(ssid.c_str(), NULL, SETUP_CHANNEL);
|
||||||
|
WiFi.mode(WIFI_AP);
|
||||||
delay(500); // dulezite - jinak se nevraci spravna IP adresa !!! (udajne od verze 2.3.0 uz neni nutne)
|
delay(500); // dulezite - jinak se nevraci spravna IP adresa !!! (udajne od verze 2.3.0 uz neni nutne)
|
||||||
|
#else
|
||||||
|
// osetreni padu ESP32 - https://github.com/espressif/arduino-esp32/issues/2025
|
||||||
|
if (ssid.endsWith(F("?"))) {
|
||||||
|
char lmac[16];
|
||||||
|
|
||||||
|
sprintf_P(lmac, PSTR("%06X"), ESP_getChipId());
|
||||||
|
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);
|
dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
||||||
dnsServer->start(DNS_PORT, "*", WiFi.softAPIP()); // spustime tzv. Captive portal - vsechny DNS dotazy jsou smerovany na nasi ip adresu
|
dnsServer->start(DNS_PORT, "*", WiFi.softAPIP()); // spustime tzv. Captive portal - vsechny DNS dotazy jsou smerovany na nasi ip adresu
|
||||||
if (cb)
|
if (cb)
|
||||||
@ -757,18 +677,45 @@ wificonfigresult_t WiFiConfig::_setupAP(wificonfig_cb cb)
|
|||||||
server->on(F("/r"), std::bind(&WiFiConfig::_handleReset, this));
|
server->on(F("/r"), std::bind(&WiFiConfig::_handleReset, this));
|
||||||
server->on(F("/i"), std::bind(&WiFiConfig::_handleInfo, this));
|
server->on(F("/i"), std::bind(&WiFiConfig::_handleInfo, this));
|
||||||
server->on(F("/index.htm"), std::bind(&WiFiConfig::_handleRoot, this));
|
server->on(F("/index.htm"), std::bind(&WiFiConfig::_handleRoot, this));
|
||||||
|
#ifdef USE_WIFICONFIG_OTAUPDATE
|
||||||
|
server->on(F("/u"), []() {
|
||||||
|
server->send_P(200, TEXTHTML, PAGE_UPDATE);
|
||||||
|
});
|
||||||
|
server->on(F("/update"), HTTP_POST, []() {
|
||||||
|
server->sendHeader(F("Connection"), F("close"));
|
||||||
|
server->send(200, FPSTR(TEXTPLAIN), (Update.hasError()) ? F("FAIL") : F("OK"));
|
||||||
|
ESP.restart();
|
||||||
|
}, []() {
|
||||||
|
HTTPUpload& upload = server->upload();
|
||||||
|
if (upload.status == UPLOAD_FILE_START) {
|
||||||
|
WiFiUDP::stopAll();
|
||||||
|
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||||
|
if (!Update.begin(maxSketchSpace)) { //start with max available size
|
||||||
|
//Update.printError(Serial);
|
||||||
|
}
|
||||||
|
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||||
|
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
|
||||||
|
//Update.printError(Serial);
|
||||||
|
}
|
||||||
|
} else if (upload.status == UPLOAD_FILE_END) {
|
||||||
|
if (Update.end(true)) { //true to set the size to the current progress
|
||||||
|
//Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
|
||||||
|
} else {
|
||||||
|
//Update.printError(Serial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yield();
|
||||||
|
});
|
||||||
|
#endif
|
||||||
server->begin(); // startujeme webovy server
|
server->begin(); // startujeme webovy server
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
server->handleClient(); // osetrujeme praci serveru
|
server->handleClient(); // osetrujeme praci serveru
|
||||||
if (cb)
|
if (cb)
|
||||||
cb(WCS_CONFIGWAIT); // volame uzivatelsky callback (napr. signalizace)
|
cb(WCS_CONFIGWAIT); // volame uzivatelsky callback (napr. signalizace)
|
||||||
dnsServer->processNextRequest();
|
dnsServer->processNextRequest();
|
||||||
yield(); // procesy uvnitr systemu ESP potrebuji take svuj cas
|
yield(); // procesy uvnitr systemu ESP potrebuji take svuj cas
|
||||||
if (_timeout)
|
if (_timeout) {
|
||||||
{
|
if (millis() > _time) {
|
||||||
if (millis() > _time)
|
|
||||||
{
|
|
||||||
DEBUG_MSG("AP timeout\r\n");
|
DEBUG_MSG("AP timeout\r\n");
|
||||||
if (cb)
|
if (cb)
|
||||||
cb(WCS_CONFIGTIMEOUT); // signalizujeme timeout
|
cb(WCS_CONFIGTIMEOUT); // signalizujeme timeout
|
||||||
@ -794,13 +741,10 @@ bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
|||||||
String s = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
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));
|
String pass = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
||||||
|
|
||||||
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)))
|
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode))) {
|
||||||
{
|
case WIFIMODE_STA: {
|
||||||
case WIFIMODE_STA:
|
|
||||||
{
|
|
||||||
DEBUG_MSG("STA mode.\r\n");
|
DEBUG_MSG("STA mode.\r\n");
|
||||||
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip)))
|
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip))) {
|
||||||
{
|
|
||||||
DEBUG_MSG("Static configuration.\r\n");
|
DEBUG_MSG("Static configuration.\r\n");
|
||||||
WiFi.config(IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway))),
|
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))));
|
IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, dns))));
|
||||||
@ -809,8 +753,7 @@ bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
|||||||
WiFi.mode(WIFI_STA); // startujeme WiFi v rezimu klienta
|
WiFi.mode(WIFI_STA); // startujeme WiFi v rezimu klienta
|
||||||
WiFi.begin(s.c_str(), pass.c_str());
|
WiFi.begin(s.c_str(), pass.c_str());
|
||||||
DEBUG_MSG("STA params: %s, %s\r\n", s.c_str(), pass.c_str());
|
DEBUG_MSG("STA params: %s, %s\r\n", s.c_str(), pass.c_str());
|
||||||
if (strlen(WiFiDeviceName))
|
if (strlen(WiFiDeviceName)) {
|
||||||
{
|
|
||||||
WiFi.setHostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
WiFi.setHostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -818,22 +761,27 @@ bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
|||||||
|
|
||||||
case WIFIMODE_AP:
|
case WIFIMODE_AP:
|
||||||
DEBUG_MSG("AP mode.\r\n");
|
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
|
WiFi.mode(WIFI_AP); // startujeme AP
|
||||||
if (pass.length())
|
if (pass.length()) {
|
||||||
{
|
|
||||||
// je zadane heslo do AP
|
// 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(), EEPROM.read(configBase + offsetof(wificonfigarea_t, apchannel)));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// otevreny AP
|
// otevreny AP
|
||||||
WiFi.softAP(s.c_str(), NULL, EEPROM.read(configBase + offsetof(wificonfigarea_t, apchannel)));
|
WiFi.softAP(s.c_str(), NULL, EEPROM.read(configBase + offsetof(wificonfigarea_t, apchannel)));
|
||||||
}
|
}
|
||||||
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip)))
|
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))),
|
WiFi.softAPConfig(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, netmask))));
|
||||||
}
|
}
|
||||||
|
if (cb)
|
||||||
|
cb(WCS_CONNECTED);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // jakykoliv neznamy rezim (mozna zavada na EEPROM???)
|
default: // jakykoliv neznamy rezim (mozna zavada na EEPROM???)
|
||||||
@ -843,10 +791,8 @@ bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
DEBUG_MSG("Trying to connect.\r\n");
|
DEBUG_MSG("Trying to connect.\r\n");
|
||||||
while ((millis() - startt) < WIFI_STA_CONNECT_TIMEOUT)
|
while ((millis() - startt) < WIFI_STA_CONNECT_TIMEOUT) {
|
||||||
{
|
if (WL_CONNECTED == WiFi.status()) {
|
||||||
if (WL_CONNECTED == WiFi.status())
|
|
||||||
{
|
|
||||||
DEBUG_MSG("Connected...\r\n");
|
DEBUG_MSG("Connected...\r\n");
|
||||||
if (cb)
|
if (cb)
|
||||||
cb(WCS_CONNECTED);
|
cb(WCS_CONNECTED);
|
||||||
@ -872,35 +818,24 @@ wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, wificon
|
|||||||
DEBUG_MSG("\r\n\r\n"); // oddeleni vypisu
|
DEBUG_MSG("\r\n\r\n"); // oddeleni vypisu
|
||||||
|
|
||||||
configBase = configarea; // pocatek konfigurace v EEPROM
|
configBase = configarea; // pocatek konfigurace v EEPROM
|
||||||
if (0 == forceConfigure)
|
if (0 == forceConfigure) {
|
||||||
{
|
|
||||||
DEBUG_MSG("Force config.\r\n");
|
DEBUG_MSG("Force config.\r\n");
|
||||||
_status = 0xff;
|
_status = 0xff;
|
||||||
result = _setupAP(cb);
|
result = _setupAP(cb);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
if (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)) != WiFi.getMode())
|
if (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)) != WiFi.getMode()) {
|
||||||
{ // neshoduje se rezim - musime spustit konfiguracni AP (poskozena konfigurace)
|
// 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", EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)), WiFi.getMode());
|
||||||
_status = 0xfe;
|
_status = 0xfe;
|
||||||
result = _setupAP(cb);
|
result = _setupAP(cb);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)))
|
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode))) {
|
||||||
{
|
case WIFIMODE_STA: {
|
||||||
case WIFIMODE_STA:
|
SETHOSTNAME(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||||
{
|
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip))) {
|
||||||
#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");
|
DEBUG_MSG("Static configuration SET.\r\n");
|
||||||
WiFi.config(IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway))),
|
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))));
|
IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, dns))));
|
||||||
@ -908,12 +843,10 @@ wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, wificon
|
|||||||
DEBUG_MSG("STA mode.\r\n");
|
DEBUG_MSG("STA mode.\r\n");
|
||||||
if (WC_DONT_RUN_CONFIGAP == _timeout)
|
if (WC_DONT_RUN_CONFIGAP == _timeout)
|
||||||
result = WCR_CONFIGAP_NOT_STARTED; // nemame spoustet konfiguracni AP - vracime se hned
|
result = WCR_CONFIGAP_NOT_STARTED; // nemame spoustet konfiguracni AP - vracime se hned
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
if (cb)
|
if (cb)
|
||||||
cb(WCS_CONNECTSTART); // signalizujeme zacatek pokusu o pripojeni
|
cb(WCS_CONNECTSTART); // signalizujeme zacatek pokusu o pripojeni
|
||||||
if (!_testWifi(cb))
|
if (!_testWifi(cb)) {
|
||||||
{
|
|
||||||
result = _setupAP(cb); // modul se nepripojil - startujeme AP rezim
|
result = _setupAP(cb); // modul se nepripojil - startujeme AP rezim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -922,8 +855,12 @@ wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, wificon
|
|||||||
|
|
||||||
case WIFIMODE_AP:
|
case WIFIMODE_AP:
|
||||||
DEBUG_MSG("AP mode.\r\n");
|
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 (cb)
|
if (cb)
|
||||||
cb(WCS_CONNECTSTART); // signalizujeme zacatek pokusu o pripojeni (zde se nic jineho stejne nestane...)
|
cb(WCS_CONNECTED); // signalizujeme pripojeni (zde se nic jineho stejne nestane...)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if !defined(ESP8266)
|
#if !defined(ESP8266)
|
||||||
@ -951,4 +888,91 @@ wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, int tim
|
|||||||
_time = millis() + (_timeout * 1000); // spocitame si novy cas, kdy budeme modul restartovat
|
_time = millis() + (_timeout * 1000); // spocitame si novy cas, kdy budeme modul restartovat
|
||||||
return begin(configarea, forceConfigure, cb); // spustime WiFi
|
return begin(configarea, forceConfigure, cb); // spustime WiFi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WiFiConfig::initConfig(int cfgBase, const String &ssid, const String &pass, const int mode, const int ipcfg, const IPAddress &ip, const IPAddress &mask, const IPAddress &gw, const IPAddress &dns)
|
||||||
|
{
|
||||||
|
|
||||||
|
DEBUG_MSG("initConfig %d\r\n", mode);
|
||||||
|
configBase = cfgBase;
|
||||||
|
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);
|
||||||
|
EEPROM.write(configBase + offsetof(wificonfigarea_t, apchannel), 3);
|
||||||
|
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);
|
||||||
|
DEBUG_MSG("IP: %s\r\n", ip.toString().c_str());
|
||||||
|
EEPROM.commit(); // ulozime zmeny v EEPROM
|
||||||
|
_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 = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
||||||
|
String pass = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
||||||
|
uint8_t mode = EEPROM.read(configBase + offsetof(wificonfigarea_t, mode));
|
||||||
|
|
||||||
|
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 == 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(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");
|
||||||
|
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 (%d)!!\r\n", (int)mode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(1000); // cekame XX sekund na ulozeni atd...
|
||||||
|
}
|
||||||
// EOF
|
// EOF
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @file WiFiConfig.h
|
* @file WiFiConfig.h
|
||||||
* @author Pavel Brychta, http://www.xpablo.cz
|
* @author Pavel Brychta, http://www.xpablo.cz
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015-19 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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -31,9 +31,9 @@
|
|||||||
#define __WiFiConfig_h__
|
#define __WiFiConfig_h__
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
# include <ESP8266WiFi.h>
|
||||||
#else
|
#else
|
||||||
#include <WiFi.h>
|
# include <WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -42,8 +42,7 @@
|
|||||||
#define WC_DONT_RUN_CONFIGAP -1 // priznak, ze si neprejeme spoustet konfiguracni AP (uziva se misto parametru timeout). Urceno pro bateriove napajene pristroje
|
#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
|
// Struktura konfigurace, ulozena v EEPROM
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
uint8_t mode; // rezim prace AP/STA
|
uint8_t mode; // rezim prace AP/STA
|
||||||
uint8_t ip; // konfigurace ip (staticka/DHCP)
|
uint8_t ip; // konfigurace ip (staticka/DHCP)
|
||||||
char ssid[32 + 2]; // SSID site
|
char ssid[32 + 2]; // SSID site
|
||||||
@ -56,38 +55,49 @@ typedef struct
|
|||||||
} wificonfigarea_t;
|
} wificonfigarea_t;
|
||||||
|
|
||||||
// Parametr, predany uzivatelske callback funkci, urceny pro aplikacni vizualizaci stavu konfigurace a pripojeni
|
// Parametr, predany uzivatelske callback funkci, urceny pro aplikacni vizualizaci stavu konfigurace a pripojeni
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
WCS_CONNECTSTART = 0, // zacatek pokusu o pripojeni k ulozene konfiguraci
|
WCS_CONNECTSTART = 0, // zacatek pokusu o pripojeni k ulozene konfiguraci
|
||||||
WCS_CONNECTING = 1, // probiha pokus o pripojeni
|
WCS_CONNECTING = 1, // probiha pokus o pripojeni
|
||||||
WCS_CONNECTED = 2, // pripojeni bylo uspesne
|
WCS_CONNECTED = 2, // pripojeni bylo uspesne/byl spusteny AP
|
||||||
WCS_CONFIGSTART = 3, // zacatek startu konfiguracniho AP
|
WCS_CONFIGSTART = 3, // zacatek startu konfiguracniho AP
|
||||||
WCS_CONFIGWAIT = 4, // cekame na nastaveni konfigurace pres web
|
WCS_CONFIGWAIT = 4, // cekame na nastaveni konfigurace pres web
|
||||||
WCS_CONFIGTIMEOUT = 5, // doslo k vyprseni timeoutu konfigurace, budeme se vracet s False jako vysledek z .begin(...)
|
WCS_CONFIGTIMEOUT = 5, // doslo k vyprseni timeoutu konfigurace, budeme se vracet s False jako vysledek z .begin(...)
|
||||||
}wificonfigstate_t;
|
} wificonfigstate_t;
|
||||||
|
|
||||||
// Navratovy parametr z volani begin() - udava, jak se podarilo WiFiConfig modulu pripojit k AP
|
// Navratovy parametr z volani begin() - udava, jak se podarilo WiFiConfig modulu pripojit k AP
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
WCR_OK = 0, // wifi pripojena/AP nastartovane (dle parametru v EEPROM)
|
WCR_OK = 0, // wifi pripojena/AP nastartovane (dle parametru v EEPROM)
|
||||||
WCR_TIMEOUT = 1, // wifi neni pripojena a vyprsel zadany timeout
|
WCR_TIMEOUT = 1, // wifi neni pripojena a vyprsel zadany timeout
|
||||||
WCR_CONFIGAP_NOT_STARTED = 2, // wifi neni pripojena a spusteni konfiguracniho AP bylo zakazane parametrem timeout (WC_DONT_RUN_CONFIGAP)
|
WCR_CONFIGAP_NOT_STARTED = 2, // wifi neni pripojena a spusteni konfiguracniho AP bylo zakazane parametrem timeout (WC_DONT_RUN_CONFIGAP)
|
||||||
}wificonfigresult_t;
|
} 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 (*wificonfig_cb)(wificonfigstate_t state); // definice callbacku
|
||||||
|
|
||||||
typedef void (*storeparam_cb)(const char *newvalue); // callback pro ulozeni uzivatelskeho parametru
|
typedef void (*storeparam_cb)(const char *newvalue); // callback pro ulozeni uzivatelskeho parametru
|
||||||
|
|
||||||
#ifndef WIFI_STA_CONNECT_TIMEOUT
|
#ifndef WIFI_STA_CONNECT_TIMEOUT
|
||||||
#define WIFI_STA_CONNECT_TIMEOUT 15000UL // delka cekani na pripojeni k AP [ms]
|
# define WIFI_STA_CONNECT_TIMEOUT 20000UL // delka cekani na pripojeni k AP [ms]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SETUP_SSID
|
#ifndef SETUP_SSID
|
||||||
#define SETUP_SSID "ESPPBSetup_?"
|
# define SETUP_SSID "ESPPBSetup_?"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SETUP_CHANNEL
|
#ifndef SETUP_CHANNEL
|
||||||
#define SETUP_CHANNEL 3
|
# define SETUP_CHANNEL 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,7 +154,7 @@ void setEEPROMuint32(int start, uint32_t val);
|
|||||||
|
|
||||||
class WiFiConfigUsrParameter
|
class WiFiConfigUsrParameter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WiFiConfigUsrParameter(const char *id, const char *label, const char *defaultValue, unsigned int length, storeparam_cb cb);
|
WiFiConfigUsrParameter(const char *id, const char *label, const char *defaultValue, unsigned int length, storeparam_cb cb);
|
||||||
|
|
||||||
const char *getID();
|
const char *getID();
|
||||||
@ -154,7 +164,7 @@ class WiFiConfigUsrParameter
|
|||||||
void setNext(WiFiConfigUsrParameter *n);
|
void setNext(WiFiConfigUsrParameter *n);
|
||||||
WiFiConfigUsrParameter *getNext();
|
WiFiConfigUsrParameter *getNext();
|
||||||
void setNewValue(const char *newval);
|
void setNewValue(const char *newval);
|
||||||
private:
|
private:
|
||||||
const char *_id;
|
const char *_id;
|
||||||
const char *_label;
|
const char *_label;
|
||||||
char *_value;
|
char *_value;
|
||||||
@ -173,7 +183,10 @@ public:
|
|||||||
wificonfigresult_t begin(int configarea, int forceConfigure, wificonfig_cb cb);
|
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 configarea, int forceConfigure, int timeout, wificonfig_cb cb);
|
||||||
void addParameter(WiFiConfigUsrParameter *p);
|
void addParameter(WiFiConfigUsrParameter *p);
|
||||||
|
void initConfig(int cfgBase, 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(void);
|
||||||
wificonfigresult_t _setupAP(wificonfig_cb cb);
|
wificonfigresult_t _setupAP(wificonfig_cb cb);
|
||||||
void _handleDisplayAP(void);
|
void _handleDisplayAP(void);
|
||||||
void _handleSetAP(void);
|
void _handleSetAP(void);
|
||||||
@ -191,4 +204,5 @@ private:
|
|||||||
uint32_t _time; // hodnota, po ktere bude ESP restartovano (pokud je _timeout != 0)
|
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
|
uint8_t _status; // stav pripojeni - je pouzity pro signalizaci duvodu, proc se nepripoji k AP
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
// HTML data
|
// 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 TEXTHTML[] PROGMEM = "text/html";
|
||||||
static const char TEXTPLAIN[] PROGMEM = "text/plain";
|
static const char TEXTPLAIN[] PROGMEM = "text/plain";
|
||||||
|
|
||||||
static const char PAGE_INDEX1[] PROGMEM = R"=====(
|
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">
|
<!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>
|
<style>
|
||||||
.c{text-align: center;}
|
.c{text-align: center;}
|
||||||
div,input{padding:5px;font-size:1em;}
|
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 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';}}
|
function hSC(){if (document.getElementById('_st').checked){document.getElementById('staticip').style.display = 'block';}else{document.getElementById('staticip').style.display = 'none';}}
|
||||||
</script>
|
</script>
|
||||||
</head><body><h1>ESP8266 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
|
/* Polozky nalezenych SSID
|
||||||
@ -119,10 +127,22 @@ static const char PAGE_CAPTIVEPORTALCATCH[] PROGMEM = R"=====(
|
|||||||
<style>.c{text-align: center;} div,input{padding:5px;font-size:1em;} input{width:95%;} body{text-align: center;font-family:verdana;} button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;} .q{float: right;width: 64px;text-align: right;}
|
<style>.c{text-align: center;} div,input{padding:5px;font-size:1em;} input{width:95%;} body{text-align: center;font-family:verdana;} button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;} .q{float: right;width: 64px;text-align: right;}
|
||||||
.vl-info {border-left: thick solid #1fa3ec;background: #cee6ff; text-align:left; display:inline-block; min-width:260px; margin-top:15px}
|
.vl-info {border-left: thick solid #1fa3ec;background: #cee6ff; text-align:left; display:inline-block; min-width:260px; margin-top:15px}
|
||||||
.red { background-color: #ff0000;}
|
.red { background-color: #ff0000;}
|
||||||
|
.magenta { background-color: #ff00ff;}
|
||||||
</style>
|
</style>
|
||||||
</head><body><div style='text-align:left;display:inline-block;min-width:260px;'>
|
</head><body><div style='text-align:left;display:inline-block;min-width:260px;'>
|
||||||
<form action="/config" method="get"><button>Konfigurace WiFi</button></form><br/><form action="/i" method="get"><button>Informace o modulu</button></form><br/><form action="/r" method="post"><button class="red">Reset</button></form><br>
|
<form action="/config" method="get">
|
||||||
)=====";
|
<button>Konfigurace WiFi</button>
|
||||||
|
</form><br/>
|
||||||
|
<form action="/i" method="get">
|
||||||
|
<button>Informace o modulu</button>
|
||||||
|
</form><br/><form action="/r" method="post">
|
||||||
|
<button class="red">Reset</button></form><br>)====="
|
||||||
|
#if defined USE_WIFICONFIG_OTAUPDATE
|
||||||
|
R"=====(
|
||||||
|
</form><br/><form action="/u" method="get">
|
||||||
|
<button class="magenta">Aktualizace firmware</button></form><br>)====="
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
// druha cast (mezi 1. a 2. cast muzeme doplnit dodatecne informace)
|
// druha cast (mezi 1. a 2. cast muzeme doplnit dodatecne informace)
|
||||||
static const char PAGE_CAPTIVEPORTALCATCH2[] PROGMEM = R"=====(
|
static const char PAGE_CAPTIVEPORTALCATCH2[] PROGMEM = R"=====(
|
||||||
@ -150,3 +170,58 @@ static const char PAGE_RESTART[] PROGMEM = R"=====(
|
|||||||
Restartuji...
|
Restartuji...
|
||||||
</body></html>
|
</body></html>
|
||||||
)=====";
|
)=====";
|
||||||
|
|
||||||
|
static const char PAGE_UPDATE[] PROGMEM = R"=====(
|
||||||
|
<html lang='en'>
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8'>
|
||||||
|
<meta name='viewport' content='width=device-width,initial-scale=1'/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form method="POST" action="#" enctype="multipart/form-data" id="upload_form">
|
||||||
|
<input type="file" name="update" accept='.bin' id="file">
|
||||||
|
<input type="submit" value="Update"> </form>
|
||||||
|
<div id="prg_wrap" style="border: 0px solid; width: 100%;">
|
||||||
|
<div id="prg" style="text-shadow: 2px 2px 3px black; padding: 5px 0; display: none; border: 1px solid #008aff; background: #002180; text-align: center; color: white;"></div>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
var domReady = function(callback) {
|
||||||
|
document.readyState === "interactive" || document.readyState === "complete" ? callback() : document.addEventListener("DOMContentLoaded", callback);
|
||||||
|
};
|
||||||
|
domReady(function() {
|
||||||
|
var myform = document.getElementById('upload_form');
|
||||||
|
var filez = document.getElementById('file');
|
||||||
|
myform.onsubmit = function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
var formData = new FormData();
|
||||||
|
var file = filez.files[0];
|
||||||
|
if(!file) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
formData.append("files", file, file.name);
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.upload.addEventListener("progress", function(evt) {
|
||||||
|
if(evt.lengthComputable) {
|
||||||
|
var per = Math.round((evt.loaded / evt.total) * 100);
|
||||||
|
var prg = document.getElementById('prg');
|
||||||
|
prg.innerHTML = per + "%"
|
||||||
|
prg.style.width = per + "%"
|
||||||
|
prg.style.display = "block"
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
xhr.open('POST', location.href, true);
|
||||||
|
// Set up a handler for when the request finishes.
|
||||||
|
xhr.onload = function() {
|
||||||
|
if(xhr.status === 200) {
|
||||||
|
//alert('Success');
|
||||||
|
} else {
|
||||||
|
//alert('An error occurred!');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.send(formData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
)=====";
|
||||||
|
Reference in New Issue
Block a user