Optimalizace i pro ESP32, moznost uploadu firmware
This commit is contained in:
parent
52648c8915
commit
c6f3e3371c
@ -12,7 +12,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://git.xpablo.cz/pablo2048/WiFiConfig.git"
|
"url": "http://git.xpablo.cz/pablo2048/WiFiConfig.git"
|
||||||
},
|
},
|
||||||
"version": "6.3.1",
|
"version": "6.3.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": ["espressif8266", "espressif32"],
|
"platforms": ["espressif8266", "espressif32"],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=WiFiConfig
|
name=WiFiConfig
|
||||||
version=6.3.1
|
version=6.3.2
|
||||||
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.
|
||||||
|
1136
src/WiFiConfig.cpp
1136
src/WiFiConfig.cpp
File diff suppressed because it is too large
Load Diff
111
src/WiFiConfig.h
111
src/WiFiConfig.h
@ -31,9 +31,9 @@
|
|||||||
#define __WiFiConfig_h__
|
#define __WiFiConfig_h__
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#else
|
#else
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -42,52 +42,49 @@
|
|||||||
#define WC_DONT_RUN_CONFIGAP -1 // priznak, ze si neprejeme spoustet konfiguracni AP (uziva se misto parametru timeout). Urceno pro bateriove napajene pristroje
|
#define WC_DONT_RUN_CONFIGAP -1 // priznak, ze si neprejeme spoustet konfiguracni AP (uziva se misto parametru timeout). Urceno pro bateriove napajene pristroje
|
||||||
|
|
||||||
// Struktura konfigurace, ulozena v EEPROM
|
// Struktura konfigurace, ulozena v EEPROM
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
uint8_t mode; // rezim prace AP/STA
|
||||||
uint8_t mode; // rezim prace AP/STA
|
uint8_t ip; // konfigurace ip (staticka/DHCP)
|
||||||
uint8_t ip; // konfigurace ip (staticka/DHCP)
|
char ssid[32 + 2]; // SSID site
|
||||||
char ssid[32 + 2]; // SSID site
|
char pass[64 + 2]; // heslo
|
||||||
char pass[64 + 2]; // heslo
|
uint32_t ipaddr; // ip adresa v pripade staticke konfigurace
|
||||||
uint32_t ipaddr; // ip adresa v pripade staticke konfigurace
|
uint32_t netmask; // sitova maska v pripade staticke konfigurace
|
||||||
uint32_t netmask; // sitova maska v pripade staticke konfigurace
|
uint32_t gateway; // sitova brana v pripade staticke konfigurace
|
||||||
uint32_t gateway; // sitova brana v pripade staticke konfigurace
|
uint32_t dns; // ip adresa DNS serveru 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)
|
||||||
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
|
||||||
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;
|
|
||||||
|
|
||||||
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 15000UL // delka cekani na pripojeni k AP [ms]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SETUP_SSID
|
#ifndef SETUP_SSID
|
||||||
#define SETUP_SSID "ESPPBSetup_?"
|
#define SETUP_SSID "ESPPBSetup_?"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SETUP_CHANNEL
|
#ifndef SETUP_CHANNEL
|
||||||
#define SETUP_CHANNEL 3
|
#define SETUP_CHANNEL 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,24 +141,24 @@ void setEEPROMuint32(int start, uint32_t val);
|
|||||||
|
|
||||||
class WiFiConfigUsrParameter
|
class WiFiConfigUsrParameter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WiFiConfigUsrParameter(const char *id, const char *label, const char *defaultValue, unsigned int length, storeparam_cb cb);
|
WiFiConfigUsrParameter(const char *id, const char *label, const char *defaultValue, unsigned int length, storeparam_cb cb);
|
||||||
|
|
||||||
const char *getID();
|
const char *getID();
|
||||||
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;
|
||||||
};
|
};
|
||||||
@ -169,26 +166,26 @@ class WiFiConfigUsrParameter
|
|||||||
class WiFiConfig
|
class WiFiConfig
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WiFiConfig(): _params(NULL), _timeout(0) {}
|
WiFiConfig(): _params(NULL), _timeout(0) {}
|
||||||
wificonfigresult_t begin(int configarea, int forceConfigure, wificonfig_cb cb);
|
wificonfigresult_t begin(int configarea, int forceConfigure, wificonfig_cb cb);
|
||||||
wificonfigresult_t begin(int configarea, int forceConfigure, int timeout, wificonfig_cb cb);
|
wificonfigresult_t begin(int configarea, int forceConfigure, int timeout, wificonfig_cb cb);
|
||||||
void addParameter(WiFiConfigUsrParameter *p);
|
void addParameter(WiFiConfigUsrParameter *p);
|
||||||
private:
|
private:
|
||||||
wificonfigresult_t _setupAP(wificonfig_cb cb);
|
wificonfigresult_t _setupAP(wificonfig_cb cb);
|
||||||
void _handleDisplayAP(void);
|
void _handleDisplayAP(void);
|
||||||
void _handleSetAP(void);
|
void _handleSetAP(void);
|
||||||
void _handleInfo(void);
|
void _handleInfo(void);
|
||||||
void _handleReset(void);
|
void _handleReset(void);
|
||||||
void _handleNotFound(); // CaptivePortal redirector
|
void _handleNotFound(); // CaptivePortal redirector
|
||||||
void _handleRoot(); // jen jednoducha stranka kvuli CaptivePortalu umoznuje prejit na spravnou stranku (ale nedela to...)
|
void _handleRoot(); // jen jednoducha stranka kvuli CaptivePortalu umoznuje prejit na spravnou stranku (ale nedela to...)
|
||||||
bool _testWifi(wificonfig_cb cb);
|
bool _testWifi(wificonfig_cb cb);
|
||||||
bool _storeString(unsigned int start, size_t maxlen, String &string); // sifrovany retezec, max 255 znaku
|
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
|
String _readString(unsigned int start, size_t maxlen); // sifrovany retezec, max. 255 znaku
|
||||||
WiFiConfigUsrParameter *_searchUsrParameter(const char *name);
|
WiFiConfigUsrParameter *_searchUsrParameter(const char *name);
|
||||||
|
|
||||||
WiFiConfigUsrParameter *_params; // ukazatel na posledni zadany uzivatelsky parametr
|
WiFiConfigUsrParameter *_params; // ukazatel na posledni zadany uzivatelsky parametr
|
||||||
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
|
||||||
|
@ -21,7 +21,7 @@ function c(l){document.getElementById('_s').value=l.innerText||l.textContent;doc
|
|||||||
function hAP(){if (document.getElementById('_a').checked){document.getElementById('apconfig').style.display = 'block';}else{document.getElementById('apconfig').style.display = 'none';}}
|
function hAP(){if (document.getElementById('_a').checked){document.getElementById('apconfig').style.display = 'block';}else{document.getElementById('apconfig').style.display = 'none';}}
|
||||||
function hSC(){if (document.getElementById('_st').checked){document.getElementById('staticip').style.display = 'block';}else{document.getElementById('staticip').style.display = 'none';}}
|
function hSC(){if (document.getElementById('_st').checked){document.getElementById('staticip').style.display = 'block';}else{document.getElementById('staticip').style.display = 'none';}}
|
||||||
</script>
|
</script>
|
||||||
</head><body><h1>ESP8266 WiFiConfig</h1><div style='text-align:left;display:inline-block;min-width:260px;'>
|
</head><body><h1>ESP WiFiConfig</h1><div style='text-align:left;display:inline-block;min-width:260px;'>
|
||||||
)=====";
|
)=====";
|
||||||
|
|
||||||
/* Polozky nalezenych SSID
|
/* Polozky nalezenych SSID
|
||||||
@ -119,10 +119,22 @@ static const char PAGE_CAPTIVEPORTALCATCH[] PROGMEM = R"=====(
|
|||||||
<style>.c{text-align: center;} div,input{padding:5px;font-size:1em;} input{width:95%;} body{text-align: center;font-family:verdana;} button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;} .q{float: right;width: 64px;text-align: right;}
|
<style>.c{text-align: center;} div,input{padding:5px;font-size:1em;} input{width:95%;} body{text-align: center;font-family:verdana;} button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;} .q{float: right;width: 64px;text-align: right;}
|
||||||
.vl-info {border-left: thick solid #1fa3ec;background: #cee6ff; text-align:left; display:inline-block; min-width:260px; margin-top:15px}
|
.vl-info {border-left: thick solid #1fa3ec;background: #cee6ff; text-align:left; display:inline-block; min-width:260px; margin-top:15px}
|
||||||
.red { background-color: #ff0000;}
|
.red { background-color: #ff0000;}
|
||||||
|
.magenta { background-color: #ff00ff;}
|
||||||
</style>
|
</style>
|
||||||
</head><body><div style='text-align:left;display:inline-block;min-width:260px;'>
|
</head><body><div style='text-align:left;display:inline-block;min-width:260px;'>
|
||||||
<form action="/config" method="get"><button>Konfigurace WiFi</button></form><br/><form action="/i" method="get"><button>Informace o modulu</button></form><br/><form action="/r" method="post"><button class="red">Reset</button></form><br>
|
<form action="/config" method="get">
|
||||||
)=====";
|
<button>Konfigurace WiFi</button>
|
||||||
|
</form><br/>
|
||||||
|
<form action="/i" method="get">
|
||||||
|
<button>Informace o modulu</button>
|
||||||
|
</form><br/><form action="/r" method="post">
|
||||||
|
<button class="red">Reset</button></form><br>)====="
|
||||||
|
#if defined USE_WIFICONFIG_OTAUPDATE
|
||||||
|
R"=====(
|
||||||
|
</form><br/><form action="/u" method="get">
|
||||||
|
<button class="magenta">Aktualizace firmware</button></form><br>)====="
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
// druha cast (mezi 1. a 2. cast muzeme doplnit dodatecne informace)
|
// druha cast (mezi 1. a 2. cast muzeme doplnit dodatecne informace)
|
||||||
static const char PAGE_CAPTIVEPORTALCATCH2[] PROGMEM = R"=====(
|
static const char PAGE_CAPTIVEPORTALCATCH2[] PROGMEM = R"=====(
|
||||||
@ -150,3 +162,58 @@ static const char PAGE_RESTART[] PROGMEM = R"=====(
|
|||||||
Restartuji...
|
Restartuji...
|
||||||
</body></html>
|
</body></html>
|
||||||
)=====";
|
)=====";
|
||||||
|
|
||||||
|
static const char PAGE_UPDATE[] PROGMEM = R"=====(
|
||||||
|
<html lang='en'>
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8'>
|
||||||
|
<meta name='viewport' content='width=device-width,initial-scale=1'/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form method="POST" action="#" enctype="multipart/form-data" id="upload_form">
|
||||||
|
<input type="file" name="update" accept='.bin' id="file">
|
||||||
|
<input type="submit" value="Update"> </form>
|
||||||
|
<div id="prg_wrap" style="border: 0px solid; width: 100%;">
|
||||||
|
<div id="prg" style="text-shadow: 2px 2px 3px black; padding: 5px 0; display: none; border: 1px solid #008aff; background: #002180; text-align: center; color: white;"></div>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
var domReady = function(callback) {
|
||||||
|
document.readyState === "interactive" || document.readyState === "complete" ? callback() : document.addEventListener("DOMContentLoaded", callback);
|
||||||
|
};
|
||||||
|
domReady(function() {
|
||||||
|
var myform = document.getElementById('upload_form');
|
||||||
|
var filez = document.getElementById('file');
|
||||||
|
myform.onsubmit = function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
var formData = new FormData();
|
||||||
|
var file = filez.files[0];
|
||||||
|
if(!file) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
formData.append("files", file, file.name);
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.upload.addEventListener("progress", function(evt) {
|
||||||
|
if(evt.lengthComputable) {
|
||||||
|
var per = Math.round((evt.loaded / evt.total) * 100);
|
||||||
|
var prg = document.getElementById('prg');
|
||||||
|
prg.innerHTML = per + "%"
|
||||||
|
prg.style.width = per + "%"
|
||||||
|
prg.style.display = "block"
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
xhr.open('POST', location.href, true);
|
||||||
|
// Set up a handler for when the request finishes.
|
||||||
|
xhr.onload = function() {
|
||||||
|
if(xhr.status === 200) {
|
||||||
|
//alert('Success');
|
||||||
|
} else {
|
||||||
|
//alert('An error occurred!');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.send(formData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
)=====";
|
||||||
|
Loading…
Reference in New Issue
Block a user