Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
7fdca6fa92 | |||
febbcefcb6 | |||
d2134e6397 | |||
d99c4dc11a | |||
36b213efde | |||
ef4be58c76 | |||
7f540c3c7a | |||
4c4f27667c |
@ -1,3 +1,5 @@
|
||||
# WiFiConfig
|
||||
|
||||

|
||||
|
||||
Knihovna pro konfiguraci WiFi rozhraní modulu ESP8266
|
BIN
doc/images/Screenshot_20180507-100906.png
Normal file
BIN
doc/images/Screenshot_20180507-100906.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 93 KiB |
@ -2,8 +2,8 @@
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <EEPROM.h>
|
||||
#include "src/espnbns/espnbns.h"
|
||||
#include "src/WiFiConfig/WiFiConfig.h"
|
||||
#include <ESP8266NetBIOS.h>
|
||||
#include <WiFiConfig.h>
|
||||
|
||||
// Plati pro desticku Witty s modulem ESP-12E
|
||||
#define PIN_FORCE_CONFIG 4
|
||||
@ -16,7 +16,6 @@
|
||||
|
||||
ESP8266WebServer wwwserver(80); // webovy server
|
||||
String content;
|
||||
NBNS nbns; // Netbios (xPablo.cz)
|
||||
|
||||
static void handleRoot(void)
|
||||
{
|
||||
@ -77,7 +76,7 @@ void ICACHE_FLASH_ATTR setup()
|
||||
|
||||
if (strlen(WiFiDeviceName) > 0)
|
||||
{
|
||||
nbns.begin(WiFiDeviceName);
|
||||
NBNS.begin(WiFiDeviceName);
|
||||
ArduinoOTA.setHostname(WiFiDeviceName);
|
||||
}
|
||||
|
||||
@ -125,5 +124,4 @@ void loop()
|
||||
{
|
||||
wwwserver.handleClient(); // osetrujeme praci serveru
|
||||
ArduinoOTA.handle();
|
||||
nbns.poll();
|
||||
}
|
||||
|
22
library.json
Normal file
22
library.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name":"WiFiConfig",
|
||||
"description":"Web based WiFi part configuration for the ESP8266 SoC",
|
||||
"keywords":"wifi,configuration",
|
||||
"authors":
|
||||
{
|
||||
"name": "Pavel Brychta",
|
||||
"maintainer": true
|
||||
},
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "http://git.xpablo.cz/pablo2048/WiFiConfig.git"
|
||||
},
|
||||
"version": "5.7",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "espressif8266",
|
||||
"build": {
|
||||
"libCompatMode": 2
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
name=WiFiConfig
|
||||
version=5.4.0
|
||||
version=5.7
|
||||
author=Pavel Brychta
|
||||
maintainer=Pavel Brychta <Pablo@xpablo.cz>
|
||||
sentence=Enables seamless module configuration.
|
||||
|
@ -1,4 +1,11 @@
|
||||
/*
|
||||
* 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
|
||||
@ -303,6 +310,7 @@ void WiFiConfig::_handleReset(void)
|
||||
void WiFiConfig::_handleInfo(void)
|
||||
{
|
||||
String reply;
|
||||
char buff[32];
|
||||
|
||||
reply.reserve(3000);
|
||||
|
||||
@ -335,10 +343,12 @@ void WiFiConfig::_handleInfo(void)
|
||||
reply.concat(macaddress);
|
||||
|
||||
reply.concat(F("<TR><TD>ESP Chip ID:<TD>"));
|
||||
reply.concat(ESP.getChipId());
|
||||
sprintf_P(buff, PSTR("%06X"), ESP.getChipId());
|
||||
reply.concat(buff);
|
||||
|
||||
reply.concat(F("<TR><TD>Flash Chip ID:<TD>"));
|
||||
reply.concat(ESP.getFlashChipId());
|
||||
sprintf_P(buff, PSTR("%08X"), ESP.getFlashChipId());
|
||||
reply.concat(buff);
|
||||
|
||||
reply.concat(F("</table></form>"));
|
||||
server->send(200, TEXTHTML, reply);
|
||||
@ -489,14 +499,6 @@ void WiFiConfig::_handleDisplayAP(void)
|
||||
server->send(200, TEXTHTML, content);
|
||||
}
|
||||
|
||||
// Deal with (potentially) plus-encoded ssid/pass
|
||||
void WiFiConfig::_plusDecode(String &s)
|
||||
{
|
||||
|
||||
for (unsigned int i = 0; i < s.length(); i++)
|
||||
s[i] = (s[i] == '+' ? ' ' : s[i]);
|
||||
}
|
||||
|
||||
void WiFiConfig::_handleSetAP(void)
|
||||
{
|
||||
uint8_t mode;
|
||||
@ -506,11 +508,9 @@ void WiFiConfig::_handleSetAP(void)
|
||||
str = server->arg(F("_s"));
|
||||
if (str.length() > 0)
|
||||
{
|
||||
_plusDecode(str);
|
||||
setEEPROMString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid), str);
|
||||
|
||||
str = server->arg(F("_p"));
|
||||
_plusDecode(str);
|
||||
setEEPROMString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass), str);
|
||||
|
||||
str = server->arg(F("_n"));
|
||||
@ -580,17 +580,21 @@ void WiFiConfig::_handleSetAP(void)
|
||||
case WIFIMODE_STA:
|
||||
{
|
||||
DEBUG_MSG("STA mode.\r\n");
|
||||
WiFi.mode(WIFI_STA); // startujeme WiFi v rezimu klienta
|
||||
if (strlen(WiFiDeviceName))
|
||||
{
|
||||
WiFi.hostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||
WiFi.begin(s.c_str(), pass.c_str());
|
||||
}
|
||||
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip)))
|
||||
{
|
||||
DEBUG_MSG("Static configuration.\r\n");
|
||||
WiFi.config(IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway))),
|
||||
IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, dns))));
|
||||
delay(100);
|
||||
}
|
||||
WiFi.mode(WIFI_STA); // startujeme WiFi v rezimu klienta
|
||||
WiFi.begin(s.c_str(), pass.c_str());
|
||||
wifi_station_set_auto_connect(true);
|
||||
delay(1000);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -598,14 +602,20 @@ void WiFiConfig::_handleSetAP(void)
|
||||
DEBUG_MSG("AP mode.\r\n");
|
||||
WiFi.mode(WIFI_AP); // startujeme AP
|
||||
if (pass.length())
|
||||
// je zadane heslo do AP
|
||||
{
|
||||
// je zadane heslo do AP
|
||||
WiFi.softAP(s.c_str(), pass.c_str(), EEPROM.read(configBase + offsetof(wificonfigarea_t, apchannel)));
|
||||
}
|
||||
else
|
||||
// otevreny AP
|
||||
WiFi.softAP(s.c_str(), NULL, EEPROM.read(configBase + offsetof(wificonfigarea_t, apchannel)));
|
||||
{
|
||||
// otevreny AP
|
||||
WiFi.softAP(s.c_str(), NULL, EEPROM.read(configBase + offsetof(wificonfigarea_t, apchannel)));
|
||||
}
|
||||
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip)))
|
||||
{
|
||||
WiFi.softAPConfig(IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway))),
|
||||
IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask))));
|
||||
}
|
||||
break;
|
||||
|
||||
default: // jakykoliv neznamy rezim (mozna zavada na EEPROM???)
|
||||
@ -739,6 +749,12 @@ wificonfigresult_t WiFiConfig::begin(int configarea, uint8_t forceConfigure, wif
|
||||
case WIFIMODE_STA:
|
||||
{
|
||||
WiFi.hostname(WiFiDeviceName); // nastavime jmeno zarizeni
|
||||
if (IPCONFIG_STATIC == EEPROM.read(configBase + offsetof(wificonfigarea_t, ip)))
|
||||
{
|
||||
DEBUG_MSG("Static configuration SET.\r\n");
|
||||
WiFi.config(IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, ipaddr))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, gateway))),
|
||||
IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, netmask))), IPAddress(getEEPROMuint32(configBase + offsetof(wificonfigarea_t, dns))));
|
||||
}
|
||||
DEBUG_MSG("STA mode.\r\n");
|
||||
if (WC_DONT_RUN_CONFIGAP == _timeout)
|
||||
result = WCR_CONFIGAP_NOT_STARTED; // nemame spoustet konfiguracni AP - vracime se hned
|
@ -168,7 +168,6 @@ private:
|
||||
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
|
||||
int _timeout; // timeout pri cekani na konfiguraci
|
@ -56,7 +56,7 @@ static const char PAGE_INDEX2[] PROGMEM = R"=====(
|
||||
</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}>Staticka 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>
|
Reference in New Issue
Block a user