Compare commits

..

No commits in common. "d0e01c567cb0641af09eab75f9fc1566899d395d" and "7a6f936a1a3d5b95234ee6d39ec08ac3dea8b6d6" have entirely different histories.

3 changed files with 31 additions and 10 deletions

View File

@ -1,7 +1,4 @@
/* /*
* 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.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 * V6.0 - 20.11.2018- Verze i pro ESP32
@ -104,7 +101,7 @@
#define DNS_PORT 53 #define DNS_PORT 53
extern char WiFiDeviceName[]; char WiFiDeviceName[elementSize(wificonfigarea_t, devname)]; // misto pro jmeno zarizeni (dodane do DNS, DHCP NBNS apod...)
enum enum
{ {
@ -498,12 +495,17 @@ void WiFiConfig::_handleDisplayAP(void)
if (v.length()) if (v.length())
s.replace(F("{s}"), String(FPSTR(VALUE)) + v + F("'")); s.replace(F("{s}"), String(FPSTR(VALUE)) + v + F("'"));
else else
s.replace(F("{s}"), F("")); s.replace(F("{s}"), F("placeholder='SSID'"));
v = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass)); v = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
if (v.length()) if (v.length())
s.replace(F("{p}"), String(FPSTR(VALUE)) + v + F("'")); s.replace(F("{p}"), String(FPSTR(VALUE)) + v + F("'"));
else else
s.replace(F("{p}"), F("")); s.replace(F("{p}"), F("placeholder='password'"));
v = EES_readString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname));
if (v.length())
s.replace(F("{n}"), String(FPSTR(VALUE)) + v + F("'"));
else
s.replace(F("{n}"), F("placeholder='name'"));
if (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)) == WIFIMODE_AP) if (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)) == WIFIMODE_AP)
s.replace(F("{a}"), FPSTR(CHECKED)); s.replace(F("{a}"), FPSTR(CHECKED));
else else
@ -561,6 +563,9 @@ void WiFiConfig::_handleSetAP(void)
str = server->arg(F("_p")); str = server->arg(F("_p"));
EES_storeString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass), str); EES_storeString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass), str);
str = server->arg(F("_n"));
EES_storeString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname), str);
str = server->arg(F("_a")); str = server->arg(F("_a"));
if (str.length() > 0) if (str.length() > 0)
{ {
@ -615,7 +620,9 @@ void WiFiConfig::_handleSetAP(void)
WiFi.disconnect(); // vsechno odpojime WiFi.disconnect(); // vsechno odpojime
WiFi.persistent(true); // chceme, aby si modul zapamatoval konfiguraci WiFi.persistent(true); // chceme, aby si modul zapamatoval konfiguraci
String s = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid)); String s = EES_readString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname));
strcpy(WiFiDeviceName, s.c_str());
s = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
String pass = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass)); String pass = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode))) switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)))
@ -706,8 +713,12 @@ wificonfigresult_t WiFiConfig::_setupAP(wificonfig_cb cb)
WiFi.softAPConfig(apIP, apIP, netMsk); WiFi.softAPConfig(apIP, apIP, netMsk);
if (ssid.endsWith(F("?"))) if (ssid.endsWith(F("?")))
{ {
//uint8_t amac[6];
char lmac[16]; char lmac[16];
//WiFi.softAPmacAddress(amac);
//sprintf_P(lmac, PSTR("%02X%02X%02X"), amac[3], amac[4], amac[5]);
sprintf_P(lmac, PSTR("%06X"), ESP_getChipId()); sprintf_P(lmac, PSTR("%06X"), ESP_getChipId());
ssid.replace(F("?"), String(lmac)); ssid.replace(F("?"), String(lmac));
} }
@ -759,6 +770,8 @@ bool WiFiConfig::_testWifi(wificonfig_cb cb)
// nakonfigurujeme ESP dle nove nastavenych parametru // nakonfigurujeme ESP dle nove nastavenych parametru
WiFi.disconnect(); // vsechno odpojime WiFi.disconnect(); // vsechno odpojime
String s = EES_readString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname));
strcpy(WiFiDeviceName, s.c_str());
s = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid)); s = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
String pass = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass)); String pass = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
@ -858,6 +871,9 @@ wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, wificon
else else
#endif #endif
{ {
String s = EES_readString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname));
strcpy(WiFiDeviceName, s.c_str());
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode))) switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)))
{ {
case WIFIMODE_STA: case WIFIMODE_STA:

View File

@ -48,6 +48,7 @@ typedef struct
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
char devname[32 + 2]; // jmeno zarizeni (pro NBNS plati jen 16 znaku)
uint32_t ipaddr; // ip adresa v pripade staticke konfigurace uint32_t ipaddr; // ip adresa v pripade staticke konfigurace
uint32_t netmask; // sitova maska v pripade staticke konfigurace uint32_t netmask; // sitova maska v pripade staticke konfigurace
uint32_t gateway; // sitova brana v pripade staticke konfigurace uint32_t gateway; // sitova brana v pripade staticke konfigurace
@ -142,6 +143,8 @@ uint32_t getEEPROMuint32(int start);
*/ */
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:

View File

@ -37,6 +37,7 @@ static const char SSID_ITEM[] PROGMEM = R"=====(
/* 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)
@ -47,8 +48,9 @@ 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 placeholder='SSID' {s}></label><br> <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' placeholder='heslo'></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>
<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,7 +58,7 @@ static const char PAGE_INDEX2[] PROGMEM = R"=====(
</div> </div>
</div> </div>
<div> <div>
<label><input id='_st' name='_st' type='checkbox' style="width: 10%; float: left; margin-top: 5px;" onclick='hSC();' {c}>Statická IP konfigurace</label> <label><input id='_st' name='_st' type='checkbox' style="width: 10%; float: left; margin-top: 5px;" onclick='hSC();' {c}>Staticka 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" 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á 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>