Compare commits

..

No commits in common. "master" and "6.3.4" have entirely different histories.

7 changed files with 744 additions and 836 deletions

View File

@ -8,8 +8,11 @@
# include <NetBIOS.h> # include <NetBIOS.h>
#endif #endif
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#include <EEPROM.h>
#include <WiFiConfig.h> #include <WiFiConfig.h>
#include <sysvars.hpp> #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
@ -17,24 +20,34 @@
//#define DEBUG_OUT(a) {} //#define DEBUG_OUT(a) {}
#define DEBUG_OUT(a) Serial.print(a) #define DEBUG_OUT(a) Serial.print(a)
char WiFiDeviceName[32]; // misto pro jmeno zarizeni (dodane do DNS, DHCP NBNS apod...) // 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) #if defined(ARDUINO_ARCH_ESP8266)
ESP8266WebServer wwwserver(80); // webovy server ESP8266WebServer wwwserver(80); // webovy server
#else #else
WebServer wwwserver(80); // webovy server WebServer wwwserver(80); // webovy server
#endif #endif
String content;
static char MAINPAGE[] PROGMEM = R"=====(<!DOCTYPE HTML>
<html>
Hello world from ESP8266
<p>
</html>
)=====";
static void handleRoot(void) static void handleRoot(void)
{ {
wwwserver.send_P(200, "text/html", MAINPAGE); content = F("<!DOCTYPE HTML>\n<html>Hello world from ESP8266");
content += F("<p>");
content += F("</html>");
wwwserver.send(200, "text/html", content);
} }
void ICACHE_FLASH_ATTR wcb(wificonfigstate_t state) void ICACHE_FLASH_ATTR wcb(wificonfigstate_t state)
@ -69,7 +82,7 @@ void ICACHE_FLASH_ATTR saveDevname(const char *param)
{ {
String p = param; String p = param;
svSetV(F("devname"), p); EES_storeString(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, devname), elementSize(eepromconfig_t, devname), p);
} }
void ICACHE_FLASH_ATTR setup() void ICACHE_FLASH_ATTR setup()
@ -77,16 +90,28 @@ void ICACHE_FLASH_ATTR setup()
WiFiConfig wifi; // konfigurace ESP modulu WiFiConfig wifi; // konfigurace ESP modulu
WiFiConfigUsrParameter devname("devname", "Jméno zařízení", (const char *)WiFiDeviceName, 32, saveDevname); WiFiConfigUsrParameter devname("devname", "Jméno zařízení", (const char *)WiFiDeviceName, 32, saveDevname);
LittleFS.begin(); 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(115200); Serial.begin(115200);
String dn = svGetV<String>(F("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);
if (WCR_OK != wifi.begin(fc, wcb)) // startujeme pripojeni if (WCR_OK != wifi.begin(EEPROM_WIFICONFIG_ORIGIN, fc, wcb)) // startujeme pripojeni
ESP.restart(); ESP.restart();
wwwserver.on("/", handleRoot); wwwserver.on("/", handleRoot);

View File

@ -1,91 +0,0 @@
/*
* v7.0.0- 4.3.2021 - verze s konfiguraci v JSON na souborovem systemu
*
* v6.4.0- 27.2.2021 - funkcni inicializace konfigurace
*
* v6.3.5-28.11.2020 - moznost nadefinovat titulek webove stranky a popisek okna v prohlizeci pomoci WIFICONFIG_TITLE a WIFICONFIG_WEBTITLE
*
* v6.3.4-23.3.2020 - staticka konfigurace v AP rezimu funkcni
*
* v6.3.3-27.10.2019 - volani WS_CONNECTED i v pripade, ze bezi AP
*
* 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
* konfiguraci ip adres, takze je treba je vzdycky nastavit znovu
*
* V5.6 - 1.7.2018 - BugFix - odstraneno volani _plusDecode, protoze parametry jsou nyni predavany v 'ciste' forme uz z weboveho serveru a tato metoda znehodnotila retezce, ktere obsahovaly ynak '+'
*
* V5.5 - 3.6.2018 - Flash Chip ID a ESP Chip ID jsou zobrazeny hexadecimalne v prehledove strance
*
* V5.4 - 9.1.2018 - na titulni stranku pridan duvod, proc je spusteny konfiguracni AP. Usnadni to diagnostiku pripadu, kdy se ESP nechce pripojit k AP.
*
* 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 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 .
*
* V5.1 - 3.4.2017 - Webove rozhrani upravene pro snadnejsi ovladani na telefonu/tabletu, sila signalu AP zobrazena jako barevne odliseny indikator.
*
* V5.0 - 29.10.2016- Vyuziti vlastnosti ESP, ktere si uklada wifi konfiguraci do sve vlastni flash oblasti, takze nemusim vse konfigurovat znovu po startu - doufam, ze se tim zrychli asociace s AP
* kvuli bateriove napajenym pristrojum.
*
* V4.7 - 30.8.2016 - Metody .begin se nyni vraci s wificonfigresult_t (podarilo se pripojit k AP, nepodarilo se pripojit a vyprsel timeout pro konfiguracni AP, nepodarilo se pripojit, ale je zakazane spousteni konfiguracniho AP).
* ESP NYNI NENI RESETOVAN PO VYPRSENI TIMEOUTU!!!! Je to kvuli bateriovym cidlum a DeepSleep rezimu v situaci, kdy zmizi AP, ke kteremu se bezne pripojujeme
* Odstraneno odesilani reakce na generate_204 (viz. https://github.com/tzapu/WiFiManager/issues/114)
* Zbytek MAC adresy v pripadnem SSID je nyni vzdy velkymi pismeny (UAA Unique Address Assignment)
* Kvalita signalu jednotlivych AP je nyni uvadena v % namisto uzivatelum nic nerikajicich -dBm
* Pokud do polozky timeout v .begin() metode zadame hodnotu WC_DONT_RUN_CONFIGAP, tak i po neuspesnem pokusu o pripojeni do site NENI spusteny konfiguracni AP (bateriove pristroje, stale bezici pristroje)
*
* V4.6 - 26.7.2016 - Moznost nastavit cislo kanalu pro rezim AP, nove eye-candy rozhrani.
*
* V4.5 - 20.7.2016 - Moznost konfigurovat cislo kanalu pro nastavovaci AP (default je 3), po nacteni konfiguracni stranky je nastaveny timeout na 6 minut, pokud je ve jmenu SSID pro konfiguracni
* AP znak ? (otaznik), tak je tento nahrazen HEXASCII reprezentaci 3 poslednich bytu MAC adresy AP (POZOR!!! je jina, nez STA!!!)
*
* V4.4 - 10.7.2016 - Zmena nazvu vsech privatnich metod (doplnene uvodni podtrzitko _). Pokud tam nebylo, tak napriklad nesel prelozit skript s handleNotFound pokud nebyl dopredne deklarovany (asi zmatek v Arduino preprocesoru)
*
* V4.3 - 23.6.2016 - Kazde nacteni webove stranky prodluzuje pripadny timeout pro restart zarizeni.
*
* V4.2 - 10.6.2016 - DNSServer a WebServer ukazatele jsou nyni staticke primo v modulu WiFiConfig. Predchozi verze neumoznila soucasne pouziti s knihovnami ESPAsyncWebServer z duvodu kolize nekterych definic HTTP metod
*
* V4.1 - 18.5.2016 - Nenechame SDK ukladat WiFi konfiguraci do Flash (setrime prepisy)
*
* V4.0 - 10.4.2016 - pridana moznost staticke konfigurace ip parametru. POZOR!!!! ukladani dat do EEPROM (verejne funkce) nyni nevolaji automaticky commit() kvuli snizeni poctu prepisu Flash EEPROM
* pridana moznost timeoutu pro konfiguracni AP. Pokud timeout vyprsi, tak se zarizeni automaticky restartuje, coz vyvola novy pokus o pripojeni.
*
* V3.0 - 27.2.2016 - pridana presmerovavaci stranka kvuli Captive portalu, doplneno servirovani favicon.ico, doplnena moznost zadavani uzivatelskych parametru, www server a DNS server jsou dynamicky vytvareny
*
* V2.4 - 7.2.2016 - upraveno casovani pri pripojovani k AP (zmizel delay(100))
*
* V2.3 - 5.2.2016 - pridano zverejneni jmena hosta a nastaveni tohoto jmena pro DHCP apod.
*
* V2.2 - 19.1.2016 - pridan Captive portal pri konfiguracnim AP.
*
* V2.1 - 20.9.2015 - pridano zadavani jmena zarizeni. Modul ho sice nevyuziva, ale aplikace ano a v pripade DHCP se dost hodi.
*
* V2.0 - 30.8.2015 - Podstatnym zpusobem vylepsena signalizace vnitrniho stavu, presunuto ulozeni rezimu (commit je uz zbytecny - udela se pri ukladani retezcu - uspora kodu/setreni prepisu pameti Flash)
*
* V1.2 - 23.8.2015 - BugFix - pridan chybejici eeprom.commit() po ulozeni rezimu prace
*
* V1.1 - 5.8.2015 - pridana moznost volani callback metody pri behu konfiguracniho AP (signalizace stavu uzivatelskym zpusobem)
*
* V1.0 - publikace na www.xpablo.cz
*
*/

View File

@ -10,24 +10,13 @@
"repository": "repository":
{ {
"type": "git", "type": "git",
"url": "https://git.xpablo.cz/pablo2048/WiFiConfig.git" "url": "http://git.xpablo.cz/pablo2048/WiFiConfig.git"
}, },
"dependencies": [ "version": "6.3.4",
{
"name":"encString",
"version":"https://git.xpablo.cz/xPablo.cz/encString.git"
},
{
"name":"sysvars",
"version":"https://git.xpablo.cz/xPablo.cz/sysvars.git"
}
],
"version": "7.0.0",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": ["espressif8266", "espressif32"], "platforms": ["espressif8266", "espressif32"],
"build": { "build": {
"libCompatMode": 2, "libCompatMode": 2
"libLDFMode": "deep"
} }
} }

View File

@ -1,9 +1,9 @@
name=WiFiConfig name=WiFiConfig
version=7.0.0 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 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=https://www.xpablo.cz url=http://www.xpablo.cz
architectures=esp8266,esp32 architectures=esp8266,esp32

File diff suppressed because it is too large Load Diff

View File

@ -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-21 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
@ -31,26 +31,28 @@
#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>
#include <ESPAsyncWebServer.h>
#include <DNSServer.h>
#if TEMPLATE_PLACEHOLDER != '$' #define elementSize(type, element) sizeof(((type *)0)->element)
# error 'Need to redefine TEPLATE_PLACEHOLDER to $ sign'
#endif
#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
#if not defined(WIFICFG_FILE) // Struktura konfigurace, ulozena v EEPROM
# define WIFICFG_FILE "/wifi.json" typedef struct {
#endif uint8_t mode; // rezim prace AP/STA
#if not defined(WIFICFG_OLD_FILE) uint8_t ip; // konfigurace ip (staticka/DHCP)
# define WIFICFG_OLD_FILE "/wifi.old" char ssid[32 + 2]; // SSID site
#endif char pass[64 + 2]; // heslo
uint32_t ipaddr; // ip adresa v pripade staticke konfigurace
uint32_t netmask; // sitova maska v pripade staticke konfigurace
uint32_t gateway; // sitova brana v pripade staticke konfigurace
uint32_t dns; // ip adresa DNS serveru v pripade staticke konfigurace
uint8_t apchannel; // kanal, na kterem pracuje AP (pokud je zapnuty rezim AP)
} wificonfigarea_t;
// Parametr, predany uzivatelske callback funkci, urceny pro aplikacni vizualizaci stavu konfigurace a pripojeni // Parametr, predany uzivatelske callback funkci, urceny pro aplikacni vizualizaci stavu konfigurace a pripojeni
typedef enum { typedef enum {
@ -69,19 +71,6 @@ typedef enum {
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
@ -98,6 +87,24 @@ typedef void (*storeparam_cb)(const char *newvalue); // callback pro ulozeni uzi
# define SETUP_CHANNEL 3 # define SETUP_CHANNEL 3
#endif #endif
/**
* \brief Ziskani retezce z EEPROM ze zadaneho offsetu
*
* \param [in] start Ofset zacatku retezce
* \param [in] len Delka retezce
* \return Vycteny retezec
*/
String getEEPROMString(unsigned int start, size_t len);
/**
* \brief Ulozeni retezce do EEPROM
*
* \param [in] start Ofset zacatku ukladani
* \param [in] len Maximalni delka ulozeneho retezce
* \param [in] string Ukladany retezec
*/
void setEEPROMString(unsigned int start, size_t len, String &string);
/** /**
* \brief Ziskani nasi ip adresy * \brief Ziskani nasi ip adresy
* *
@ -115,6 +122,23 @@ 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);
/**
* @brief Ulozeni 32 bitoveho cisla do EEPROM
*
* @param[in] start Pocatecni adresa, kam cislo ukladame.
* @param[in] val Ukladana hodnota
*/
void setEEPROMuint32(int start, uint32_t val);
class WiFiConfigUsrParameter class WiFiConfigUsrParameter
{ {
public: public:
@ -134,45 +158,34 @@ private:
int _length; int _length;
storeparam_cb _cb; storeparam_cb _cb;
WiFiConfigUsrParameter *_next = nullptr; WiFiConfigUsrParameter *_next;
friend class WiFiConfig;
}; };
class WiFiConfig class WiFiConfig
{ {
public: public:
WiFiConfig() WiFiConfig(): _params(NULL), _timeout(0) {}
: _params(nullptr) wificonfigresult_t begin(int configarea, int forceConfigure, wificonfig_cb cb);
, _timeout(0) wificonfigresult_t begin(int configarea, int forceConfigure, int timeout, wificonfig_cb cb);
{}
wificonfigresult_t begin(int forceConfigure, wificonfig_cb cb);
wificonfigresult_t begin(int forceConfigure, int timeout, wificonfig_cb cb);
void addParameter(WiFiConfigUsrParameter *p); void addParameter(WiFiConfigUsrParameter *p);
void initConfig(const String &ssid, const String &pass, const int mode = WIFIMODE_STA, const int ipcfg = IPCONFIG_DHCP, const IPAddress &ip = (uint32_t)0, const IPAddress &mask = (uint32_t)0, const IPAddress &gw = (uint32_t)0, const IPAddress &dns = (uint32_t)0);
private: private:
AsyncWebServer *server;
std::unique_ptr<DNSServer> dnsServer;
void _prepareWifi(void);
wificonfigresult_t _setupAP(wificonfig_cb cb); wificonfigresult_t _setupAP(wificonfig_cb cb);
void _handleDisplayAP(AsyncWebServerRequest *request); void _handleDisplayAP(void);
void _handleSetAP(AsyncWebServerRequest *request); void _handleSetAP(void);
void _handleInfo(AsyncWebServerRequest *request); void _handleInfo(void);
void _handleReset(AsyncWebServerRequest *request); void _handleReset(void);
void _handleNotFound(AsyncWebServerRequest *request); // CaptivePortal redirector void _handleNotFound(); // CaptivePortal redirector
void _handleRoot(AsyncWebServerRequest *request); // 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...)
void _handleScan(AsyncWebServerRequest *request);
void _handleRestore(AsyncWebServerRequest *request);
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);
IPAddress _getIP(const String &from);
String rootProcessor(const String &var);
String apProcessor(const String &var);
String infoProcessor(const String & var);
WiFiConfigUsrParameter *_params; // ukazatel na posledni zadany uzivatelsky parametr WiFiConfigUsrParameter *_params; // ukazatel na posledni zadany uzivatelsky parametr
int _timeout; // timeout pri cekani na konfiguraci int _timeout; // timeout pri cekani na konfiguraci
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

View File

@ -1,19 +1,10 @@
// 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 TEXTJSON[] PROGMEM = "text/json";
static const char PAGE_INDEX1[] PROGMEM = R"=====(<!DOCTYPE html> static const char PAGE_INDEX1[] PROGMEM = R"=====(
<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>)=====" WIFICONFIG_WEBTITLE R"=====(</title> <title>xPablo.cz Setup</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;}
@ -30,64 +21,66 @@ 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>)=====" WIFICONFIG_TITLE R"=====(</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;'>
<div id="ssids"> )=====";
</div>
/* Polozky nalezenych SSID
{v} - SSID
{a} - RSSI (%)
{s} - bud nic, nebo 'l'>
Rozsahy otestovany zde https://css-tricks.com/html5-meter-element/
*/
static const char SSID_ITEM[] PROGMEM = R"=====(
<div><a href='#p' onclick='c(this)'>{v}</a>&nbsp;<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
{s} - SSID
{p} - password
{a} - AP mode (checkbox)
{ch}- cislo kanalu AP
{c} - staticka IP konfigurace (checkbox)
{i} - ip adresa
{m} - maska
{g} - brana
{d} - dns server
*/
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 placeholder='SSID' value="$SSID$"></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' onfocus="this.select();" maxlength=64 value="$PASS$" type='password' placeholder='heslo'></label><br> <label>Heslo<br><input id='_p' name='_p' maxlength=64 {p} type='password' placeholder='heslo'></label><br>
<div> <div>
<label><input id='_a' name='_a' type='checkbox' style="width: 10%; float: left; margin-top: 5px;" onclick='hAP();' $APMODE$>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">
<label>Kanál<br><input type="number" name="_ch" min="1" max="13" title='cislo kanalu v intervalu 1-13' value='$APCHAN$'></label><br> <label>Kanál<br><input type="number" name="_ch" min="1" max="13" title='cislo kanalu v intervalu 1-13' value='{ch}'></label><br>
</div> </div>
</div> </div>
<div> <div>
<label><input id='_st' name='_st' type='checkbox' style="width: 10%; float: left; margin-top: 5px;" onclick='hSC();' $STATIC$>Statická 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" value='$IP$'></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" value='$MASK$'></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" value='$GATE$'></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" value='$DNS$'></label><br> <label>Server DNS<br><input type="text" name="_d" value='{d}'></label><br>
</div> </div>
</div> </div>
$USER$ <script>hAP();hSC();</script>
)=====";
// Uzivatelsky pridane polozky
static const char PAGE_PARAM_HDR[] PROGMEM = R"=====(
<hr>
<h2>Uživatelské položky</h2>
)=====";
static const char PAGE_PARAM[] PROGMEM = R"=====(
<label>{t}<br><input name='{n}' maxlength='{l}' value='{v}'></label><br>
)=====";
// Konec formulare a stranky
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>
<script>
window.onload = function() {
hAP();
hSC();
var req = new XMLHttpRequest();
req.open("GET", "/scan", true);
req.onreadystatechange = function() {
if (req.readyState != 4 || req.status != 200)
return;
ssids = document.getElementById('ssids');
data = JSON.parse(req.responseText);
status = data.status;
html = "";
if (status > 0) {
for (i= 0 ; i < status; ++i) {
lock = "";
if (data.ssids[i].secure != 0)
lock = "l";
value = data.ssids[i].rssi;
if (value <= -100)
value = 0;
else if (value >= -50)
value = 100;
else
value = 2 * (value + 100);
line = "<div><a href='#p' onclick='c(this)'>" + data.ssids[i].ssid + "</a>&nbsp;<span class='q " + lock + "'><meter value='" + value + "' min='0' low='30' optimum='70' high='60' max='100' style='width: 70%;'></meter></span></div>";
html += line;
}
ssids.innerHTML = html;
}
};
req.send();
};
</script>
</div>)=====" </div>)====="
#if defined APP_NAME && defined APP_VERSION #if defined APP_NAME && defined APP_VERSION
R"=====(<div style='text-align:right;font-size:11px;'><hr/>)=====" R"=====(<div style='text-align:right;font-size:11px;'><hr/>)====="
@ -101,17 +94,6 @@ R"=====(<div style='text-align:right;font-size:11px;'><hr/><a href='http://xpabl
#endif #endif
R"=====(</body></html> R"=====(</body></html>
)====="; )=====";
// Uzivatelsky pridane polozky
static const char PAGE_PARAM_HDR[] PROGMEM = R"=====(
<hr>
<h2>Uživatelské položky</h2>
)=====";
static const char PAGE_PARAM[] PROGMEM = R"=====(
<label>%s<br><input name='%s' maxlength='%d' value='%s'></label><br>
)=====";
/* /*
<div style='text-align:right;font-size:11px;'><hr/><a href='http://xpablo.cz' target='_blank' style='color:#aaa;'>WiFiConfig by xPablo</a></div> <div style='text-align:right;font-size:11px;'><hr/><a href='http://xpablo.cz' target='_blank' style='color:#aaa;'>WiFiConfig by xPablo</a></div>
*/ */
@ -127,18 +109,17 @@ static const char PAGE_SAVED[] PROGMEM = R"=====(
<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 Flash...<br/> Uloženo do EEPROM...<br/>
Restart za několik sekund. Restart za 5 sekund.
</body></html> </body></html>
)====="; )=====";
static const char PAGE_CAPTIVEPORTALCATCH[] PROGMEM = R"=====(<!DOCTYPE html> static const char PAGE_CAPTIVEPORTALCATCH[] PROGMEM = R"=====(
<html lang="cs"><head><meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/><title>xPablo.cz Setup</title> <!DOCTYPE html><html lang="cs"><head><meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/><title>xPablo.cz Setup</title>
<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;} .magenta { background-color: #ff00ff;}
.yellow { background-color: #FFD700;}
</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"> <form action="/config" method="get">
@ -146,17 +127,18 @@ static const char PAGE_CAPTIVEPORTALCATCH[] PROGMEM = R"=====(<!DOCTYPE html>
</form><br/> </form><br/>
<form action="/i" method="get"> <form action="/i" method="get">
<button>Informace o modulu</button> <button>Informace o modulu</button>
</form><br/> </form><br/><form action="/r" method="post">
$RESTORE$
<form action="/r" method="post">
<button class="red">Reset</button></form><br>)=====" <button class="red">Reset</button></form><br>)====="
#if defined USE_WIFICONFIG_OTAUPDATE #if defined USE_WIFICONFIG_OTAUPDATE
R"=====( R"=====(
</form><br/><form action="/u" method="get"> </form><br/><form action="/u" method="get">
<button class="magenta">Aktualizace firmware</button></form><br>)=====" <button class="magenta">Aktualizace firmware</button></form><br>)====="
#endif #endif
R"=====( ;
<div class=\"vl-info\">Pokus o připojení: $STATUS$</div>
// druha cast (mezi 1. a 2. cast muzeme doplnit dodatecne informace)
static const char PAGE_CAPTIVEPORTALCATCH2[] PROGMEM = R"=====(
</div>
)=====" )====="
#if defined APP_NAME && defined APP_VERSION #if defined APP_NAME && defined APP_VERSION
R"=====(<div style='text-align:right;font-size:11px;'><hr/>)=====" R"=====(<div style='text-align:right;font-size:11px;'><hr/>)====="
@ -171,8 +153,8 @@ R"=====(<div style='text-align:right;font-size:11px;'><hr/><a href='http://xpabl
R"=====(</body></html> R"=====(</body></html>
)====="; )=====";
static const char PAGE_RESTART[] PROGMEM = R"=====(<!DOCTYPE html> static const char PAGE_RESTART[] PROGMEM = R"=====(
<html lang="cs"><head><meta http-equiv="refresh" content="5;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 - Restart</title> <title>xPablo Setup - Restart</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>
@ -235,32 +217,3 @@ domReady(function() {
</body> </body>
</html> </html>
)====="; )=====";
static const char PAGE_INFO[] PROGMEM = R"=====(
<!DOCTYPE html><html lang="en"><head><meta charset= "utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>)=====" WIFICONFIG_WEBTITLE R"=====(</title>
<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>
</head><body><h1>)=====" WIFICONFIG_TITLE R"=====(</h1><div style='text-align:left;display:inline-block;min-width:260px;'>
<form><table><tr><th>System Info<th>
<tr><td>Core Version:<td>$SDK$
<tr><td>Flash Size:<td>$FS$ kB
<tr><td>Sketch Size/Free:<td>$SS$ kB / $FSS$ kB
<tr><td>STA MAC:<td>$STAMAC$
<tr><td>AP MAC:<td>$APMAC$
<tr><td>ESP Chip ID:<td>$ESPID$
<tr><td>Flash Chip ID:<td>$FID$
</table></form>
)=====";
static const char PAGE_RESTORE[] PROGMEM = R"=====(
<form action="/o" method="post">
<button class="yellow">Předminulá konfigurace</button>
</form><br/>
)=====";