mirror of
https://github.com/luc-github/ESP3D.git
synced 2025-10-31 11:56:48 -07:00
sync with devt branch
This commit is contained in:
@@ -236,6 +236,7 @@ void CONFIG::print_config()
|
||||
{
|
||||
//use biggest size for buffer
|
||||
char sbuf[MAX_PASSWORD_LENGTH+1];
|
||||
uint8_t ipbuf[4];
|
||||
byte bbuf=0;
|
||||
int ibuf=0;
|
||||
if (CONFIG::read_byte(EP_WIFI_MODE, &bbuf )) {
|
||||
@@ -257,7 +258,6 @@ void CONFIG::print_config()
|
||||
} else {
|
||||
Serial.println(F("Error reading SSID"));
|
||||
}
|
||||
//if (CONFIG::read_string(EP_PASSWORD, sbuf , MAX_PASSWORD_LENGTH))Serial.println(sbuf);
|
||||
|
||||
if (CONFIG::read_byte(EP_IP_MODE, &bbuf )) {
|
||||
Serial.print(F("IP Mode: "));
|
||||
@@ -272,23 +272,23 @@ void CONFIG::print_config()
|
||||
Serial.println(F("Error reading IP mode"));
|
||||
}
|
||||
|
||||
if (CONFIG::read_buffer(EP_IP_VALUE,(byte *)sbuf , IP_LENGTH)) {
|
||||
if (CONFIG::read_buffer(EP_IP_VALUE,(byte *)ipbuf , IP_LENGTH)) {
|
||||
Serial.print(F("IP: "));
|
||||
Serial.println(wifi_config.ip2str((byte *)sbuf));
|
||||
Serial.println(IPAddress(ipbuf).toString());
|
||||
} else {
|
||||
Serial.println(F("Error reading IP"));
|
||||
}
|
||||
|
||||
if (CONFIG::read_buffer(EP_MASK_VALUE, (byte *)sbuf , IP_LENGTH)) {
|
||||
if (CONFIG::read_buffer(EP_MASK_VALUE, (byte *)ipbuf , IP_LENGTH)) {
|
||||
Serial.print(F("Subnet: "));
|
||||
Serial.println(wifi_config.ip2str((byte *)sbuf));
|
||||
Serial.println(IPAddress(ipbuf).toString());
|
||||
} else {
|
||||
Serial.println(F("Error reading subnet"));
|
||||
}
|
||||
|
||||
if (CONFIG::read_buffer(EP_GATEWAY_VALUE, (byte *)sbuf , IP_LENGTH)) {
|
||||
if (CONFIG::read_buffer(EP_GATEWAY_VALUE, (byte *)ipbuf , IP_LENGTH)) {
|
||||
Serial.print(F("Gateway: "));
|
||||
Serial.println(wifi_config.ip2str((byte *)sbuf));
|
||||
Serial.println(IPAddress(ipbuf).toString());
|
||||
} else {
|
||||
Serial.println(F("Error reading gateway"));
|
||||
}
|
||||
@@ -443,5 +443,17 @@ void CONFIG::print_config()
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
Serial.print(F("Pin 2 Recovery: "));
|
||||
#ifdef RECOVERY_FEATURE
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
Serial.print(F("Authentication: "));
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
//comment to disable
|
||||
//MDNS_FEATURE: this feature allow type the name defined
|
||||
//in web browser by default: http:\\esp8266.local and connect
|
||||
#define MDNS_FEATURE
|
||||
//#define MDNS_FEATURE
|
||||
|
||||
//SSDD_FEATURE: this feature is a discovery protocol, supported on Windows out of the box
|
||||
#define SSDP_FEATURE
|
||||
@@ -41,16 +41,16 @@
|
||||
//TCP_IP_DATA_FEATURE: allow to connect serial from TCP/IP
|
||||
#define TCP_IP_DATA_FEATURE
|
||||
|
||||
//RECOVERY_FEATURE: allow to use GPIO2 pin as hardware reset for EEPROM, add 8s to boot time to let user to jump GPIO2 to GND
|
||||
#define RECOVERY_FEATURE
|
||||
|
||||
#ifndef CONFIG_h
|
||||
#define CONFIG_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "wifi.h"
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
//version and sources location
|
||||
#define FW_VERSION "0.6.0"
|
||||
#define FW_VERSION "0.6.1"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP8266"
|
||||
|
||||
|
||||
@@ -99,8 +99,8 @@ const byte DEFAULT_MASK_VALUE[] = {255, 255, 255, 0};
|
||||
#define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE
|
||||
const long DEFAULT_BAUD_RATE = 9600;
|
||||
const char M117_[] PROGMEM = "M117 ";
|
||||
#define DEFAULT_PHY_MODE PHY_MODE_11G
|
||||
#define DEFAULT_SLEEP_MODE MODEM_SLEEP_T
|
||||
#define DEFAULT_PHY_MODE WIFI_PHY_MODE_11G
|
||||
#define DEFAULT_SLEEP_MODE WIFI_MODEM_SLEEP
|
||||
#define DEFAULT_CHANNEL 11
|
||||
#define DEFAULT_AUTH_TYPE AUTH_WPA_PSK
|
||||
#define DEFAULT_SSID_VISIBLE 1
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<BR><BR>
|
||||
if not redirected, <a href='http://$WEB_ADDRESS$'>click here</a>
|
||||
<BR><BR>
|
||||
<PROGRESS name='prg' id='prg'>
|
||||
<PROGRESS name='prg' id='prg'></PROGRESS>
|
||||
|
||||
<script>
|
||||
var i = 0;
|
||||
|
||||
@@ -10,7 +10,7 @@ $INCLUDE[css.inc]$
|
||||
<body>
|
||||
<div class="container"><table class="nav">
|
||||
<tr width=100%>
|
||||
<td class="$MENU_HOME$"><a href="http://$WEB_ADDRESS$">Home</a></td>
|
||||
<td class="$MENU_HOME$"><a href="http://$WEB_ADDRESS$/HOME">Home</a></td>
|
||||
<td class="$MENU_SYSTEM$"><a href="http://$WEB_ADDRESS$/CONFIGSYS">System</a></td>
|
||||
<td class="$MENU_AP$"><a href="http://$WEB_ADDRESS$/CONFIGAP">Access Point</a></td>
|
||||
<td class="$MENU_STA$"><a href="http://$WEB_ADDRESS$/CONFIGSTA">Station</a></td>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<BODY>
|
||||
<CENTER>Restarting, please wait....
|
||||
<BR>
|
||||
<PROGRESS name='prg' id='prg'>
|
||||
<PROGRESS name='prg' id='prg'></PROGRESS>
|
||||
</CENTER>
|
||||
<script>
|
||||
var i = 0;
|
||||
|
||||
@@ -26,7 +26,7 @@ $SLEEP_MODE_OPTIONS_LIST$
|
||||
</select></div>
|
||||
<div class="form-group $WEB_PORT_STATUS$"><label class="control-label" for="CONFIG3">Web port:</label><br>
|
||||
<input type="number" class="form-control" id="CONFIG3" name="WEBPORT" min="1" max="65000" step="1" placeholder="1~65000" value="$WEB_PORT$" style="width: auto;"></div>
|
||||
<div class="form-group $DATA_PORT_STATUS$" style="$DATA_PORT_VISIBILITY$"><label class="control-label" for="CONFIG4">Data port:</label><br>
|
||||
<div id='dataport' class="form-group $DATA_PORT_STATUS$" style="$DATA_PORT_VISIBILITY$"><label class="control-label" for="CONFIG4">Data port:</label><br>
|
||||
<input type="number" class="form-control" id="CONFIG4" name="DATAPORT" min="1" max="65000" step="1" placeholder="1~65000" value="$DATA_PORT$" style="width: auto;"></div>
|
||||
<div class="alert alert-danger" role="alert" style="$ERROR_MSG_VISIBILITY$" >
|
||||
$ERROR_MSG$
|
||||
@@ -69,6 +69,8 @@ document.getElementById('upload-button').style.visibility = 'hidden';
|
||||
document.getElementById('upload-button').style.width = '0px';
|
||||
document.getElementById('system').style.visibility = 'hidden';
|
||||
document.getElementById('system').style.height = '0px';
|
||||
document.getElementById('dataport').style.visibility = 'hidden';
|
||||
document.getElementById('dataport').style.height = '0px';
|
||||
document.getElementById('msg').style.visibility = "visible";
|
||||
document.getElementById('file-select').value="";
|
||||
document.getElementById('file-select').style.visibility = 'hidden';
|
||||
|
||||
4
esp8266/data/tags.json
Normal file
4
esp8266/data/tags.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"WEB_ADDRESS":"localhost",
|
||||
"PAGE_TITLE":"Testing things..."
|
||||
}
|
||||
@@ -27,7 +27,6 @@
|
||||
#ifndef ARDUINO_ARCH_ESP8266
|
||||
#error Oops! Make sure you have 'ESP8266' compatible board selected from the 'Tools -> Boards' menu.
|
||||
#endif
|
||||
#include <SPI.h>
|
||||
#include <EEPROM.h>
|
||||
#include "config.h"
|
||||
#include "wifi.h"
|
||||
@@ -47,9 +46,6 @@ DNSServer dnsServer;
|
||||
#ifdef SSDP_FEATURE
|
||||
#include <ESP8266SSDP.h>
|
||||
#endif
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include <FS.h>
|
||||
#define MAX_SRV_CLIENTS 1
|
||||
WiFiServer * data_server;
|
||||
@@ -61,14 +57,16 @@ void setup()
|
||||
web_interface = NULL;
|
||||
data_server = NULL;
|
||||
WiFi.disconnect();
|
||||
system_update_cpu_freq(SYS_CPU_160MHZ);
|
||||
delay(8000);
|
||||
WiFi.mode(WIFI_OFF);
|
||||
bool breset_config=false;
|
||||
#ifdef RECOVERY_FEATURE
|
||||
delay(8000);
|
||||
//check if reset config is requested
|
||||
pinMode(RESET_CONFIG_PIN, INPUT);
|
||||
if (digitalRead(RESET_CONFIG_PIN)==0) {
|
||||
breset_config=true; //if requested =>reset settings
|
||||
}
|
||||
#endif
|
||||
//default baud rate
|
||||
long baud_rate=0;
|
||||
|
||||
@@ -97,7 +95,7 @@ void setup()
|
||||
delay(1000);
|
||||
//put some default value to a void some exception at first start
|
||||
WiFi.mode(WIFI_AP);
|
||||
wifi_set_phy_mode(PHY_MODE_11G);
|
||||
WiFi.setPhyMode(WIFI_PHY_MODE_11G);
|
||||
Serial.flush();
|
||||
delay(500);
|
||||
Serial.swap();
|
||||
@@ -124,6 +122,13 @@ void setup()
|
||||
size_t headerkeyssize = sizeof(headerkeys)/sizeof(char*);
|
||||
//ask server to track these headers
|
||||
web_interface->WebServer.collectHeaders(headerkeys, headerkeyssize );
|
||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||
if (WiFi.getMode()!=WIFI_STA ) {
|
||||
// if DNSServer is started with "*" for domain name, it will reply with
|
||||
// provided IP to all DNS request
|
||||
dnsServer.start(DNS_PORT, "*", WiFi.softAPIP());
|
||||
}
|
||||
#endif
|
||||
web_interface->WebServer.begin();
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
//start TCP/IP interface
|
||||
@@ -137,15 +142,6 @@ void setup()
|
||||
wifi_config.mdns.addService("http", "tcp", wifi_config.iweb_port);
|
||||
#endif
|
||||
|
||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||
if (wifi_get_opmode()!=WIFI_STA ) {
|
||||
// if DNSServer is started with "*" for domain name, it will reply with
|
||||
// provided IP to all DNS request
|
||||
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
|
||||
dnsServer.start(DNS_PORT, "*", WiFi.softAPIP());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SSDP_FEATURE
|
||||
String stmp;
|
||||
SSDP.setSchemaURL("description.xml");
|
||||
@@ -154,7 +150,7 @@ void setup()
|
||||
stmp=wifi_config.get_default_hostname();
|
||||
}
|
||||
SSDP.setName(stmp.c_str());
|
||||
stmp=String(system_get_chip_id());
|
||||
stmp=String(ESP.getChipId());
|
||||
SSDP.setSerialNumber(stmp.c_str());
|
||||
SSDP.setURL("/");
|
||||
SSDP.setModelName("ESP8266 01");
|
||||
@@ -172,12 +168,13 @@ void setup()
|
||||
void loop()
|
||||
{
|
||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||
if (wifi_get_opmode()!=WIFI_STA ) {
|
||||
if (WiFi.getMode()!=WIFI_STA ) {
|
||||
dnsServer.processNextRequest();
|
||||
}
|
||||
#endif
|
||||
//web requests
|
||||
web_interface->WebServer.handleClient();
|
||||
|
||||
//TODO use a method to handle serial also in class and call it instead of this one
|
||||
uint8_t i,data;
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
|
||||
@@ -46,8 +46,8 @@ extern "C" {
|
||||
#define UPLOAD_STATUS_SUCCESSFUL 3
|
||||
#define UPLOAD_STATUS_ONGOING 4
|
||||
|
||||
const char PAGE_404 [] PROGMEM ="<HTML>\n<HEAD>\n<title>Redirecting...</title> \n</HEAD>\n<BODY>\n<CENTER>Unknown page - you will be redirected...\n<BR><BR>\nif not redirected, <a href='http://$WEB_ADDRESS$'>click here</a>\n<BR><BR>\n<PROGRESS name='prg' id='prg'>\n\n<script>\nvar i = 0; \nvar x = document.getElementById(\"prg\"); \nx.max=5; \nvar interval=setInterval(function(){\ni=i+1; \nvar x = document.getElementById(\"prg\"); \nx.value=i; \nif (i>5) \n{\nclearInterval(interval);\nwindow.location.href='/';\n}\n},1000);\n</script>\n</CENTER>\n</BODY>\n</HTML>\n\n";
|
||||
const char PAGE_RESTART [] PROGMEM ="<HTML>\n<HEAD>\n<title>Restarting...</title> \n</HEAD>\n<BODY>\n<CENTER>Restarting, please wait....\n<BR>\n<PROGRESS name='prg' id='prg'>\n</CENTER>\n<script>\nvar i = 0;\nvar interval; \nvar x = document.getElementById(\"prg\"); \nx.max=40; \ninterval = setInterval(function(){\ni=i+1; \nvar x = document.getElementById(\"prg\"); \nx.value=i; \nif (i>40) \n{\nclearInterval(interval);\nwindow.location.href='/';\n}\n},1000);\n</script>\n</BODY>\n</HTML>\n";
|
||||
const char PAGE_404 [] PROGMEM ="<HTML>\n<HEAD>\n<title>Redirecting...</title> \n</HEAD>\n<BODY>\n<CENTER>Unknown page - you will be redirected...\n<BR><BR>\nif not redirected, <a href='http://$WEB_ADDRESS$'>click here</a>\n<BR><BR>\n<PROGRESS name='prg' id='prg'></PROGRESS>\n\n<script>\nvar i = 0; \nvar x = document.getElementById(\"prg\"); \nx.max=5; \nvar interval=setInterval(function(){\ni=i+1; \nvar x = document.getElementById(\"prg\"); \nx.value=i; \nif (i>5) \n{\nclearInterval(interval);\nwindow.location.href='/';\n}\n},1000);\n</script>\n</CENTER>\n</BODY>\n</HTML>\n\n";
|
||||
const char PAGE_RESTART [] PROGMEM ="<HTML>\n<HEAD>\n<title>Restarting...</title> \n</HEAD>\n<BODY>\n<CENTER>Restarting, please wait....\n<BR>\n<PROGRESS name='prg' id='prg'></PROGRESS>\n</CENTER>\n<script>\nvar i = 0;\nvar interval; \nvar x = document.getElementById(\"prg\"); \nx.max=40; \ninterval = setInterval(function(){\ni=i+1; \nvar x = document.getElementById(\"prg\"); \nx.value=i; \nif (i>40) \n{\nclearInterval(interval);\nwindow.location.href='/';\n}\n},1000);\n</script>\n</BODY>\n</HTML>\n";
|
||||
const char RESTARTCMD [] PROGMEM ="<script>setTimeout(function(){window.location.href='/RESTART'},3000);</script>";
|
||||
const char VALUE_11B[] PROGMEM = "11b";
|
||||
const char VALUE_11N[] PROGMEM = "11n";
|
||||
@@ -339,9 +339,10 @@ char * intTostr(int value)
|
||||
bool processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , STORESTRINGS_CLASS & ValuesList )
|
||||
{
|
||||
if(KeysList.size() != ValuesList.size()) { //Sanity check
|
||||
Serial.print("Error");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
LinkedList<File> myFileList = LinkedList<File>();
|
||||
String buffer2send;
|
||||
String bufferheader(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: "));
|
||||
@@ -480,6 +481,7 @@ bool processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , ST
|
||||
//send header with calculated size
|
||||
header_sent=true;
|
||||
web_interface->WebServer.sendContent(bufferheader);
|
||||
|
||||
}
|
||||
//send data
|
||||
web_interface->WebServer.sendContent(buffer2send);
|
||||
@@ -521,6 +523,7 @@ bool processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , ST
|
||||
}
|
||||
//send data
|
||||
web_interface->WebServer.sendContent(buffer2send);
|
||||
|
||||
}
|
||||
}
|
||||
//if we end size calculation loop
|
||||
@@ -701,6 +704,13 @@ void ProcessNoAlert(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesLi
|
||||
|
||||
//root insterface
|
||||
void handle_web_interface_root()
|
||||
{
|
||||
static const char HOME_PAGE [] PROGMEM = "HTTP/1.1 301 OK\r\nLocation: /HOME\r\nCache-Control: no-cache\r\n\r\n";
|
||||
web_interface->WebServer.sendContent_P(HOME_PAGE);
|
||||
}
|
||||
|
||||
//root insterface
|
||||
void handle_web_interface_home()
|
||||
{
|
||||
String stmp;
|
||||
long lstatus;
|
||||
@@ -861,7 +871,7 @@ void handle_web_interface_root()
|
||||
//IP
|
||||
stmp = "$IP_CONNECTED["+String(client_counter)+"]$";
|
||||
KeysList.add(stmp.c_str());
|
||||
ValuesList.add(wifi_config.ip2str((byte *)&station->ip));
|
||||
ValuesList.add(IPAddress((const uint8_t *)&station->ip).toString().c_str());
|
||||
//increment counter
|
||||
client_counter++;
|
||||
//go next record
|
||||
@@ -940,13 +950,13 @@ void handle_web_interface_root()
|
||||
if (wifi_get_ip_info(SOFTAP_IF,&info)) {
|
||||
//IP address
|
||||
KeysList.add(FPSTR(KEY_AP_IP));
|
||||
ValuesList.add(wifi_config.ip2str(info.ip.addr));
|
||||
ValuesList.add(IPAddress((const uint8_t *)&(info.ip.addr)).toString().c_str());
|
||||
//GW address
|
||||
KeysList.add(FPSTR(KEY_AP_GW));
|
||||
ValuesList.add(wifi_config.ip2str(info.gw.addr));
|
||||
ValuesList.add(IPAddress((const uint8_t *)&(info.gw.addr)).toString().c_str());
|
||||
//Sub Net Mask
|
||||
KeysList.add(FPSTR(KEY_AP_SUBNET));
|
||||
ValuesList.add(wifi_config.ip2str(info.netmask.addr));
|
||||
ValuesList.add(IPAddress((const uint8_t *)&(info.netmask.addr)).toString().c_str());
|
||||
} else {
|
||||
//IP address
|
||||
KeysList.add(FPSTR(KEY_AP_IP));
|
||||
@@ -1022,7 +1032,6 @@ void handle_web_interface_root()
|
||||
ValuesList.add("");
|
||||
//Firmware & Free Mem, at the end to reflect situation
|
||||
GetFreeMem(KeysList, ValuesList);
|
||||
|
||||
//process the template file and provide list of variables
|
||||
processTemplate("/home.tpl", KeysList , ValuesList);
|
||||
//need to clean to speed up memory recovery
|
||||
@@ -1525,22 +1534,23 @@ void handle_web_interface_configAP()
|
||||
}
|
||||
//IP for static IP
|
||||
if (!CONFIG::read_buffer(EP_IP_VALUE,ip_sav , IP_LENGTH) ) {
|
||||
sIP=wifi_config.ip2str((byte *)DEFAULT_IP_VALUE);
|
||||
sIP=IPAddress((const uint8_t *)DEFAULT_IP_VALUE).toString();
|
||||
|
||||
} else {
|
||||
sIP=wifi_config.ip2str(ip_sav);
|
||||
sIP=IPAddress((const uint8_t *)ip_sav).toString();
|
||||
}
|
||||
//GW for static IP
|
||||
if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,gw_sav , IP_LENGTH) ) {
|
||||
sGW=wifi_config.ip2str((byte *)DEFAULT_GATEWAY_VALUE);
|
||||
sGW=IPAddress((const uint8_t *)DEFAULT_GATEWAY_VALUE).toString();
|
||||
} else {
|
||||
sGW=wifi_config.ip2str(gw_sav);
|
||||
sGW=IPAddress((const uint8_t *)gw_sav).toString();
|
||||
}
|
||||
|
||||
//Subnet for static IP
|
||||
if (!CONFIG::read_buffer(EP_MASK_VALUE,msk_sav , IP_LENGTH) ) {
|
||||
sMask=wifi_config.ip2str((byte *)DEFAULT_MASK_VALUE);
|
||||
sMask=IPAddress((const uint8_t *)DEFAULT_MASK_VALUE).toString();
|
||||
} else {
|
||||
sMask=wifi_config.ip2str(msk_sav);
|
||||
sMask=IPAddress((const uint8_t *)msk_sav).toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1839,21 +1849,21 @@ void handle_web_interface_configSTA()
|
||||
}
|
||||
//IP for static IP
|
||||
if (!CONFIG::read_buffer(EP_IP_VALUE,ip_sav , IP_LENGTH) ) {
|
||||
sIP=wifi_config.ip2str((byte *)DEFAULT_IP_VALUE);
|
||||
sIP=IPAddress((const uint8_t *)DEFAULT_IP_VALUE).toString();
|
||||
} else {
|
||||
sIP=wifi_config.ip2str(ip_sav);
|
||||
sIP=IPAddress((const uint8_t *)ip_sav).toString();
|
||||
}
|
||||
//GW for static IP
|
||||
if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,gw_sav , IP_LENGTH) ) {
|
||||
sGW=wifi_config.ip2str((byte *)DEFAULT_GATEWAY_VALUE);
|
||||
sGW=IPAddress((const uint8_t *)DEFAULT_GATEWAY_VALUE).toString();
|
||||
} else {
|
||||
sGW=wifi_config.ip2str(gw_sav);
|
||||
sGW=IPAddress((const uint8_t *)gw_sav).toString();
|
||||
}
|
||||
//Subnet for static IP
|
||||
if (!CONFIG::read_buffer(EP_MASK_VALUE,msk_sav , IP_LENGTH) ) {
|
||||
sMask=wifi_config.ip2str((byte *)DEFAULT_MASK_VALUE);
|
||||
sMask=IPAddress((const uint8_t *)DEFAULT_MASK_VALUE).toString();
|
||||
} else {
|
||||
sMask=wifi_config.ip2str(msk_sav);
|
||||
sMask=IPAddress((const uint8_t *)msk_sav).toString();
|
||||
}
|
||||
}
|
||||
//Display values
|
||||
@@ -2534,7 +2544,7 @@ void handleSDFileList()
|
||||
//and handle not registred path
|
||||
void handle_not_found()
|
||||
{
|
||||
static const char NOT_AUTH_NF [] PROGMEM = "HTTP/1.1 301 OK\r\nLocation: /\r\nCache-Control: no-cache\r\n\r\n";
|
||||
static const char NOT_AUTH_NF [] PROGMEM = "HTTP/1.1 301 OK\r\nLocation: /HOME\r\nCache-Control: no-cache\r\n\r\n";
|
||||
|
||||
if (!web_interface->is_authenticated()) {
|
||||
web_interface->WebServer.sendContent_P(NOT_AUTH_NF);
|
||||
@@ -2833,6 +2843,7 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
|
||||
{
|
||||
//init what will handle "/"
|
||||
WebServer.on("/",HTTP_ANY, handle_web_interface_root);
|
||||
WebServer.on("/HOME",HTTP_ANY, handle_web_interface_home);
|
||||
WebServer.on("/CONFIGSYS",HTTP_ANY, handle_web_interface_configSys);
|
||||
WebServer.on("/CONFIGAP",HTTP_ANY, handle_web_interface_configAP);
|
||||
WebServer.on("/CONFIGSTA",HTTP_ANY, handle_web_interface_configSTA);
|
||||
|
||||
@@ -25,14 +25,13 @@
|
||||
#ifdef MDNS_FEATURE
|
||||
#include <ESP8266mDNS.h>
|
||||
#endif
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||
#include <DNSServer.h>
|
||||
extern DNSServer dnsServer;
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
WIFI_CONFIG::WIFI_CONFIG()
|
||||
{
|
||||
iweb_port=DEFAULT_WEB_PORT;
|
||||
@@ -65,8 +64,9 @@ const char * WIFI_CONFIG::get_default_hostname()
|
||||
return hostname;
|
||||
}
|
||||
|
||||
//no strtok so this is simplified version
|
||||
//return number of part
|
||||
//helper to convert string to IP
|
||||
//do not use IPAddress.fromString() because lack of check point and error result
|
||||
//return number of parts
|
||||
byte WIFI_CONFIG::split_ip (const char * ptr,byte * part)
|
||||
{
|
||||
if (strlen(ptr)>15 || strlen(ptr)< 7) {
|
||||
@@ -112,16 +112,7 @@ char * WIFI_CONFIG::mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH])
|
||||
return macstr;
|
||||
}
|
||||
|
||||
//just simple helper to convert IP address to string
|
||||
char * WIFI_CONFIG::ip2str(IPAddress Ip )
|
||||
{
|
||||
static char ipstr [16];
|
||||
if (0>sprintf(ipstr, "%i.%i.%i.%i",Ip[0],Ip[1],Ip[2],Ip[3])) {
|
||||
strcpy (ipstr, "0.0.0.0");
|
||||
}
|
||||
return ipstr;
|
||||
}
|
||||
|
||||
//safe setup if no connection
|
||||
void WIFI_CONFIG::Safe_Setup()
|
||||
{
|
||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||
@@ -153,24 +144,52 @@ bool WIFI_CONFIG::Setup()
|
||||
int wstatus;
|
||||
IPAddress currentIP;
|
||||
byte bflag=0;
|
||||
|
||||
byte bmode=0;
|
||||
//system_update_cpu_freq(SYS_CPU_160MHZ);
|
||||
//set the sleep mode
|
||||
if (!CONFIG::read_byte(EP_SLEEP_MODE, &bflag )) {
|
||||
return false;
|
||||
}
|
||||
wifi_set_sleep_type ((sleep_type_t)bflag);
|
||||
WiFi.setSleepMode ((WiFiSleepType_t)bflag);
|
||||
sleep_mode=bflag;
|
||||
//AP or client ?
|
||||
if (!CONFIG::read_byte(EP_WIFI_MODE, &bflag ) || !CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGTH) ||!CONFIG::read_string(EP_PASSWORD, pwd , MAX_PASSWORD_LENGTH)) {
|
||||
if (!CONFIG::read_byte(EP_WIFI_MODE, &bmode ) || !CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGTH) ||!CONFIG::read_string(EP_PASSWORD, pwd , MAX_PASSWORD_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
if (!CONFIG::read_string(EP_HOSTNAME, hostname , MAX_HOSTNAME_LENGTH)) {
|
||||
strcpy(hostname,get_default_hostname());
|
||||
}
|
||||
//disconnect if connected
|
||||
WiFi.disconnect();
|
||||
//DHCP or Static IP ?
|
||||
if (!CONFIG::read_byte(EP_IP_MODE, &bflag )) {
|
||||
return false;
|
||||
}
|
||||
if (bflag==STATIC_IP_MODE) {
|
||||
byte ip_buf[4];
|
||||
//get the IP
|
||||
if (!CONFIG::read_buffer(EP_IP_VALUE,ip_buf , IP_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||
//get the gateway
|
||||
if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,ip_buf , IP_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||
//get the mask
|
||||
if (!CONFIG::read_buffer(EP_MASK_VALUE,ip_buf , IP_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||
//apply according active wifi mode
|
||||
if (bmode==AP_MODE) {
|
||||
WiFi.softAPConfig( local_ip, gateway, subnet);
|
||||
} else {
|
||||
WiFi.config( local_ip, gateway, subnet);
|
||||
}
|
||||
}
|
||||
//this is AP mode
|
||||
if (bflag==AP_MODE) {
|
||||
if (bmode==AP_MODE) {
|
||||
WiFi.enableSTA(true);
|
||||
//setup Soft AP
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.softAP(sbuf, pwd);
|
||||
@@ -178,7 +197,7 @@ bool WIFI_CONFIG::Setup()
|
||||
if (!CONFIG::read_byte(EP_PHY_MODE, &bflag )) {
|
||||
return false;
|
||||
}
|
||||
wifi_set_phy_mode((phy_mode_t)bflag);
|
||||
WiFi.setPhyMode((WiFiPhyMode_t)bflag);
|
||||
//get current config
|
||||
struct softap_config apconfig;
|
||||
wifi_softap_get_config(&apconfig);
|
||||
@@ -206,6 +225,7 @@ bool WIFI_CONFIG::Setup()
|
||||
delay(1000);
|
||||
}
|
||||
} else {
|
||||
WiFi.enableAP(false);
|
||||
//setup station mode
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(sbuf, pwd);
|
||||
@@ -214,7 +234,7 @@ bool WIFI_CONFIG::Setup()
|
||||
if (!CONFIG::read_byte(EP_PHY_MODE, &bflag )) {
|
||||
return false;
|
||||
}
|
||||
wifi_set_phy_mode((phy_mode_t)bflag);
|
||||
WiFi.setPhyMode((WiFiPhyMode_t)bflag);
|
||||
delay(500);
|
||||
byte i=0;
|
||||
//try to connect
|
||||
@@ -244,34 +264,7 @@ bool WIFI_CONFIG::Setup()
|
||||
WiFi.hostname(hostname);
|
||||
}
|
||||
|
||||
//DHCP or Static IP ?
|
||||
if (!CONFIG::read_byte(EP_IP_MODE, &bflag )) {
|
||||
return false;
|
||||
}
|
||||
if (bflag==STATIC_IP_MODE) {
|
||||
byte ip_buf[4];
|
||||
//get the IP
|
||||
if (!CONFIG::read_buffer(EP_IP_VALUE,ip_buf , IP_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||
//get the gateway
|
||||
if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,ip_buf , IP_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||
//get the mask
|
||||
if (!CONFIG::read_buffer(EP_MASK_VALUE,ip_buf , IP_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||
//apply according active wifi mode
|
||||
if (wifi_get_opmode()==WIFI_AP || wifi_get_opmode()==WIFI_AP_STA) {
|
||||
WiFi.softAPConfig( local_ip, gateway, subnet);
|
||||
} else {
|
||||
WiFi.config( local_ip, gateway, subnet);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MDNS_FEATURE
|
||||
// Set up mDNS responder:
|
||||
if (!mdns.begin(hostname)) {
|
||||
@@ -281,7 +274,7 @@ bool WIFI_CONFIG::Setup()
|
||||
}
|
||||
#endif
|
||||
//Get IP
|
||||
if (wifi_get_opmode()==WIFI_STA) {
|
||||
if (WiFi.getMode()==WIFI_STA) {
|
||||
currentIP=WiFi.localIP();
|
||||
} else {
|
||||
currentIP=WiFi.softAPIP();
|
||||
|
||||
@@ -44,7 +44,6 @@ public:
|
||||
bool Setup();
|
||||
void Safe_Setup();
|
||||
char * mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH]);
|
||||
char * ip2str(IPAddress Ip );
|
||||
byte split_ip (const char * ptr,byte * part);
|
||||
const char * get_default_hostname();
|
||||
const char * get_hostname();
|
||||
|
||||
Reference in New Issue
Block a user