Compare commits

...

62 Commits
v5.8 ... master

Author SHA1 Message Date
66cd08894e Debugovaci mako 2022-06-08 13:01:10 +02:00
36e0ab5f3a Snaha o zprehledneni kodu. 2022-04-01 08:06:56 +02:00
1ebcab01e7 Oprava pro preklad i pro ESP8266 2021-10-27 10:29:21 +02:00
518b1b43c8 Moznost zapnout ArduinoOTA i pri bezicim konfiguracnim AP 2021-10-27 10:22:59 +02:00
60fb85f3ff Moznost predefinovat WifiConfigAPSSID metodu pro jiny zpusob definice SSID pro konfiguracni AP. 2021-10-16 17:45:56 +02:00
3a6ddbcda4 Definice souboroveho systemu dle knihovny sysvars 2021-10-02 09:31:43 +02:00
bead5efcf4 Pridana zavislost na sysvars 2021-09-23 07:00:34 +02:00
d2e764bee0 BugFix v ulozeni gateway gate -> gw je spravne jmeno 2021-09-21 16:45:09 +02:00
9797117ab9 Moznost pouzit predminulou konfiguraci 2021-08-26 07:03:29 +02:00
610229d21d Pouziti modifikovaneho template placeholderu (nutno overit!) 2021-08-25 17:32:19 +02:00
cbeac02edc Zalohovani stare konfigurace 2021-08-24 17:09:21 +02:00
95a15b11dc Moznost pouzit editor souboroveho systemu pomoci USE_WIFICONFIG_FSEDITOR, bugfix v ID cipu pro ESP32 2021-08-07 11:20:44 +02:00
ba361b7ae4 Zavislosti knihovny 2021-07-25 14:17:50 +02:00
99a4d17097 Chybejici parametrizace USEDFS 2021-06-29 12:33:10 +02:00
8e857a1ae2 Zaklad pro verzi 7.x.x - Pouziva knihovnu sysvars, takze neni zavisla na zadnem druhu souboroveho systemu 2021-06-21 17:22:19 +02:00
5c382257e9 Merge pull request 'LittleFS' (#10) from LittleFS into master
Reviewed-on: #10
2021-06-21 17:19:55 +02:00
3f433aedc8 Lepsi popis chyby konfigurace 2021-03-05 07:51:20 +01:00
1106aa060a Zprovozneni prikladu 2021-03-05 07:41:14 +01:00
b608d36096 Upravy pro praci se sysvars 2021-03-04 17:36:43 +01:00
6f845e1e45 Ukladani default konfigurace je funkcni, odstranena obsolete funkcnost 2021-02-27 10:56:20 +01:00
170af78f28 Moznost nadefinovat vlastni titulek pro webovou stranku a popisku v prohlizeci 2020-11-28 11:40:28 +01:00
dd4204c7a1 Jina aktivace noveho nastaveni. TODO: prekontrolovat, zda neni mozne metodu vyuzit i pri ukladani nove konfigurace z webu 2020-10-22 08:52:26 +02:00
4cdce88ca5 Osetreni SSID, konciciho znakem ?, aktivace noveho nastaveni (pozor!!! mozna je problem se statickymi ip adresami - proverit... 2020-10-20 07:51:23 +02:00
6f1dd6a7ba Inicializace AP kanalu 2020-10-20 07:43:52 +02:00
11aaf8450f Priprava na ukladani predpripravene/default konfigurace 2020-10-17 12:50:42 +02:00
2353bfa617 Merge pull request 'feature/APSTA' (#8) from feature/APSTA into master
Reviewed-on: #8
2020-08-21 14:04:57 +02:00
7ea5b222ad Cekani na start AP pro ESP32 2020-08-21 14:03:36 +02:00
f42c8a1bf3 Priprava pro rezim APSTA (bezi jak STA, tak AP) 2020-06-23 10:15:28 +02:00
8d709429e0 Posun verzi 2020-05-26 10:58:16 +02:00
e83160d3d2 Prodlouzeni timeoutu pro STA pripojeni 2020-05-26 10:55:14 +02:00
baef6c322e Oprava jmena magic cisla. 2020-04-07 08:38:52 +02:00
349bc68180 Oprava padu ESP32 pri pokusu o iskani adresy pres DHCP (odkaz na popis chyby do githubu je v kodu) 2020-04-07 07:30:51 +02:00
8a95f6d69b Example i pro ESP32 2020-04-06 17:37:23 +02:00
26a65f00ac Staticka ip konfigurace v rezimu AP je funkcni. 2020-03-24 08:13:56 +01:00
48f3d58f7e Fix. posledniho odevzdani 2019-10-27 13:15:59 +01:00
304618c722 Signalizace pripojeni pri startu AP 2019-10-27 13:11:32 +01:00
c6f3e3371c Optimalizace i pro ESP32, moznost uploadu firmware 2019-10-11 16:17:54 +02:00
52648c8915 Footer, info pro ESP32, lepsi reset stranka 2019-10-04 19:30:14 +02:00
e66a3306f1 Navrh na footer 2019-10-04 13:03:23 +02:00
4033637b82 Indikace stavu pripojeni pro ESP32 2019-10-04 10:50:35 +02:00
ed1659791a Odstraneni HTML5 validatoru 2019-09-02 06:46:45 +02:00
60f106cef3 Merge branch 'feature/ipChange' of pablo2048/WiFiConfig into master 2019-08-28 12:55:44 +02:00
4590e99a54 Oprava chovani pri vynucene konfiguraci a pozadavku rychleho startu. Posun cisla verze v json 2019-08-12 11:04:01 +02:00
557d06a557 Zmena default ip adresy 2019-08-12 10:17:52 +02:00
f45d742435 Oprava demo prikladu. Funkcni i ve verzi core 2.4.2 2019-08-07 12:01:00 +02:00
3172bb0d17 Dalsi fixy v ESP32 casti 2019-01-06 11:00:45 +01:00
90618b0ae6 Undo zmena ip adresy - zatim to nepomohlo. Bugfix v ESP32 kodu. 2019-01-06 10:08:04 +01:00
7fec2df6b9 Zmena ip adresy na 10.1.1.1 kvuli Captive portalu 2018-12-21 07:43:11 +01:00
d0e01c567c Odstranena nepouzivana cast. Vse se zda byt funkcni. 2018-12-12 10:02:39 +01:00
48986510dd drobne zmeny v umisteni placeholderu 2018-12-12 09:18:58 +01:00
90da6a05e5 Verze 6.2 - pozor - zatim se nezobrazi ssid a heslo ve formulari 2018-12-12 08:52:50 +01:00
7a6f936a1a Sifrovani retezcu je nyni v externi knihovne. 2018-12-11 08:33:11 +01:00
3a8ffdcd01 Odstraneny zbytecny vypis timeoutu. 2018-11-20 16:57:26 +01:00
dc8aa8890d Reformatovani textu po zasahu VSC :-( 2018-11-20 16:53:18 +01:00
81ceb9aca9 Prvni verze s podporou ESP32 2018-11-20 16:40:15 +01:00
33f8f6a8b8 BugFix v _storeString (zapis za povolenou oblast) 2018-07-24 12:48:43 +02:00
f5fce8dee3 Posunuti verze v podpurnych souborech. 2018-07-20 08:22:28 +02:00
8c23c4eddb Merge branch 'feature/encrypt' 2018-07-20 08:19:59 +02:00
51ae416dd0 Interni metody pro sifrovane ukladani (zpetna kompatibilita) 2018-07-20 06:59:43 +02:00
a742f624fb Opravy pro preklad. 2018-07-19 12:19:54 +02:00
242238a1f0 Opraven i header. 2018-07-19 08:47:12 +02:00
f4f8915197 Pokus o sifrovani retezcu v EEPROM 2018-07-18 14:06:40 +02:00
9 changed files with 1282 additions and 894 deletions

View File

@ -2,4 +2,4 @@
![Screenshot](doc/images/Screenshot_20180507-100906.png)
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

View File

@ -1,37 +1,46 @@
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#if defined(ARDUINO_ARCH_ESP8266)
# include <ESP8266WiFi.h>
# include <ESP8266WebServer.h>
# include <ESP8266NetBIOS.h>
#else
# include <WiFi.h>
# include <WebServer.h>
# include <NetBIOS.h>
#endif
#include <ArduinoOTA.h>
#include <EEPROM.h>
#include <ESP8266NetBIOS.h>
#include <WiFiConfig.h>
#include <sysvars.hpp>
// Plati pro desticku Witty s modulem ESP-12E
#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) Serial.print(a)
char WiFiDeviceName[32]; // misto pro jmeno zarizeni (dodane do DNS, DHCP NBNS apod...)
#if defined(ARDUINO_ARCH_ESP8266)
ESP8266WebServer wwwserver(80); // webovy server
String content;
#else
WebServer wwwserver(80); // webovy server
#endif
static char MAINPAGE[] PROGMEM = R"=====(<!DOCTYPE HTML>
<html>
Hello world from ESP8266
<p>
</html>
)=====";
static void handleRoot(void)
{
content = F("<!DOCTYPE HTML>\n<html>Hello world from ESP8266");
content += F("<p>");
content += F("</html>");
wwwserver.send(200, "text/html", content);
wwwserver.send_P(200, "text/html", MAINPAGE);
}
void ICACHE_FLASH_ATTR wcb(wificonfigstate_t state)
{
switch (state)
{
switch (state) {
case WCS_CONNECTSTART:
DEBUG_OUT(F("Starting connect...\r\n"));
break;
@ -49,33 +58,41 @@ void ICACHE_FLASH_ATTR wcb(wificonfigstate_t state)
case WCS_CONFIGWAIT:
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);
svSetV(F("devname"), p);
}
void ICACHE_FLASH_ATTR setup()
{
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);
LittleFS.begin();
EEPROM.begin(512); // zahajujeme praci s EEPROM
pinMode(PIN_FORCE_CONFIG, INPUT_PULLUP); // pin, co slouzi jako vstup tlacitka
int fc = digitalRead(PIN_FORCE_CONFIG); // pozadavek na vynucene vyvolani konfigurace
Serial.begin(9600);
wifi.addParameter(&testOnly);
if (WCR_OK != wifi.begin(0, fc, wcb)) // startujeme pripojeni
Serial.begin(115200);
String dn = svGetV<String>(F("devname"));
strcpy(WiFiDeviceName, dn.c_str());
wifi.addParameter(&devname);
if (WCR_OK != wifi.begin(fc, wcb)) // startujeme pripojeni
ESP.restart();
wwwserver.on("/", handleRoot);
wwwserver.begin(); // startujeme webovy server
if (strlen(WiFiDeviceName) > 0)
{
if (strlen(WiFiDeviceName) > 0) {
NBNS.begin(WiFiDeviceName);
ArduinoOTA.setHostname(WiFiDeviceName);
}
@ -90,8 +107,7 @@ void ICACHE_FLASH_ATTR setup()
DEBUG_OUT(F("Error["));
DEBUG_OUT(error);
DEBUG_OUT(F("]: "));
switch (error)
{
switch (error) {
case OTA_AUTH_ERROR:
DEBUG_OUT(F("Auth Failed\r\n"));
break;

91
history.txt Normal file
View File

@ -0,0 +1,91 @@
/*
* 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

@ -1,6 +1,6 @@
{
"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",
"authors":
{
@ -10,13 +10,24 @@
"repository":
{
"type": "git",
"url": "http://git.xpablo.cz/pablo2048/WiFiConfig.git"
"url": "https://git.xpablo.cz/pablo2048/WiFiConfig.git"
},
"version": "5.8",
"dependencies": [
{
"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",
"frameworks": "arduino",
"platforms": "espressif8266",
"platforms": ["espressif8266", "espressif32"],
"build": {
"libCompatMode": 2
"libCompatMode": 2,
"libLDFMode": "deep"
}
}

View File

@ -1,9 +1,9 @@
name=WiFiConfig
version=5.8
version=7.0.0
author=Pavel Brychta
maintainer=Pavel Brychta <Pablo@xpablo.cz>
maintainer=Pavel Brychta <pablo@xpablo.cz>
sentence=Enables seamless module configuration.
paragraph=With this library you can enable your ESP8266 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
url=http://www.xpablo.cz
architectures=esp8266
url=https://www.xpablo.cz
architectures=esp8266,esp32

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
* @file WiFiConfig.h
* @author Pavel Brychta, http://www.xpablo.cz
*
* Copyright (c) 2015,16,17 Pavel Brychta. All rights reserved.
* Copyright (c) 2015-21 Pavel Brychta. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -24,86 +24,80 @@
* 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)
* 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__
#define __WiFiConfig_h__
#include <ESP8266WiFi.h>
#if defined(ESP8266)
# include <ESP8266WiFi.h>
#else
# include <WiFi.h>
#endif
#include <memory>
#include <ESPAsyncWebServer.h>
#include <DNSServer.h>
#define elementSize(type, element) sizeof(((type *)0)->element)
#if TEMPLATE_PLACEHOLDER != '$'
# 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
// Struktura konfigurace, ulozena v EEPROM
typedef struct
{
uint8_t mode; // rezim prace AP/STA
uint8_t ip; // konfigurace ip (staticka/DHCP)
char ssid[32]; // SSID site
char pass[64]; // heslo
char devname[32]; // jmeno zarizeni (pro NBNS plati jen 16 znaku)
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;
#if not defined(WIFICFG_FILE)
# define WIFICFG_FILE "/wifi.json"
#endif
#if not defined(WIFICFG_OLD_FILE)
# define WIFICFG_OLD_FILE "/wifi.old"
#endif
// 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_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_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(...)
}wificonfigstate_t;
} wificonfigstate_t;
// 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_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)
}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 (*storeparam_cb)(const char *newvalue); // callback pro ulozeni uzivatelskeho parametru
#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
#ifndef SETUP_SSID
#define SETUP_SSID "ESPPBSetup_?"
# define SETUP_SSID "ESPPBSetup_?"
#endif
#ifndef SETUP_CHANNEL
#define SETUP_CHANNEL 3
# define SETUP_CHANNEL 3
#endif
/**
* \brief Ziskani retezce z EEPROM ze zadaneho offsetu
*
* \param [in] start Ofset zacatku retezce
* \param [in] len Delka retezce
* \return Vycteny retezec
*/
String getEEPROMString(int start, int 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(int start, int len, String string);
/**
* \brief Ziskani nasi ip adresy
*
@ -121,16 +115,10 @@ IPAddress getOurIP(void);
*/
uint8_t * getOurMAC(uint8_t *mac);
uint32_t getEEPROMuint32(int start);
void setEEPROMuint32(int start, uint32_t val);
extern char WiFiDeviceName[]; // jmeno zarizeni, pouzivane i pro DHCP
class WiFiConfigUsrParameter
{
public:
WiFiConfigUsrParameter(const char *id, const char *label, const char *defaultValue, int length, storeparam_cb cb);
public:
WiFiConfigUsrParameter(const char *id, const char *label, const char *defaultValue, unsigned int length, storeparam_cb cb);
const char *getID();
const char *getValue();
@ -139,39 +127,52 @@ class WiFiConfigUsrParameter
void setNext(WiFiConfigUsrParameter *n);
WiFiConfigUsrParameter *getNext();
void setNewValue(const char *newval);
private:
private:
const char *_id;
const char *_label;
char *_value;
int _length;
storeparam_cb _cb;
WiFiConfigUsrParameter *_next;
friend class WiFiConfig;
WiFiConfigUsrParameter *_next = nullptr;
};
class WiFiConfig
{
public:
WiFiConfig(): _params(NULL), _timeout(0) {}
wificonfigresult_t begin(int configarea, uint8_t forceConfigure, wificonfig_cb cb);
wificonfigresult_t begin(int configarea, uint8_t forceConfigure, int timeout, wificonfig_cb cb);
WiFiConfig()
: _params(nullptr)
, _timeout(0)
{}
wificonfigresult_t begin(int forceConfigure, wificonfig_cb cb);
wificonfigresult_t begin(int forceConfigure, int timeout, wificonfig_cb cb);
void addParameter(WiFiConfigUsrParameter *p);
void initConfig(const String &ssid, const String &pass, const int mode = WIFIMODE_STA, const int ipcfg = IPCONFIG_DHCP, const IPAddress &ip = (uint32_t)0, const IPAddress &mask = (uint32_t)0, const IPAddress &gw = (uint32_t)0, const IPAddress &dns = (uint32_t)0);
private:
AsyncWebServer *server;
std::unique_ptr<DNSServer> dnsServer;
void _prepareWifi(void);
wificonfigresult_t _setupAP(wificonfig_cb cb);
void _handleDisplayAP(void);
void _handleSetAP(void);
void _handleInfo(void);
void _handleReset(void);
void _handleNotFound(); // CaptivePortal redirector
void _handleRoot(); // jen jednoducha stranka kvuli CaptivePortalu umoznuje prejit na spravnou stranku (ale nedela to...)
void _handleDisplayAP(AsyncWebServerRequest *request);
void _handleSetAP(AsyncWebServerRequest *request);
void _handleInfo(AsyncWebServerRequest *request);
void _handleReset(AsyncWebServerRequest *request);
void _handleNotFound(AsyncWebServerRequest *request); // CaptivePortal redirector
void _handleRoot(AsyncWebServerRequest *request); // 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);
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
int _timeout; // timeout pri cekani na konfiguraci
uint32_t _time; // hodnota, po ktere bude ESP restartovano (pokud je _timeout != 0)
uint8_t _status; // stav pripojeni - je pouzity pro signalizaci duvodu, proc se nepripoji k AP
};
#endif

View File

@ -1,9 +1,19 @@
// 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}
static const char TEXTHTML[] PROGMEM = "text/html";
// HTML data
#ifndef WIFICONFIG_WEBTITLE
# define WIFICONFIG_WEBTITLE "xPablo.cz Setup"
#endif
static const char PAGE_INDEX1[] PROGMEM = R"=====(
<!DOCTYPE html><html lang="en"><head><meta charset= "utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>xPablo.cz Setup</title>
#ifndef WIFICONFIG_TITLE
# define WIFICONFIG_TITLE "ESP WiFiConfig"
#endif
static const char TEXTHTML[] PROGMEM = "text/html";
static const char TEXTPLAIN[] PROGMEM = "text/plain";
static const char TEXTJSON[] PROGMEM = "text/json";
static const char PAGE_INDEX1[] PROGMEM = R"=====(<!DOCTYPE html>
<html lang="en"><head><meta charset= "utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>)=====" WIFICONFIG_WEBTITLE R"=====(</title>
<style>
.c{text-align: center;}
div,input{padding:5px;font-size:1em;}
@ -20,52 +30,76 @@ function c(l){document.getElementById('_s').value=l.innerText||l.textContent;doc
function hAP(){if (document.getElementById('_a').checked){document.getElementById('apconfig').style.display = 'block';}else{document.getElementById('apconfig').style.display = 'none';}}
function hSC(){if (document.getElementById('_st').checked){document.getElementById('staticip').style.display = 'block';}else{document.getElementById('staticip').style.display = 'none';}}
</script>
</head><body><h1>ESP8266 WiFiConfig</h1><div style='text-align:left;display:inline-block;min-width:260px;'>
)=====";
/* 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
{n} - Netbios name
{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"=====(
</head><body><h1>)=====" WIFICONFIG_TITLE R"=====(</h1><div style='text-align:left;display:inline-block;min-width:260px;'>
<div id="ssids">
</div>
<form method='post' action='s'>
<label>SSID<br><input id='_s' name='_s' maxlength=32 required {s}></label><br>
<label>Heslo<br><input id='_p' name='_p' maxlength=64 {p} type='password'></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>
<label>SSID<br><input id='_s' name='_s' maxlength=32 required placeholder='SSID' value="$SSID$"></label><br>
<label>Heslo<br><input id='_p' name='_p' onfocus="this.select();" maxlength=64 value="$PASS$" type='password' placeholder='heslo'></label><br>
<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();' $APMODE$>Režim AP</label>
<div id="apconfig">
<label>Kanál<br><input type="number" name="_ch" min="1" max="13" title='cislo kanalu v intervalu 1-13' value='{ch}'></label><br>
<label>Kanál<br><input type="number" name="_ch" min="1" max="13" title='cislo kanalu v intervalu 1-13' value='$APCHAN$'></label><br>
</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();' $STATIC$>Statická IP konfigurace</label>
<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>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á 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>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>IP adresa<br><input type="text" name="_i" value='$IP$'></label><br>
<label>Síťová maska<br><input type="text" name="_m" value='$MASK$'></label><br>
<label>Síťová brána<br><input type="text" name="_g" value='$GATE$'></label><br>
<label>Server DNS<br><input type="text" name="_d" value='$DNS$'></label><br>
</div>
</div>
<script>hAP();hSC();</script>
$USER$
<br>
<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>)====="
#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>
)=====";
// Uzivatelsky pridane polozky
@ -75,16 +109,12 @@ static const char PAGE_PARAM_HDR[] PROGMEM = R"=====(
)=====";
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>
<button type='submit'>Uložit a restartovat</button></form>
</div></body></html>
<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>
*/
// Nenalezeno zadne SSID
static const char PAGE_NO_SSID[] PROGMEM = R"=====(
<div>Nenalezená žádná síť. Občerstvi stránku pro nové hledání.</div>
@ -92,31 +122,145 @@ static const char PAGE_NO_SSID[] PROGMEM = R"=====(
// Konfigurace ulozena - restartuji...
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"/>
<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>
</head><body>
Uloženo do EEPROM...<br/>
Restart za 10 sekund.
Uloženo do Flash...<br/>
Restart za několik sekund.
</body></html>
)=====";
static const char PAGE_CAPTIVEPORTALCATCH[] PROGMEM = R"=====(
<!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>
static const char PAGE_CAPTIVEPORTALCATCH[] PROGMEM = R"=====(<!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;}
.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;}
.magenta { background-color: #ff00ff;}
.yellow { background-color: #FFD700;}
</style>
</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/>
$RESTORE$
<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
R"=====(
<div class=\"vl-info\">Pokus o připojení: $STATUS$</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>
)=====";
// druha cast (mezi 1. a druhou cast muzeme doplnit dodatecne informace)
static const char PAGE_CAPTIVEPORTALCATCH2[] PROGMEM = R"=====(
</div></body></html>
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...
</body></html>
)=====";
static const char PAGE_RESTART[] PROGMEM = R"=====(
Restartuji...
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>
)=====";
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/>
)=====";