Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
8d709429e0 | |||
e83160d3d2 | |||
baef6c322e | |||
349bc68180 | |||
8a95f6d69b | |||
26a65f00ac | |||
48f3d58f7e | |||
304618c722 | |||
c6f3e3371c | |||
52648c8915 | |||
e66a3306f1 | |||
4033637b82 | |||
ed1659791a | |||
60f106cef3 | |||
4590e99a54 | |||
557d06a557 | |||
f45d742435 | |||
3172bb0d17 | |||
90618b0ae6 | |||
7fec2df6b9 | |||
d0e01c567c | |||
48986510dd | |||
90da6a05e5 | |||
7a6f936a1a | |||
3a8ffdcd01 | |||
dc8aa8890d | |||
81ceb9aca9 | |||
33f8f6a8b8 | |||
f5fce8dee3 | |||
8c23c4eddb | |||
51ae416dd0 | |||
a742f624fb | |||
242238a1f0 | |||
f4f8915197 | |||
68083ee040 |
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Knihovna pro konfiguraci WiFi rozhraní modulu ESP8266
|
Knihovna pro konfiguraci WiFi rozhraní modulu ESP8266 a ESP32, obsahující Captive portal.
|
Binary file not shown.
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 56 KiB |
@ -1,20 +1,43 @@
|
|||||||
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
# include <ESP8266WiFi.h>
|
# include <ESP8266WiFi.h>
|
||||||
# include <ESP8266WebServer.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>
|
||||||
|
|
||||||
|
#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)
|
||||||
|
|
||||||
|
// 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...)
|
||||||
|
#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)
|
||||||
@ -30,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;
|
||||||
@ -49,33 +71,53 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveServer(const char *param)
|
void ICACHE_FLASH_ATTR saveDevname(const char *param)
|
||||||
{
|
{
|
||||||
|
String p = param;
|
||||||
|
|
||||||
DEBUG_OUT(param);
|
EES_storeString(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, devname), elementSize(eepromconfig_t, devname), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICACHE_FLASH_ATTR setup()
|
void ICACHE_FLASH_ATTR setup()
|
||||||
{
|
{
|
||||||
WiFiConfig wifi; // konfigurace ESP modulu
|
WiFiConfig wifi; // konfigurace ESP modulu
|
||||||
WiFiConfigUsrParameter testOnly("server", "adresa serveru", "Default server", 32, saveServer);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
EEPROM.begin(512); // zahajujeme praci s EEPROM
|
|
||||||
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);
|
||||||
wifi.addParameter(&testOnly);
|
String dn = EES_readString(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, devname), elementSize(eepromconfig_t, devname));
|
||||||
if (WCR_OK != wifi.begin(0, fc, wcb)) // startujeme pripojeni
|
strcpy(WiFiDeviceName, dn.c_str());
|
||||||
|
wifi.addParameter(&devname);
|
||||||
|
|
||||||
|
if (WCR_OK != wifi.begin(EEPROM_WIFICONFIG_ORIGIN, fc, wcb)) // startujeme pripojeni
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -90,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;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name":"WiFiConfig",
|
"name":"WiFiConfig",
|
||||||
"description":"Web based WiFi part configuration for the ESP8266 SoC",
|
"description":"Web based WiFi part configuration for the ESP8266 and ESP32 SoC",
|
||||||
"keywords":"wifi, configuration",
|
"keywords":"wifi, configuration",
|
||||||
"authors":
|
"authors":
|
||||||
{
|
{
|
||||||
@ -12,10 +12,10 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://git.xpablo.cz/pablo2048/WiFiConfig.git"
|
"url": "http://git.xpablo.cz/pablo2048/WiFiConfig.git"
|
||||||
},
|
},
|
||||||
"version": "5.7",
|
"version": "6.3.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "espressif8266",
|
"platforms": ["espressif8266", "espressif32"],
|
||||||
"build": {
|
"build": {
|
||||||
"libCompatMode": 2
|
"libCompatMode": 2
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
name=WiFiConfig
|
name=WiFiConfig
|
||||||
version=5.7
|
version=6.3.4
|
||||||
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 module to be configured over network. 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=http://www.xpablo.cz
|
||||||
architectures=esp8266
|
architectures=esp8266,esp32
|
||||||
|
@ -1,4 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
|
* 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
|
||||||
|
* verze pro ESP32 zobrazuje neco malo informaci o stavu pripojeni a duvodu vstupu do WifiConfig
|
||||||
|
*
|
||||||
|
* V6.3.1- 1.9.2019 - Odstraneni HTML5 validatoru - delaly akorat problemy a nedala se ulozit konfigurace i kdyz byly polozky skryty
|
||||||
|
*
|
||||||
|
* V6.3 - 12.8.2019 - IP adresa Captive portalu je zmenena na 172.217.28.1 kvuli funkcnosti na Android zarizenich (viz. zmena zde https://github.com/esp8266/Arduino/blob/master/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino)
|
||||||
|
* ladici vypis pri zachyceni presmerovani v Captive portalu.
|
||||||
|
*
|
||||||
|
* V6.2 - 12.12.2018- Nastaveni jmena zarizeni nadale NENI soucasti WiFiConfig a je treba ho pridat jako uzivatelsky parametr. Je to proto, protoze
|
||||||
|
* se ukazalo, ze neni dobre z externiho kodu sahat do vnitrni struktury WiFiConfig (napr. pri ukladani noveho jmena).
|
||||||
|
*
|
||||||
|
* V6.1 - 11.12.2018- Sifrovani retezcu vytazeno mimo WiFiConfig do knihovny encipheredEEPROMStrings (dostupna na gitu) kvuli pristupu i jinych modulu
|
||||||
|
*
|
||||||
|
* V6.0 - 20.11.2018- Verze i pro ESP32
|
||||||
|
*
|
||||||
|
* V5.9 - 18.7.2018 - Retezce, ukladane do EEPROM jsou primitivnim zpusobem sifrovany pro ztizeni odhaleni SSID a hesla pri dumpu pameti
|
||||||
|
*
|
||||||
|
* V5.8 - 5.7.2018 - Opraveno spatne zobrazovani sily signalu v prehledu WiFi siti (spatne barvy)
|
||||||
|
*
|
||||||
* V5.7 - 4.7.2018 - BugFix - staticka konfigurace ip adresy se neuplatnila - vypada to, jako kdyby SDK ukladalo SSID a Password, ale uz neuklada
|
* V5.7 - 4.7.2018 - BugFix - staticka konfigurace ip adresy se neuplatnila - vypada to, jako kdyby SDK ukladalo SSID a Password, ale uz neuklada
|
||||||
* konfiguraci ip adres, takze je treba je vzdycky nastavit znovu
|
* konfiguraci ip adres, takze je treba je vzdycky nastavit znovu
|
||||||
*
|
*
|
||||||
@ -10,7 +33,7 @@
|
|||||||
*
|
*
|
||||||
* V5.3 - 8.12.2017 - prepracovano presmerovani v Captive portalu, DEBUG_MSG makro upraveno na posledni pouzivanou verzi, scitani retezcu prepracovano na .concat. Pripsany Informace o modulu, reakce na Reset
|
* V5.3 - 8.12.2017 - prepracovano presmerovani v Captive portalu, DEBUG_MSG makro upraveno na posledni pouzivanou verzi, scitani retezcu prepracovano na .concat. Pripsany Informace o modulu, reakce na Reset
|
||||||
*
|
*
|
||||||
* V5.2 - 20.4.2017 - Pokud je pouzite v timeoutu EC_DONT_RUN_CONFIGAP tak se vracime okamzite a necekame na pripojeni k WiFi (take nevolame zadnou callback metodu).
|
* V5.2 - 20.4.2017 - Pokud je pouzite v timeoutu WC_DONT_RUN_CONFIGAP tak se vracime okamzite a necekame na pripojeni k WiFi (take nevolame zadnou callback metodu).
|
||||||
* Navratovy kod je pak WCR_CONFIGAP_NOT_STARTED .
|
* Navratovy kod je pak WCR_CONFIGAP_NOT_STARTED .
|
||||||
*
|
*
|
||||||
* V5.1 - 3.4.2017 - Webove rozhrani upravene pro snadnejsi ovladani na telefonu/tabletu, sila signalu AP zobrazena jako barevne odliseny indikator.
|
* V5.1 - 3.4.2017 - Webove rozhrani upravene pro snadnejsi ovladani na telefonu/tabletu, sila signalu AP zobrazena jako barevne odliseny indikator.
|
||||||
@ -63,11 +86,17 @@
|
|||||||
* Prejit na pripojovani pomoci vnitrnich mechanizmu SDK ESP - zvysi se tim rychlost pripojeni kvuli bateriovym zarizenim
|
* Prejit na pripojovani pomoci vnitrnich mechanizmu SDK ESP - zvysi se tim rychlost pripojeni kvuli bateriovym zarizenim
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "WiFiConfig.h"
|
|
||||||
#include <ESP8266WebServer.h>
|
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
|
#if defined(ESP8266)
|
||||||
|
# include <ESP8266WebServer.h>
|
||||||
|
#else
|
||||||
|
# include <WebServer.h>
|
||||||
|
# include <rom/rtc.h> // duvod resetu (https://github.com/espressif/arduino-esp32/issues/449)
|
||||||
|
#endif
|
||||||
|
#include "WiFiConfig.h"
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include <Ticker.h>
|
#include <Ticker.h>
|
||||||
|
#include <encipheredEEPROMStrings.h>
|
||||||
#include "embHTML.h"
|
#include "embHTML.h"
|
||||||
|
|
||||||
#ifdef DEBUG_ESP_PORT
|
#ifdef DEBUG_ESP_PORT
|
||||||
@ -76,23 +105,27 @@
|
|||||||
# define DEBUG_MSG(...)
|
# define DEBUG_MSG(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
# include "user_interface.h"
|
# include "user_interface.h"
|
||||||
}
|
}
|
||||||
|
# define ESP_getChipId() (ESP.getChipId())
|
||||||
|
#else
|
||||||
|
# include <esp_wifi.h>
|
||||||
|
# define ESP_getChipId() ((uint32_t)ESP.getEfuseMac())
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DNS_PORT 53
|
#define DNS_PORT 53
|
||||||
|
|
||||||
char WiFiDeviceName[elementSize(wificonfigarea_t, devname)]; // misto pro jmeno zarizeni (dodane do DNS, DHCP NBNS apod...)
|
extern char WiFiDeviceName[];
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
|
||||||
WIFIMODE_AP = WIFI_AP, // rezim prace jako pristupovy bod (AP)
|
WIFIMODE_AP = WIFI_AP, // rezim prace jako pristupovy bod (AP)
|
||||||
WIFIMODE_STA = WIFI_STA, // rezim prace jako klient
|
WIFIMODE_STA = WIFI_STA, // rezim prace jako klient
|
||||||
WIFIMODE_AP_STA = WIFI_AP_STA // rezim prace jako klient i pristupovy bod
|
WIFIMODE_AP_STA = WIFI_AP_STA // rezim prace jako klient i pristupovy bod
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
|
||||||
IPCONFIG_DHCP = 0x55, // DHCP konfigurace ip adres (default)
|
IPCONFIG_DHCP = 0x55, // DHCP konfigurace ip adres (default)
|
||||||
IPCONFIG_STATIC = 0xaa // staticka konfigurace ip adres
|
IPCONFIG_STATIC = 0xaa // staticka konfigurace ip adres
|
||||||
};
|
};
|
||||||
@ -100,7 +133,11 @@ enum
|
|||||||
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;
|
||||||
|
#if defined(ESP8266)
|
||||||
static std::unique_ptr<ESP8266WebServer> server;
|
static std::unique_ptr<ESP8266WebServer> server;
|
||||||
|
#else
|
||||||
|
static std::unique_ptr<WebServer> server;
|
||||||
|
#endif
|
||||||
static std::unique_ptr<Ticker> rsttick;
|
static std::unique_ptr<Ticker> rsttick;
|
||||||
|
|
||||||
const char VALUE[] PROGMEM = "value='";
|
const char VALUE[] PROGMEM = "value='";
|
||||||
@ -111,8 +148,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;
|
||||||
@ -137,12 +173,11 @@ uint8_t * getOurMAC(uint8_t *mac)
|
|||||||
return WiFi.softAPmacAddress(mac);
|
return WiFi.softAPmacAddress(mac);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getEEPROMuint32(int start)
|
uint32_t getEEPROMuint32(unsigned int start)
|
||||||
{
|
{
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
|
|
||||||
for (int 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;
|
||||||
@ -150,45 +185,39 @@ uint32_t getEEPROMuint32(int start)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEEPROMuint32(int start, uint32_t val)
|
void setEEPROMuint32(unsigned int start, uint32_t val)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getEEPROMString(int start, int len)
|
String getEEPROMString(unsigned int start, size_t len)
|
||||||
{
|
{
|
||||||
String string = "";
|
String string = "";
|
||||||
|
|
||||||
for (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))
|
||||||
break;
|
break;
|
||||||
string.concat(char(b));
|
string += char(b);
|
||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEEPROMString(int start, int len, String string)
|
void setEEPROMString(unsigned int start, size_t len, String &string)
|
||||||
{
|
{
|
||||||
unsigned int si = 0;
|
unsigned int si = 0;
|
||||||
|
|
||||||
for (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);
|
||||||
@ -196,7 +225,7 @@ void setEEPROMString(int start, int len, String string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFiConfigUsrParameter::WiFiConfigUsrParameter(const char *id, const char *label, const char *defaultValue, int length, storeparam_cb cb)
|
WiFiConfigUsrParameter::WiFiConfigUsrParameter(const char *id, const char *label, const char *defaultValue, unsigned int length, storeparam_cb cb)
|
||||||
{
|
{
|
||||||
_next = NULL;
|
_next = NULL;
|
||||||
_cb = cb;
|
_cb = cb;
|
||||||
@ -204,12 +233,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 (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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,8 +288,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();
|
||||||
@ -279,18 +305,19 @@ void WiFiConfig::addParameter(WiFiConfigUsrParameter *p)
|
|||||||
void WiFiConfig::_handleNotFound(void)
|
void WiFiConfig::_handleNotFound(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
// _time = millis() + (_timeout * 1000); // spocitame si novy cas, kdy budeme modul restartovat
|
|
||||||
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(404, F("text/plain"), F("Err"));
|
} else {
|
||||||
}
|
String redirect;
|
||||||
else
|
redirect.reserve(256);
|
||||||
{
|
redirect = F("http://");
|
||||||
server->sendHeader(F("Location"), String(F("http://")) + server->client().localIP().toString() + String(F("/index.htm")), true);
|
redirect.concat(server->client().localIP().toString());
|
||||||
// server->sendHeader(F("Location"), String(F("http://")) + WiFi.softAPIP().toString() + String(F("/index.htm")), true);
|
redirect.concat(F("/index.htm"));
|
||||||
server->send (302, F("text/plain"), F("Redirect"));
|
DEBUG_MSG("Redirection to: %s\r\n", redirect.c_str());
|
||||||
|
server->sendHeader(F("Location"), redirect, true);
|
||||||
|
server->send_P(302, TEXTPLAIN, PSTR("Redirect"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,8 +326,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();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -318,20 +344,32 @@ void WiFiConfig::_handleInfo(void)
|
|||||||
reply.concat(F("<form><table><TR><TH>System Info<TH>"));
|
reply.concat(F("<form><table><TR><TH>System Info<TH>"));
|
||||||
|
|
||||||
reply.concat(F("<TR><TD>Core Version:<TD>"));
|
reply.concat(F("<TR><TD>Core Version:<TD>"));
|
||||||
reply.concat(ESP.getCoreVersion());
|
#if defined(ESP8266)
|
||||||
|
reply.concat(ESP.getFullVersion());
|
||||||
|
#else
|
||||||
|
// TODO
|
||||||
|
reply.concat(ESP.getSdkVersion());
|
||||||
|
#endif
|
||||||
|
|
||||||
reply.concat(F("<TR><TD>Flash Size:<TD>"));
|
reply.concat(F("<TR><TD>Flash Size:<TD>"));
|
||||||
|
#if defined(ESP8266)
|
||||||
reply.concat(ESP.getFlashChipRealSize() / 1024);
|
reply.concat(ESP.getFlashChipRealSize() / 1024);
|
||||||
|
#else
|
||||||
|
// TODO
|
||||||
|
reply.concat(ESP.getFlashChipSize());
|
||||||
|
#endif
|
||||||
reply.concat(F(" kB"));
|
reply.concat(F(" kB"));
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
reply.concat(F("<TR><TD>Sketch Size/Free:<TD>"));
|
reply.concat(F("<TR><TD>Sketch Size/Free:<TD>"));
|
||||||
reply.concat(ESP.getSketchSize() / 1024);
|
reply.concat(ESP.getSketchSize() / 1024);
|
||||||
reply.concat(F(" kB / "));
|
reply.concat(F(" kB / "));
|
||||||
reply.concat(ESP.getFreeSketchSpace() / 1024);
|
reply.concat(ESP.getFreeSketchSpace() / 1024);
|
||||||
reply.concat(F(" kB"));
|
reply.concat(F(" kB"));
|
||||||
|
#endif
|
||||||
|
|
||||||
reply.concat(F("<TR><TD>STA MAC:<TD>"));
|
reply.concat(F("<TR><TD>STA MAC:<TD>"));
|
||||||
uint8_t mac[] = {0, 0, 0, 0, 0, 0};
|
uint8_t mac[6];
|
||||||
uint8_t* macread = WiFi.macAddress(mac);
|
uint8_t* macread = WiFi.macAddress(mac);
|
||||||
char macaddress[20];
|
char macaddress[20];
|
||||||
sprintf_P(macaddress, PSTR("%02x:%02x:%02x:%02x:%02x:%02x"), macread[0], macread[1], macread[2], macread[3], macread[4], macread[5]);
|
sprintf_P(macaddress, PSTR("%02x:%02x:%02x:%02x:%02x:%02x"), macread[0], macread[1], macread[2], macread[3], macread[4], macread[5]);
|
||||||
@ -343,15 +381,24 @@ void WiFiConfig::_handleInfo(void)
|
|||||||
reply.concat(macaddress);
|
reply.concat(macaddress);
|
||||||
|
|
||||||
reply.concat(F("<TR><TD>ESP Chip ID:<TD>"));
|
reply.concat(F("<TR><TD>ESP Chip ID:<TD>"));
|
||||||
sprintf_P(buff, PSTR("%06X"), ESP.getChipId());
|
sprintf_P(buff, PSTR("%06X"), ESP_getChipId());
|
||||||
reply.concat(buff);
|
reply.concat(buff);
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
reply.concat(F("<TR><TD>Flash Chip ID:<TD>"));
|
reply.concat(F("<TR><TD>Flash Chip ID:<TD>"));
|
||||||
sprintf_P(buff, PSTR("%08X"), ESP.getFlashChipId());
|
sprintf_P(buff, PSTR("%08X"), ESP.getFlashChipId());
|
||||||
reply.concat(buff);
|
reply.concat(buff);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
|
uint8_t stations = wifi_softap_get_station_num();
|
||||||
|
|
||||||
|
reply.concat(F("<TR><TD>Clients:<TD>"));
|
||||||
|
reply.concat(stations);
|
||||||
|
#endif
|
||||||
|
|
||||||
reply.concat(F("</table></form>"));
|
reply.concat(F("</table></form>"));
|
||||||
server->send(200, TEXTHTML, reply);
|
server->send(200, FPSTR(TEXTHTML), reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiFiConfig::_handleRoot(void)
|
void WiFiConfig::_handleRoot(void)
|
||||||
@ -362,8 +409,8 @@ void WiFiConfig::_handleRoot(void)
|
|||||||
content = FPSTR(PAGE_CAPTIVEPORTALCATCH); // 1. cast stranky
|
content = FPSTR(PAGE_CAPTIVEPORTALCATCH); // 1. cast stranky
|
||||||
// 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í: "));
|
||||||
switch (_status)
|
#if defined(ESP8266)
|
||||||
{
|
switch (_status) {
|
||||||
case STATION_IDLE:
|
case STATION_IDLE:
|
||||||
content.concat(F("Klid"));
|
content.concat(F("Klid"));
|
||||||
break;
|
break;
|
||||||
@ -397,12 +444,31 @@ void WiFiConfig::_handleRoot(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
content.concat(F("Neznámého"));
|
content.concat(F("Neznámý"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
switch (_status) {
|
||||||
|
case WL_CONNECT_FAILED:
|
||||||
|
content.concat(F("Připojení selhalo"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0xfe:
|
||||||
|
content.concat(F("Špatná EEPROM"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0xff:
|
||||||
|
content.concat(F("Vynucená konfigurace"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
content.concat(F("Neznámý"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
content.concat(F("</div>"));
|
content.concat(F("</div>"));
|
||||||
content.concat(FPSTR(PAGE_CAPTIVEPORTALCATCH2)); // 2. cast stranky (ukonceni)
|
content.concat(FPSTR(PAGE_CAPTIVEPORTALCATCH2)); // 2. cast stranky (ukonceni)
|
||||||
server->send(200, TEXTHTML, content);
|
server->send(200, FPSTR(TEXTHTML), content);
|
||||||
_time = millis() + (_timeout * 1000); // spocitame si novy cas, kdy budeme modul restartovat
|
_time = millis() + (_timeout * 1000); // spocitame si novy cas, kdy budeme modul restartovat
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,14 +482,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)
|
||||||
@ -436,26 +498,25 @@ void WiFiConfig::_handleDisplayAP(void)
|
|||||||
s = FPSTR(SSID_ITEM);
|
s = FPSTR(SSID_ITEM);
|
||||||
s.replace(F("{v}"), WiFi.SSID(i));
|
s.replace(F("{v}"), WiFi.SSID(i));
|
||||||
s.replace(F("{a}"), String(quality));
|
s.replace(F("{a}"), String(quality));
|
||||||
|
#if defined(ESP8266)
|
||||||
s.replace(F("{s}"), (ENC_TYPE_NONE == WiFi.encryptionType(i)) ? F("") : F("l"));
|
s.replace(F("{s}"), (ENC_TYPE_NONE == WiFi.encryptionType(i)) ? F("") : F("l"));
|
||||||
|
#else
|
||||||
|
s.replace(F("{s}"), (WIFI_AUTH_OPEN == WiFi.encryptionType(i)) ? F("") : F("l"));
|
||||||
|
#endif
|
||||||
content.concat(s);
|
content.concat(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s = FPSTR(PAGE_INDEX2);
|
s = FPSTR(PAGE_INDEX2);
|
||||||
v = getEEPROMString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
v = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
||||||
if (v.length())
|
if (v.length())
|
||||||
s.replace(F("{s}"), String(FPSTR(VALUE)) + v + F("'"));
|
s.replace(F("{s}"), String(FPSTR(VALUE)) + v + F("'"));
|
||||||
else
|
else
|
||||||
s.replace(F("{s}"), F("placeholder='SSID'"));
|
s.replace(F("{s}"), F(""));
|
||||||
v = getEEPROMString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
v = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
||||||
if (v.length())
|
if (v.length())
|
||||||
s.replace(F("{p}"), String(FPSTR(VALUE)) + v + F("'"));
|
s.replace(F("{p}"), String(FPSTR(VALUE)) + v + F("'"));
|
||||||
else
|
else
|
||||||
s.replace(F("{p}"), F("placeholder='password'"));
|
s.replace(F("{p}"), F(""));
|
||||||
v = getEEPROMString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname));
|
|
||||||
if (v.length())
|
|
||||||
s.replace(F("{n}"), String(FPSTR(VALUE)) + v + F("'"));
|
|
||||||
else
|
|
||||||
s.replace(F("{n}"), F("placeholder='name'"));
|
|
||||||
if (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)) == WIFIMODE_AP)
|
if (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)) == WIFIMODE_AP)
|
||||||
s.replace(F("{a}"), FPSTR(CHECKED));
|
s.replace(F("{a}"), FPSTR(CHECKED));
|
||||||
else
|
else
|
||||||
@ -477,15 +538,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());
|
||||||
@ -496,7 +555,7 @@ void WiFiConfig::_handleDisplayAP(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
content.concat(FPSTR(PAGE_END));
|
content.concat(FPSTR(PAGE_END));
|
||||||
server->send(200, TEXTHTML, content);
|
server->send(200, FPSTR(TEXTHTML), content);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiFiConfig::_handleSetAP(void)
|
void WiFiConfig::_handleSetAP(void)
|
||||||
@ -506,32 +565,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);
|
||||||
setEEPROMString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid), str);
|
|
||||||
|
|
||||||
str = server->arg(F("_p"));
|
str = server->arg(F("_p"));
|
||||||
setEEPROMString(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("_n"));
|
|
||||||
setEEPROMString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname), 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);
|
||||||
@ -553,10 +606,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());
|
||||||
@ -564,28 +615,24 @@ void WiFiConfig::_handleSetAP(void)
|
|||||||
}
|
}
|
||||||
EEPROM.commit(); // skutecne ulozime data
|
EEPROM.commit(); // skutecne ulozime data
|
||||||
}
|
}
|
||||||
server->send(200, F("text/html"), FPSTR(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
|
|
||||||
WiFi.persistent(true); // chceme, aby si modul zapamatoval konfiguraci
|
WiFi.persistent(true); // chceme, aby si modul zapamatoval konfiguraci
|
||||||
|
WiFi.disconnect(); // vsechno odpojime
|
||||||
|
|
||||||
String s = getEEPROMString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname));
|
String s = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
||||||
strcpy(WiFiDeviceName, s.c_str());
|
String pass = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
||||||
s = getEEPROMString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
|
||||||
String pass = getEEPROMString(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 (strlen(WiFiDeviceName))
|
#if defined(ESP8266)
|
||||||
{
|
if (strlen(WiFiDeviceName)) {
|
||||||
WiFi.hostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
WiFi.hostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||||
}
|
}
|
||||||
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip)))
|
#endif
|
||||||
{
|
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))));
|
||||||
@ -593,7 +640,17 @@ void WiFiConfig::_handleSetAP(void)
|
|||||||
}
|
}
|
||||||
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());
|
||||||
|
#if !defined(ESP8266)
|
||||||
|
if (strlen(WiFiDeviceName)) {
|
||||||
|
WiFi.setHostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(ESP8266)
|
||||||
wifi_station_set_auto_connect(true);
|
wifi_station_set_auto_connect(true);
|
||||||
|
#else
|
||||||
|
//esp_wifi_set_auto_connect(true);
|
||||||
|
#endif
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -601,18 +658,14 @@ void WiFiConfig::_handleSetAP(void)
|
|||||||
case WIFIMODE_AP:
|
case WIFIMODE_AP:
|
||||||
DEBUG_MSG("AP mode.\r\n");
|
DEBUG_MSG("AP mode.\r\n");
|
||||||
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))) {
|
||||||
{
|
|
||||||
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))));
|
||||||
}
|
}
|
||||||
@ -634,30 +687,41 @@ wificonfigresult_t WiFiConfig::_setupAP(wificonfig_cb cb)
|
|||||||
|
|
||||||
WiFi.persistent(false); // chranime flash pred zbytecnymi prepisy
|
WiFi.persistent(false); // chranime flash pred zbytecnymi prepisy
|
||||||
dnsServer.reset(new DNSServer());
|
dnsServer.reset(new DNSServer());
|
||||||
|
#if defined(ESP8266)
|
||||||
server.reset(new ESP8266WebServer(80));
|
server.reset(new ESP8266WebServer(80));
|
||||||
|
#else
|
||||||
|
server.reset(new WebServer(80));
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Soft AP network parameters */
|
/* Soft AP network parameters */
|
||||||
IPAddress apIP(192, 168, 4, 1);
|
IPAddress apIP(172, 217, 28, 1);
|
||||||
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("?"))) {
|
||||||
{
|
|
||||||
//uint8_t amac[6];
|
|
||||||
char lmac[16];
|
char lmac[16];
|
||||||
|
|
||||||
//WiFi.softAPmacAddress(amac);
|
sprintf_P(lmac, PSTR("%06X"), ESP_getChipId());
|
||||||
//sprintf_P(lmac, PSTR("%02X%02X%02X"), amac[3], amac[4], amac[5]);
|
|
||||||
|
|
||||||
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);
|
||||||
|
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)
|
||||||
@ -669,18 +733,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
|
||||||
@ -699,11 +790,58 @@ bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
|||||||
{
|
{
|
||||||
uint32_t startt = millis();
|
uint32_t startt = millis();
|
||||||
|
|
||||||
|
#if !defined(ESP8266)
|
||||||
|
// nakonfigurujeme ESP dle nove nastavenych parametru
|
||||||
|
WiFi.disconnect(); // vsechno odpojime
|
||||||
|
|
||||||
|
String s = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
||||||
|
String pass = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
||||||
|
|
||||||
|
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode))) {
|
||||||
|
case WIFIMODE_STA: {
|
||||||
|
DEBUG_MSG("STA mode.\r\n");
|
||||||
|
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip))) {
|
||||||
|
DEBUG_MSG("Static configuration.\r\n");
|
||||||
|
WiFi.config(IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway))),
|
||||||
|
IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, dns))));
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
WiFi.mode(WIFI_STA); // startujeme WiFi v rezimu klienta
|
||||||
|
WiFi.begin(s.c_str(), pass.c_str());
|
||||||
|
DEBUG_MSG("STA params: %s, %s\r\n", s.c_str(), pass.c_str());
|
||||||
|
if (strlen(WiFiDeviceName)) {
|
||||||
|
WiFi.setHostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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))));
|
||||||
|
}
|
||||||
|
if (cb)
|
||||||
|
cb(WCS_CONNECTED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: // jakykoliv neznamy rezim (mozna zavada na EEPROM???)
|
||||||
|
DEBUG_MSG("Mode Error!!\r\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#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);
|
||||||
@ -714,43 +852,43 @@ bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
|||||||
cb(WCS_CONNECTING); // signalizujeme pokracujici pokus o spojeni
|
cb(WCS_CONNECTING); // signalizujeme pokracujici pokus o spojeni
|
||||||
}
|
}
|
||||||
DEBUG_MSG("Not connected!\r\n");
|
DEBUG_MSG("Not connected!\r\n");
|
||||||
|
#if defined(ESP8266)
|
||||||
_status = wifi_station_get_connect_status();
|
_status = wifi_station_get_connect_status();
|
||||||
|
#else
|
||||||
|
_status = WiFi.status();
|
||||||
|
#endif
|
||||||
return false; // pripojeni se nezdarilo
|
return false; // pripojeni se nezdarilo
|
||||||
}
|
}
|
||||||
|
|
||||||
wificonfigresult_t WiFiConfig::begin(int configarea, uint8_t forceConfigure, wificonfig_cb cb)
|
wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, wificonfig_cb cb)
|
||||||
{
|
{
|
||||||
wificonfigresult_t result = WCR_OK; // predpokladame, ze se pripojeni podari
|
wificonfigresult_t result = WCR_OK; // predpokladame, ze se pripojeni podari
|
||||||
|
|
||||||
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 (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\r\n");
|
|
||||||
_status = 0xfe;
|
_status = 0xfe;
|
||||||
result = _setupAP(cb);
|
result = _setupAP(cb);
|
||||||
}
|
} else
|
||||||
else
|
#endif
|
||||||
{
|
|
||||||
String s = getEEPROMString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname));
|
|
||||||
strcpy(WiFiDeviceName, s.c_str());
|
|
||||||
|
|
||||||
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)))
|
|
||||||
{
|
|
||||||
case WIFIMODE_STA:
|
|
||||||
{
|
{
|
||||||
|
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode))) {
|
||||||
|
case WIFIMODE_STA: {
|
||||||
|
#if defined(ESP8266)
|
||||||
WiFi.hostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
WiFi.hostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||||
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip)))
|
#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))));
|
||||||
@ -758,12 +896,10 @@ wificonfigresult_t WiFiConfig::begin(int configarea, uint8_t forceConfigure, wif
|
|||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -772,27 +908,37 @@ wificonfigresult_t WiFiConfig::begin(int configarea, uint8_t forceConfigure, wif
|
|||||||
|
|
||||||
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)
|
||||||
|
default:
|
||||||
|
DEBUG_MSG("Wrong config (%d)\r\n", EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)));
|
||||||
|
_status = 0xfe;
|
||||||
|
result = _setupAP(cb);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result; // mame vyreseno
|
return result; // mame vyreseno
|
||||||
}
|
}
|
||||||
|
|
||||||
wificonfigresult_t WiFiConfig::begin(int configarea, uint8_t forceConfigure, int timeout, wificonfig_cb cb = NULL)
|
wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, int timeout, wificonfig_cb cb = NULL)
|
||||||
{
|
{
|
||||||
if (forceConfigure)
|
|
||||||
{ // pouze pokud nemame vynucenou konfiguraci merime cas - to nam umozni dostat se ze spatne zadaneho timeoutu, ktery se neda zvladnout
|
|
||||||
if ((timeout > 0) && (40 > timeout))
|
if ((timeout > 0) && (40 > timeout))
|
||||||
timeout = 40; // timeout musi byt minimalne 40 sekund
|
timeout = 40; // timeout musi byt minimalne 40 sekund
|
||||||
|
if ((0 == forceConfigure) && (WC_DONT_RUN_CONFIGAP == timeout))
|
||||||
|
timeout = 40;
|
||||||
_timeout = timeout;
|
_timeout = timeout;
|
||||||
if (_timeout > 0)
|
if (_timeout > 0)
|
||||||
_time = millis() + (_timeout * 1000); // spocitame si novy cas, kdy budeme modul restartovat
|
_time = millis() + (_timeout * 1000); // spocitame si novy cas, kdy budeme modul restartovat
|
||||||
}
|
|
||||||
else
|
|
||||||
_timeout = 0; // pri vynucene konfiguraci se parametr timeout neuplatni
|
|
||||||
return begin(configarea, forceConfigure, cb); // spustime WiFi
|
return begin(configarea, forceConfigure, cb); // spustime WiFi
|
||||||
}
|
}
|
||||||
// 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,16,17 Pavel Brychta. All rights reserved.
|
* Copyright (c) 2015-20 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
|
||||||
@ -24,12 +24,17 @@
|
|||||||
* 1. Pokud je forceConfigure ==0, tak se aktivuje WiFi v rezimu AP a cele ESP je mozne nastavit webovym rozhranim (pocitam s prenosem hodnoty nouzoveho tlacitka pri startu).
|
* 1. Pokud je forceConfigure ==0, tak se aktivuje WiFi v rezimu AP a cele ESP je mozne nastavit webovym rozhranim (pocitam s prenosem hodnoty nouzoveho tlacitka pri startu).
|
||||||
* 2. Neni-li tlacitko stisknute, tak se vezme rezim prace a AP se nastavi dle nej (WIFI_STA a WIFI_AP)
|
* 2. Neni-li tlacitko stisknute, tak se vezme rezim prace a AP se nastavi dle nej (WIFI_STA a WIFI_AP)
|
||||||
* 3. Pokud byl rezim prace WIFI_STA a ESP se nepripoji k zadne siti do casu WIFI_STA_CONNECT_TIMEOUT, tak se pokracuje jako kdyby bylo stisknute rekonfiguracni tlacitko
|
* 3. Pokud byl rezim prace WIFI_STA a ESP se nepripoji k zadne siti do casu WIFI_STA_CONNECT_TIMEOUT, tak se pokracuje jako kdyby bylo stisknute rekonfiguracni tlacitko
|
||||||
|
* Podrobnejsi informace o upravach chovani v jednotlivych verzich jsou v zahlavi .cpp souboru.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __WiFiConfig_h__
|
#ifndef __WiFiConfig_h__
|
||||||
#define __WiFiConfig_h__
|
#define __WiFiConfig_h__
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
#else
|
||||||
|
#include <WiFi.h>
|
||||||
|
#endif
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#define elementSize(type, element) sizeof(((type *)0)->element)
|
#define elementSize(type, element) sizeof(((type *)0)->element)
|
||||||
@ -37,13 +42,11 @@
|
|||||||
#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]; // SSID site
|
char ssid[32 + 2]; // SSID site
|
||||||
char pass[64]; // heslo
|
char pass[64 + 2]; // heslo
|
||||||
char devname[32]; // jmeno zarizeni (pro NBNS plati jen 16 znaku)
|
|
||||||
uint32_t ipaddr; // ip adresa v pripade staticke konfigurace
|
uint32_t ipaddr; // ip adresa v pripade staticke konfigurace
|
||||||
uint32_t netmask; // sitova maska v pripade staticke konfigurace
|
uint32_t netmask; // sitova maska v pripade staticke konfigurace
|
||||||
uint32_t gateway; // sitova brana v pripade staticke konfigurace
|
uint32_t gateway; // sitova brana v pripade staticke konfigurace
|
||||||
@ -52,19 +55,17 @@ 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)
|
||||||
@ -75,7 +76,7 @@ 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
|
||||||
@ -93,7 +94,7 @@ typedef void (*storeparam_cb)(const char *newvalue); // callback pro ulozeni uzi
|
|||||||
* \param [in] len Delka retezce
|
* \param [in] len Delka retezce
|
||||||
* \return Vycteny retezec
|
* \return Vycteny retezec
|
||||||
*/
|
*/
|
||||||
String getEEPROMString(int start, int len);
|
String getEEPROMString(unsigned int start, size_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Ulozeni retezce do EEPROM
|
* \brief Ulozeni retezce do EEPROM
|
||||||
@ -102,7 +103,7 @@ String getEEPROMString(int start, int len);
|
|||||||
* \param [in] len Maximalni delka ulozeneho retezce
|
* \param [in] len Maximalni delka ulozeneho retezce
|
||||||
* \param [in] string Ukladany retezec
|
* \param [in] string Ukladany retezec
|
||||||
*/
|
*/
|
||||||
void setEEPROMString(int start, int len, String string);
|
void setEEPROMString(unsigned int start, size_t len, String &string);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Ziskani nasi ip adresy
|
* \brief Ziskani nasi ip adresy
|
||||||
@ -121,16 +122,27 @@ IPAddress getOurIP(void);
|
|||||||
*/
|
*/
|
||||||
uint8_t * getOurMAC(uint8_t *mac);
|
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);
|
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);
|
void setEEPROMuint32(int start, uint32_t val);
|
||||||
|
|
||||||
extern char WiFiDeviceName[]; // jmeno zarizeni, pouzivane i pro DHCP
|
|
||||||
|
|
||||||
class WiFiConfigUsrParameter
|
class WiFiConfigUsrParameter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WiFiConfigUsrParameter(const char *id, const char *label, const char *defaultValue, 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();
|
||||||
const char *getValue();
|
const char *getValue();
|
||||||
@ -155,8 +167,8 @@ class WiFiConfig
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WiFiConfig(): _params(NULL), _timeout(0) {}
|
WiFiConfig(): _params(NULL), _timeout(0) {}
|
||||||
wificonfigresult_t begin(int configarea, uint8_t forceConfigure, wificonfig_cb cb);
|
wificonfigresult_t begin(int configarea, int forceConfigure, wificonfig_cb cb);
|
||||||
wificonfigresult_t begin(int configarea, uint8_t 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);
|
||||||
private:
|
private:
|
||||||
wificonfigresult_t _setupAP(wificonfig_cb cb);
|
wificonfigresult_t _setupAP(wificonfig_cb cb);
|
||||||
@ -167,6 +179,8 @@ private:
|
|||||||
void _handleNotFound(); // CaptivePortal redirector
|
void _handleNotFound(); // CaptivePortal redirector
|
||||||
void _handleRoot(); // jen jednoducha stranka kvuli CaptivePortalu umoznuje prejit na spravnou stranku (ale nedela to...)
|
void _handleRoot(); // jen jednoducha stranka kvuli CaptivePortalu umoznuje prejit na spravnou stranku (ale nedela to...)
|
||||||
bool _testWifi(wificonfig_cb cb);
|
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 *_searchUsrParameter(const char *name);
|
||||||
|
|
||||||
WiFiConfigUsrParameter *_params; // ukazatel na posledni zadany uzivatelsky parametr
|
WiFiConfigUsrParameter *_params; // ukazatel na posledni zadany uzivatelsky parametr
|
||||||
|
140
src/embHTML.h
140
src/embHTML.h
@ -1,5 +1,6 @@
|
|||||||
// file:///I:/MyProjects/PB_ESP8266_WiFiConfig_Vyvoj/doc/_testy/s?_s=SSID1&_p=heslo&_n=jmeno_zarizeni&_a=on&_st=on&_i=192.168.1.1&_m=255.255.255.0&_g=192.168.1.3&_d=192.168.1.3&{n}={v}
|
// HTML data
|
||||||
static const char TEXTHTML[] PROGMEM = "text/html";
|
static const char TEXTHTML[] PROGMEM = "text/html";
|
||||||
|
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">
|
||||||
@ -20,22 +21,22 @@ 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>ESP WiFiConfig</h1><div style='text-align:left;display:inline-block;min-width:260px;'>
|
||||||
)=====";
|
)=====";
|
||||||
|
|
||||||
/* Polozky nalezenych SSID
|
/* Polozky nalezenych SSID
|
||||||
{v} - SSID
|
{v} - SSID
|
||||||
{a} - RSSI (primo v dBm)
|
{a} - RSSI (%)
|
||||||
{s} - bud nic, nebo 'l'>
|
{s} - bud nic, nebo 'l'>
|
||||||
|
Rozsahy otestovany zde https://css-tricks.com/html5-meter-element/
|
||||||
*/
|
*/
|
||||||
static const char SSID_ITEM[] PROGMEM = R"=====(
|
static const char SSID_ITEM[] PROGMEM = R"=====(
|
||||||
<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q {s}'><meter value="{a}" min="0" max="100" low="30" high="80" optimum="50" style="width: 70%;"></meter></span></div>
|
<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q {s}'><meter value="{a}" min="0" low="30" optimum="70" high="60" max="100" style="width: 70%;"></meter></span></div>
|
||||||
)=====";
|
)=====";
|
||||||
|
|
||||||
/* Zacatek formulare pro vyplneni
|
/* Zacatek formulare pro vyplneni
|
||||||
{s} - SSID
|
{s} - SSID
|
||||||
{p} - password
|
{p} - password
|
||||||
{n} - Netbios name
|
|
||||||
{a} - AP mode (checkbox)
|
{a} - AP mode (checkbox)
|
||||||
{ch}- cislo kanalu AP
|
{ch}- cislo kanalu AP
|
||||||
{c} - staticka IP konfigurace (checkbox)
|
{c} - staticka IP konfigurace (checkbox)
|
||||||
@ -46,9 +47,8 @@ static const char SSID_ITEM[] PROGMEM = R"=====(
|
|||||||
*/
|
*/
|
||||||
static const char PAGE_INDEX2[] PROGMEM = R"=====(
|
static const char PAGE_INDEX2[] PROGMEM = R"=====(
|
||||||
<form method='post' action='s'>
|
<form method='post' action='s'>
|
||||||
<label>SSID<br><input id='_s' name='_s' maxlength=32 required {s}></label><br>
|
<label>SSID<br><input id='_s' name='_s' maxlength=32 required placeholder='SSID' {s}></label><br>
|
||||||
<label>Heslo<br><input id='_p' name='_p' maxlength=64 {p} type='password'></label><br>
|
<label>Heslo<br><input id='_p' name='_p' maxlength=64 {p} type='password' placeholder='heslo'></label><br>
|
||||||
<label>Jméno zařízení<br><input name='_n' maxlength=32 pattern='^[a-zA-Z][a-zA-Z0-9-_\\.]{1,32}$' title='Jméno dle NetBios konvence (max. 16 znaků písmena, čísla a znaky "_.")' {n}></label><br>
|
|
||||||
<div>
|
<div>
|
||||||
<label><input id='_a' name='_a' type='checkbox' style="width: 10%; float: left; margin-top: 5px;" onclick='hAP();' {a}>Režim AP</label>
|
<label><input id='_a' name='_a' type='checkbox' style="width: 10%; float: left; margin-top: 5px;" onclick='hAP();' {a}>Režim AP</label>
|
||||||
<div id="apconfig">
|
<div id="apconfig">
|
||||||
@ -56,12 +56,12 @@ static const char PAGE_INDEX2[] PROGMEM = R"=====(
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label><input id='_st' name='_st' type='checkbox' style="width: 10%; float: left; margin-top: 5px;" onclick='hSC();' {c}>Staticka IP konfigurace</label>
|
<label><input id='_st' name='_st' type='checkbox' style="width: 10%; float: left; margin-top: 5px;" onclick='hSC();' {c}>Statická IP konfigurace</label>
|
||||||
<div id="staticip">
|
<div id="staticip">
|
||||||
<label>IP adresa<br><input type="text" name="_i" pattern='((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$' title='ip adresa ve formatu <cislo>.<cislo>.<cislo>.<cislo>' value='{i}'></label><br>
|
<label>IP adresa<br><input type="text" name="_i" value='{i}'></label><br>
|
||||||
<label>Síťová maska<br><input type="text" name="_m" pattern='((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$' title='ip adresa ve formatu <cislo>.<cislo>.<cislo>.<cislo>' value='{m}'></label><br>
|
<label>Síťová maska<br><input type="text" name="_m" value='{m}'></label><br>
|
||||||
<label>Síťová brána<br><input type="text" name="_g" pattern='((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$' title='ip adresa ve formatu <cislo>.<cislo>.<cislo>.<cislo>' value='{g}'></label><br>
|
<label>Síťová brána<br><input type="text" name="_g" value='{g}'></label><br>
|
||||||
<label>Server DNS<br><input type="text" name="_d" pattern='((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$' title='ip adresa ve formatu <cislo>.<cislo>.<cislo>.<cislo>' value='{d}'></label><br>
|
<label>Server DNS<br><input type="text" name="_d" value='{d}'></label><br>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>hAP();hSC();</script>
|
<script>hAP();hSC();</script>
|
||||||
@ -81,9 +81,22 @@ static const char PAGE_PARAM[] PROGMEM = R"=====(
|
|||||||
static const char PAGE_END[] PROGMEM = R"=====(
|
static const char PAGE_END[] PROGMEM = R"=====(
|
||||||
<br>
|
<br>
|
||||||
<button type='submit'>Uložit a restartovat</button></form>
|
<button type='submit'>Uložit a restartovat</button></form>
|
||||||
</div></body></html>
|
</div>)====="
|
||||||
|
#if defined APP_NAME && defined APP_VERSION
|
||||||
|
R"=====(<div style='text-align:right;font-size:11px;'><hr/>)====="
|
||||||
|
APP_NAME
|
||||||
|
" v"
|
||||||
|
APP_VERSION
|
||||||
|
R"=====(</div>
|
||||||
|
)====="
|
||||||
|
#else
|
||||||
|
R"=====(<div style='text-align:right;font-size:11px;'><hr/><a href='http://xpablo.cz' target='_blank' style='color:#aaa;'>WiFiConfig by xPablo</a></div>)====="
|
||||||
|
#endif
|
||||||
|
R"=====(</body></html>
|
||||||
)=====";
|
)=====";
|
||||||
|
/*
|
||||||
|
<div style='text-align:right;font-size:11px;'><hr/><a href='http://xpablo.cz' target='_blank' style='color:#aaa;'>WiFiConfig by xPablo</a></div>
|
||||||
|
*/
|
||||||
// Nenalezeno zadne SSID
|
// Nenalezeno zadne SSID
|
||||||
static const char PAGE_NO_SSID[] PROGMEM = R"=====(
|
static const char PAGE_NO_SSID[] PROGMEM = R"=====(
|
||||||
<div>Nenalezená žádná síť. Občerstvi stránku pro nové hledání.</div>
|
<div>Nenalezená žádná síť. Občerstvi stránku pro nové hledání.</div>
|
||||||
@ -91,13 +104,13 @@ static const char PAGE_NO_SSID[] PROGMEM = R"=====(
|
|||||||
|
|
||||||
// Konfigurace ulozena - restartuji...
|
// Konfigurace ulozena - restartuji...
|
||||||
static const char PAGE_SAVED[] PROGMEM = R"=====(
|
static const char PAGE_SAVED[] PROGMEM = R"=====(
|
||||||
<!DOCTYPE html><html lang="cs"><head><meta http-equiv="refresh" content="10;url=/"/>
|
<!DOCTYPE html><html lang="cs"><head><meta http-equiv="refresh" content="5;url=/"/>
|
||||||
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1"/>
|
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1"/>
|
||||||
<title>xPablo Setup - Konfigurace uložena</title>
|
<title>xPablo Setup - Konfigurace uložena</title>
|
||||||
<style>div,input {margin-bottom: 5px;}body{width:200px;display:block;margin-left:auto;margin-right:auto;}</style>
|
<style>div,input {margin-bottom: 5px;}body{width:200px;display:block;margin-left:auto;margin-right:auto;}</style>
|
||||||
</head><body>
|
</head><body>
|
||||||
Uloženo do EEPROM...<br/>
|
Uloženo do EEPROM...<br/>
|
||||||
Restart za 10 sekund.
|
Restart za 5 sekund.
|
||||||
</body></html>
|
</body></html>
|
||||||
)=====";
|
)=====";
|
||||||
|
|
||||||
@ -106,16 +119,101 @@ 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 druhou 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"=====(
|
||||||
</div></body></html>
|
</div>
|
||||||
|
)====="
|
||||||
|
#if defined APP_NAME && defined APP_VERSION
|
||||||
|
R"=====(<div style='text-align:right;font-size:11px;'><hr/>)====="
|
||||||
|
APP_NAME
|
||||||
|
" v"
|
||||||
|
APP_VERSION
|
||||||
|
R"=====(</div>
|
||||||
|
)====="
|
||||||
|
#else
|
||||||
|
R"=====(<div style='text-align:right;font-size:11px;'><hr/><a href='http://xpablo.cz' target='_blank' style='color:#aaa;'>WiFiConfig by xPablo</a></div>)====="
|
||||||
|
#endif
|
||||||
|
R"=====(</body></html>
|
||||||
)=====";
|
)=====";
|
||||||
|
|
||||||
static const char PAGE_RESTART[] PROGMEM = R"=====(
|
static const char PAGE_RESTART[] PROGMEM = R"=====(
|
||||||
|
<!DOCTYPE html><html lang="cs"><head><meta http-equiv="refresh" content="5;url=/"/>
|
||||||
|
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1"/>
|
||||||
|
<title>xPablo Setup - Restart</title>
|
||||||
|
<style>div,input {margin-bottom: 5px;}body{width:200px;display:block;margin-left:auto;margin-right:auto;}</style>
|
||||||
|
</head><body>
|
||||||
Restartuji...
|
Restartuji...
|
||||||
|
</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