Compare commits
46 Commits
Author | SHA1 | Date | |
---|---|---|---|
6f845e1e45 | |||
170af78f28 | |||
dd4204c7a1 | |||
4cdce88ca5 | |||
6f1dd6a7ba | |||
11aaf8450f | |||
2353bfa617 | |||
7ea5b222ad | |||
f42c8a1bf3 | |||
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 | |||
7fdca6fa92 | |||
febbcefcb6 |
@ -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,129 +1,168 @@
|
|||||||
#include <ESP8266WiFi.h>
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
#include <ESP8266WebServer.h>
|
# include <ESP8266WiFi.h>
|
||||||
|
# include <ESP8266WebServer.h>
|
||||||
|
# include <ESP8266NetBIOS.h>
|
||||||
|
#else
|
||||||
|
# include <WiFi.h>
|
||||||
|
# include <WebServer.h>
|
||||||
|
# include <NetBIOS.h>
|
||||||
|
#endif
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include "src/espnbns/espnbns.h"
|
#include <WiFiConfig.h>
|
||||||
#include "src/WiFiConfig/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;
|
||||||
NBNS nbns; // Netbios (xPablo.cz)
|
|
||||||
|
|
||||||
static void handleRoot(void)
|
static void handleRoot(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
content = F("<!DOCTYPE HTML>\n<html>Hello world from ESP8266");
|
content = F("<!DOCTYPE HTML>\n<html>Hello world from ESP8266");
|
||||||
content += F("<p>");
|
content += F("<p>");
|
||||||
content += F("</html>");
|
content += F("</html>");
|
||||||
|
|
||||||
wwwserver.send(200, "text/html", content);
|
wwwserver.send(200, "text/html", content);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
case WCS_CONNECTING:
|
case WCS_CONNECTING:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WCS_CONNECTED:
|
case WCS_CONNECTED:
|
||||||
DEBUG_OUT(F("Connected.\r\n"));
|
DEBUG_OUT(F("Connected.\r\n"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WCS_CONFIGSTART:
|
case WCS_CONFIGSTART:
|
||||||
DEBUG_OUT(F("Starting config...\r\n"));
|
DEBUG_OUT(F("Starting config...\r\n"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
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(512); // zahajujeme praci s EEPROM
|
EEPROM.begin(EEPROM_SIZE); // 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
|
|
||||||
ESP.restart();
|
|
||||||
|
|
||||||
wwwserver.on("/", handleRoot);
|
uint32_t magic;
|
||||||
wwwserver.begin(); // startujeme webovy server
|
|
||||||
|
|
||||||
if (strlen(WiFiDeviceName) > 0)
|
EEPROM.get(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, magic), magic);
|
||||||
{
|
if (EEPROM_MAGIC != magic) {
|
||||||
nbns.begin(WiFiDeviceName);
|
// EEPROM ma spatny obsah
|
||||||
ArduinoOTA.setHostname(WiFiDeviceName);
|
for (unsigned int i = 0; i < EEPROM_SIZE; i++)
|
||||||
}
|
EEPROM.write(i, 0);
|
||||||
|
magic = EEPROM_MAGIC;
|
||||||
ArduinoOTA.onStart([]() {
|
EEPROM.put(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, magic), magic);
|
||||||
DEBUG_OUT(F("Start\r\n"));
|
EEPROM.commit();
|
||||||
});
|
|
||||||
ArduinoOTA.onEnd([]() {
|
|
||||||
DEBUG_OUT(F("End\r\n"));
|
|
||||||
});
|
|
||||||
ArduinoOTA.onError([](ota_error_t error) {
|
|
||||||
DEBUG_OUT(F("Error["));
|
|
||||||
DEBUG_OUT(error);
|
|
||||||
DEBUG_OUT(F("]: "));
|
|
||||||
switch (error)
|
|
||||||
{
|
|
||||||
case OTA_AUTH_ERROR:
|
|
||||||
DEBUG_OUT(F("Auth Failed\r\n"));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OTA_BEGIN_ERROR:
|
|
||||||
DEBUG_OUT(F("Begin Failed\r\n"));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OTA_CONNECT_ERROR:
|
|
||||||
DEBUG_OUT(F("Connect Failed\r\n"));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OTA_RECEIVE_ERROR:
|
|
||||||
DEBUG_OUT(F("Receive Failed\r\n"));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OTA_END_ERROR:
|
|
||||||
DEBUG_OUT(F("End Failed\r\n"));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
DEBUG_OUT(F("\r\n"));
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
ArduinoOTA.begin();
|
pinMode(PIN_FORCE_CONFIG, INPUT_PULLUP); // pin, co slouzi jako vstup tlacitka
|
||||||
|
int fc = digitalRead(PIN_FORCE_CONFIG); // pozadavek na vynucene vyvolani konfigurace
|
||||||
|
Serial.begin(115200);
|
||||||
|
String dn = EES_readString(EEPROM_CONFIG_ORIGIN + offsetof(eepromconfig_t, devname), elementSize(eepromconfig_t, devname));
|
||||||
|
strcpy(WiFiDeviceName, dn.c_str());
|
||||||
|
wifi.addParameter(&devname);
|
||||||
|
|
||||||
|
if (WCR_OK != wifi.begin(EEPROM_WIFICONFIG_ORIGIN, fc, wcb)) // startujeme pripojeni
|
||||||
|
ESP.restart();
|
||||||
|
|
||||||
|
wwwserver.on("/", handleRoot);
|
||||||
|
wwwserver.begin(); // startujeme webovy server
|
||||||
|
|
||||||
|
if (strlen(WiFiDeviceName) > 0) {
|
||||||
|
NBNS.begin(WiFiDeviceName);
|
||||||
|
ArduinoOTA.setHostname(WiFiDeviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
ArduinoOTA.onStart([]() {
|
||||||
|
DEBUG_OUT(F("Start\r\n"));
|
||||||
|
});
|
||||||
|
ArduinoOTA.onEnd([]() {
|
||||||
|
DEBUG_OUT(F("End\r\n"));
|
||||||
|
});
|
||||||
|
ArduinoOTA.onError([](ota_error_t error) {
|
||||||
|
DEBUG_OUT(F("Error["));
|
||||||
|
DEBUG_OUT(error);
|
||||||
|
DEBUG_OUT(F("]: "));
|
||||||
|
switch (error) {
|
||||||
|
case OTA_AUTH_ERROR:
|
||||||
|
DEBUG_OUT(F("Auth Failed\r\n"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OTA_BEGIN_ERROR:
|
||||||
|
DEBUG_OUT(F("Begin Failed\r\n"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OTA_CONNECT_ERROR:
|
||||||
|
DEBUG_OUT(F("Connect Failed\r\n"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OTA_RECEIVE_ERROR:
|
||||||
|
DEBUG_OUT(F("Receive Failed\r\n"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OTA_END_ERROR:
|
||||||
|
DEBUG_OUT(F("End Failed\r\n"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
DEBUG_OUT(F("\r\n"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ArduinoOTA.begin();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
wwwserver.handleClient(); // osetrujeme praci serveru
|
wwwserver.handleClient(); // osetrujeme praci serveru
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
nbns.poll();
|
|
||||||
}
|
}
|
||||||
|
10
library.json
10
library.json
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"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":
|
||||||
{
|
{
|
||||||
"name": "Pavel Brychta",
|
"name": "Pavel Brychta",
|
||||||
@ -10,12 +10,12 @@
|
|||||||
"repository":
|
"repository":
|
||||||
{
|
{
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://git.xpablo.cz/pablo2048/WiFiConfig.git"
|
"url": "https://git.xpablo.cz/pablo2048/WiFiConfig.git"
|
||||||
},
|
},
|
||||||
"version": "5.5",
|
"version": "6.4.0",
|
||||||
"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.4.0
|
version=6.4.0
|
||||||
author=Pavel Brychta
|
author=Pavel Brychta
|
||||||
maintainer=Pavel Brychta <Pablo@xpablo.cz>
|
maintainer=Pavel Brychta <pablo@xpablo.cz>
|
||||||
sentence=Enables seamless module configuration.
|
sentence=Enables seamless module configuration.
|
||||||
paragraph=With this library you can enable your ESP8266 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=https://www.xpablo.cz
|
||||||
architectures=esp8266
|
architectures=esp8266,esp32
|
||||||
|
1303
src/WiFiConfig.cpp
1303
src/WiFiConfig.cpp
File diff suppressed because it is too large
Load Diff
156
src/WiFiConfig.h
156
src/WiFiConfig.h
@ -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-21 Pavel Brychta. All rights reserved.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -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__
|
||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
#if defined(ESP8266)
|
||||||
|
# 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,53 +42,62 @@
|
|||||||
#define WC_DONT_RUN_CONFIGAP -1 // priznak, ze si neprejeme spoustet konfiguracni AP (uziva se misto parametru timeout). Urceno pro bateriove napajene pristroje
|
#define WC_DONT_RUN_CONFIGAP -1 // priznak, ze si neprejeme spoustet konfiguracni AP (uziva se misto parametru timeout). Urceno pro bateriove napajene pristroje
|
||||||
|
|
||||||
// Struktura konfigurace, ulozena v EEPROM
|
// Struktura konfigurace, ulozena v EEPROM
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
uint8_t mode; // rezim prace AP/STA
|
||||||
uint8_t mode; // rezim prace AP/STA
|
uint8_t ip; // konfigurace ip (staticka/DHCP)
|
||||||
uint8_t ip; // konfigurace ip (staticka/DHCP)
|
char ssid[32 + 2]; // SSID site
|
||||||
char ssid[32]; // SSID site
|
char pass[64 + 2]; // heslo
|
||||||
char pass[64]; // heslo
|
uint32_t ipaddr; // ip adresa v pripade staticke konfigurace
|
||||||
char devname[32]; // jmeno zarizeni (pro NBNS plati jen 16 znaku)
|
uint32_t netmask; // sitova maska v pripade staticke konfigurace
|
||||||
uint32_t ipaddr; // ip adresa v pripade staticke konfigurace
|
uint32_t gateway; // sitova brana v pripade staticke konfigurace
|
||||||
uint32_t netmask; // sitova maska v pripade staticke konfigurace
|
uint32_t dns; // ip adresa DNS serveru v pripade staticke konfigurace
|
||||||
uint32_t gateway; // sitova brana v pripade staticke konfigurace
|
uint8_t apchannel; // kanal, na kterem pracuje AP (pokud je zapnuty rezim AP)
|
||||||
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;
|
} 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/byl spusteny AP
|
||||||
WCS_CONNECTED = 2, // pripojeni bylo uspesne
|
WCS_CONFIGSTART = 3, // zacatek startu konfiguracniho AP
|
||||||
WCS_CONFIGSTART = 3, // zacatek startu konfiguracniho AP
|
WCS_CONFIGWAIT = 4, // cekame na nastaveni konfigurace pres web
|
||||||
WCS_CONFIGWAIT = 4, // cekame na nastaveni konfigurace pres web
|
WCS_CONFIGTIMEOUT = 5, // doslo k vyprseni timeoutu konfigurace, budeme se vracet s False jako vysledek z .begin(...)
|
||||||
WCS_CONFIGTIMEOUT = 5, // doslo k vyprseni timeoutu konfigurace, budeme se vracet s False jako vysledek z .begin(...)
|
} wificonfigstate_t;
|
||||||
}wificonfigstate_t;
|
|
||||||
|
|
||||||
// Navratovy parametr z volani begin() - udava, jak se podarilo WiFiConfig modulu pripojit k AP
|
// Navratovy parametr z volani begin() - udava, jak se podarilo WiFiConfig modulu pripojit k AP
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
WCR_OK = 0, // wifi pripojena/AP nastartovane (dle parametru v EEPROM)
|
||||||
WCR_OK = 0, // wifi pripojena/AP nastartovane (dle parametru v EEPROM)
|
WCR_TIMEOUT = 1, // wifi neni pripojena a vyprsel zadany timeout
|
||||||
WCR_TIMEOUT = 1, // wifi neni pripojena a vyprsel zadany timeout
|
WCR_CONFIGAP_NOT_STARTED = 2, // wifi neni pripojena a spusteni konfiguracniho AP bylo zakazane parametrem timeout (WC_DONT_RUN_CONFIGAP)
|
||||||
WCR_CONFIGAP_NOT_STARTED = 2, // wifi neni pripojena a spusteni konfiguracniho AP bylo zakazane parametrem timeout (WC_DONT_RUN_CONFIGAP)
|
} wificonfigresult_t;
|
||||||
}wificonfigresult_t;
|
|
||||||
|
// Interni reprezentace konfigurace WiFi
|
||||||
|
enum {
|
||||||
|
WIFIMODE_AP = WIFI_AP, // rezim prace jako pristupovy bod (AP)
|
||||||
|
WIFIMODE_STA = WIFI_STA, // rezim prace jako klient
|
||||||
|
WIFIMODE_AP_STA = WIFI_AP_STA // rezim prace jako klient i pristupovy bod
|
||||||
|
};
|
||||||
|
|
||||||
|
// Interni reprezentace konfigurace ip
|
||||||
|
enum {
|
||||||
|
IPCONFIG_DHCP = 0x55, // DHCP konfigurace ip adres (default)
|
||||||
|
IPCONFIG_STATIC = 0xaa // staticka konfigurace ip adres
|
||||||
|
};
|
||||||
|
|
||||||
typedef void (*wificonfig_cb)(wificonfigstate_t state); // definice callbacku
|
typedef void (*wificonfig_cb)(wificonfigstate_t state); // definice callbacku
|
||||||
|
|
||||||
typedef void (*storeparam_cb)(const char *newvalue); // callback pro ulozeni uzivatelskeho parametru
|
typedef void (*storeparam_cb)(const char *newvalue); // callback pro ulozeni uzivatelskeho parametru
|
||||||
|
|
||||||
#ifndef WIFI_STA_CONNECT_TIMEOUT
|
#ifndef WIFI_STA_CONNECT_TIMEOUT
|
||||||
#define WIFI_STA_CONNECT_TIMEOUT 15000UL // delka cekani na pripojeni k AP [ms]
|
# define WIFI_STA_CONNECT_TIMEOUT 20000UL // delka cekani na pripojeni k AP [ms]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SETUP_SSID
|
#ifndef SETUP_SSID
|
||||||
#define SETUP_SSID "ESPPBSetup_?"
|
# define SETUP_SSID "ESPPBSetup_?"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SETUP_CHANNEL
|
#ifndef SETUP_CHANNEL
|
||||||
#define SETUP_CHANNEL 3
|
# define SETUP_CHANNEL 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,7 +107,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 +116,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,32 +135,43 @@ 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();
|
||||||
const char *getLabel();
|
const char *getLabel();
|
||||||
int getValueLength();
|
int getValueLength();
|
||||||
void setNext(WiFiConfigUsrParameter *n);
|
void setNext(WiFiConfigUsrParameter *n);
|
||||||
WiFiConfigUsrParameter *getNext();
|
WiFiConfigUsrParameter *getNext();
|
||||||
void setNewValue(const char *newval);
|
void setNewValue(const char *newval);
|
||||||
private:
|
private:
|
||||||
const char *_id;
|
const char *_id;
|
||||||
const char *_label;
|
const char *_label;
|
||||||
char *_value;
|
char *_value;
|
||||||
int _length;
|
int _length;
|
||||||
|
|
||||||
storeparam_cb _cb;
|
storeparam_cb _cb;
|
||||||
WiFiConfigUsrParameter *_next;
|
WiFiConfigUsrParameter *_next;
|
||||||
|
|
||||||
friend class WiFiConfig;
|
friend class WiFiConfig;
|
||||||
};
|
};
|
||||||
@ -154,25 +179,30 @@ class WiFiConfigUsrParameter
|
|||||||
class WiFiConfig
|
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:
|
void initConfig(int cfgBase, const String &ssid, const String &pass, const int mode = WIFIMODE_STA, const int ipcfg = IPCONFIG_DHCP, const IPAddress &ip = 0, const IPAddress &mask = 0, const IPAddress &gw = 0, const IPAddress &dns = 0);
|
||||||
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...)
|
|
||||||
bool _testWifi(wificonfig_cb cb);
|
|
||||||
WiFiConfigUsrParameter *_searchUsrParameter(const char *name);
|
|
||||||
void _plusDecode(String &s);
|
|
||||||
|
|
||||||
WiFiConfigUsrParameter *_params; // ukazatel na posledni zadany uzivatelsky parametr
|
private:
|
||||||
int _timeout; // timeout pri cekani na konfiguraci
|
void _prepareWifi(void);
|
||||||
uint32_t _time; // hodnota, po ktere bude ESP restartovano (pokud je _timeout != 0)
|
wificonfigresult_t _setupAP(wificonfig_cb cb);
|
||||||
uint8_t _status; // stav pripojeni - je pouzity pro signalizaci duvodu, proc se nepripoji k AP
|
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...)
|
||||||
|
bool _testWifi(wificonfig_cb cb);
|
||||||
|
bool _storeString(unsigned int start, size_t maxlen, String &string); // sifrovany retezec, max 255 znaku
|
||||||
|
String _readString(unsigned int start, size_t maxlen); // sifrovany retezec, max. 255 znaku
|
||||||
|
WiFiConfigUsrParameter *_searchUsrParameter(const char *name);
|
||||||
|
|
||||||
|
WiFiConfigUsrParameter *_params; // ukazatel na posledni zadany uzivatelsky parametr
|
||||||
|
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
|
#endif
|
||||||
|
152
src/embHTML.h
152
src/embHTML.h
@ -1,9 +1,18 @@
|
|||||||
// 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
|
||||||
|
#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 PAGE_INDEX1[] PROGMEM = R"=====(
|
static const char PAGE_INDEX1[] PROGMEM = R"=====(
|
||||||
<!DOCTYPE html><html lang="en"><head><meta charset= "utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
<!DOCTYPE html><html lang="en"><head><meta charset= "utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||||
<title>xPablo.cz Setup</title>
|
<title>)=====" WIFICONFIG_WEBTITLE R"=====(</title>
|
||||||
<style>
|
<style>
|
||||||
.c{text-align: center;}
|
.c{text-align: center;}
|
||||||
div,input{padding:5px;font-size:1em;}
|
div,input{padding:5px;font-size:1em;}
|
||||||
@ -20,22 +29,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>)=====" WIFICONFIG_TITLE R"=====(</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 +55,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 +64,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();' {a}>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 +89,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 +112,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 +127,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"=====(
|
||||||
Restartuji...
|
<!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_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