diff --git a/Page2.png b/Page2.png index 62a94d86..88df9ec1 100644 Binary files a/Page2.png and b/Page2.png differ diff --git a/esp8266/config.cpp b/esp8266/config.cpp index 243ade07..64c885ba 100644 --- a/esp8266/config.cpp +++ b/esp8266/config.cpp @@ -116,12 +116,14 @@ bool CONFIG::reset_config() if(!CONFIG::write_buffer(EP_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGH))return false; if(!CONFIG::write_buffer(EP_MASK_VALUE,DEFAULT_MASK_VALUE,IP_LENGH))return false; if(!CONFIG::write_buffer(EP_GATEWAY_VALUE,DEFAULT_GATEWAY_VALUE,IP_LENGH))return false; - if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&DEFAULT_BAUD_RATE,BAUD_LENGH))return false; + if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&DEFAULT_BAUD_RATE,INTEGER_LENGH))return false; if(!CONFIG::write_byte(EP_PHY_MODE,DEFAULT_PHY_MODE))return false; if(!CONFIG::write_byte(EP_SLEEP_MODE,DEFAULT_SLEEP_MODE))return false; if(!CONFIG::write_byte(EP_CHANNEL,DEFAULT_CHANNEL))return false; if(!CONFIG::write_byte(EP_AUTH_TYPE,DEFAULT_AUTH_TYPE))return false; if(!CONFIG::write_byte(EP_SSID_VISIBLE,DEFAULT_SSID_VISIBLE))return false; + if(!CONFIG::write_buffer(EP_WEB_PORT,(const byte *)&DEFAULT_WEB_PORT,INTEGER_LENGH))return false; + if(!CONFIG::write_buffer(EP_DATA_PORT,(const byte *)&DEFAULT_DATA_PORT,INTEGER_LENGH))return false; return true; } @@ -138,10 +140,12 @@ void CONFIG::print_config() if (CONFIG::read_buffer(EP_IP_VALUE,(byte *)sbuf , IP_LENGH))Serial.println(wifi_config.ip2str((byte *)sbuf)); if (CONFIG::read_buffer(EP_MASK_VALUE, (byte *)sbuf , IP_LENGH))Serial.println(wifi_config.ip2str((byte *)sbuf)); if (CONFIG::read_buffer(EP_GATEWAY_VALUE, (byte *)sbuf , IP_LENGH))Serial.println(wifi_config.ip2str((byte *)sbuf)); - if (CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&ibuf , BAUD_LENGH))Serial.println(ibuf); + if (CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&ibuf , INTEGER_LENGH))Serial.println(ibuf); if (CONFIG::read_byte(EP_PHY_MODE, &bbuf ))Serial.println(byte(bbuf)); if (CONFIG::read_byte(EP_SLEEP_MODE, &bbuf ))Serial.println(byte(bbuf)); if (CONFIG::read_byte(EP_CHANNEL, &bbuf ))Serial.println(byte(bbuf)); if (CONFIG::read_byte(EP_AUTH_TYPE, &bbuf ))Serial.println(byte(bbuf)); if (CONFIG::read_byte(EP_SSID_VISIBLE, &bbuf ))Serial.println(byte(bbuf)); + if (CONFIG::read_buffer(EP_WEB_PORT, (byte *)&ibuf , INTEGER_LENGH))Serial.println(ibuf); + if (CONFIG::read_buffer(EP_DATA_PORT, (byte *)&ibuf , INTEGER_LENGH))Serial.println(ibuf); } diff --git a/esp8266/config.h b/esp8266/config.h index 66130c53..06f07205 100644 --- a/esp8266/config.h +++ b/esp8266/config.h @@ -1,8 +1,8 @@ -/* +/* CONFIG.H - esp8266 configuration class Copyright (c) 2014 Luc Lebosse. All rights reserved. - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either @@ -40,67 +40,73 @@ extern "C" { #define RESET_CONFIG_PIN 2 //flags -#define AP_MODE 1 -#define CLIENT_MODE 2 -#define DHCP_MODE 1 +#define AP_MODE 1 +#define CLIENT_MODE 2 +#define DHCP_MODE 1 #define STATIC_IP_MODE 2 //position in EEPROM //AP mode = 1; Station client mode = 2 -#define EP_WIFI_MODE 0 //1 byte = flag -#define EP_SSID 1 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese -#define EP_PASSWORD 34 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese -#define EP_IP_MODE 99 //1 byte = flag -#define EP_IP_VALUE 100 //4 bytes xxx.xxx.xxx.xxx +#define EP_WIFI_MODE 0 //1 byte = flag +#define EP_SSID 1 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese +#define EP_PASSWORD 34 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese +#define EP_IP_MODE 99 //1 byte = flag +#define EP_IP_VALUE 100 //4 bytes xxx.xxx.xxx.xxx #define EP_MASK_VALUE 104 //4 bytes xxx.xxx.xxx.xxx #define EP_GATEWAY_VALUE 108 //4 bytes xxx.xxx.xxx.xxx -#define EP_BAUD_RATE 112 //4 bytes = int -#define EP_PHY_MODE 116 //1 byte = flag +#define EP_BAUD_RATE 112 //4 bytes = int +#define EP_PHY_MODE 116 //1 byte = flag #define EP_SLEEP_MODE 117 //1 byte = flag -#define EP_CHANNEL 118 //1 byte = flag -#define EP_AUTH_TYPE 119 //1 byte = flag +#define EP_CHANNEL 118 //1 byte = flag +#define EP_AUTH_TYPE 119 //1 byte = flag #define EP_SSID_VISIBLE 120 //1 byte = flag +#define EP_WEB_PORT 121 //4 bytes = int +#define EP_DATA_PORT 125 //4 bytes = int + + //default values -#define DEFAULT_WIFI_MODE AP_MODE -const char DEFAULT_SSID [] PROGMEM = "ESP8266"; +#define DEFAULT_WIFI_MODE AP_MODE +const char DEFAULT_SSID [] PROGMEM = "ESP8266"; const char DEFAULT_PASSWORD [] PROGMEM = "12345678"; -#define DEFAULT_IP_MODE STATIC_IP_MODE -const byte DEFAULT_IP_VALUE[] = {192,168,0,1}; -const byte DEFAULT_MASK_VALUE[] = {255,255,255,0}; -#define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE -const int DEFAULT_BAUD_RATE = 9600; +#define DEFAULT_IP_MODE STATIC_IP_MODE +const byte DEFAULT_IP_VALUE[] = {192, 168, 0, 1}; +const byte DEFAULT_MASK_VALUE[] = {255, 255, 255, 0}; +#define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE +const int DEFAULT_BAUD_RATE = 9600; #ifdef MDNS_FEATURE -const char LOCAL_NAME[] PROGMEM = "esp8266"; +const char LOCAL_NAME[] PROGMEM = "esp8266"; #endif -#define DEFAULT_PHY_MODE PHY_MODE_11G -#define DEFAULT_SLEEP_MODE MODEM_SLEEP_T -#define DEFAULT_CHANNEL 11 -#define DEFAULT_AUTH_TYPE AUTH_WPA_PSK -#define DEFAULT_SSID_VISIBLE 1 -#define DEFAULT_MAX_CONNECTIONS 4 -#define DEFAULT_BEACON_INTERVAL 100 +#define DEFAULT_PHY_MODE PHY_MODE_11G +#define DEFAULT_SLEEP_MODE MODEM_SLEEP_T +#define DEFAULT_CHANNEL 11 +#define DEFAULT_AUTH_TYPE AUTH_WPA_PSK +#define DEFAULT_SSID_VISIBLE 1 +#define DEFAULT_MAX_CONNECTIONS 4 +#define DEFAULT_BEACON_INTERVAL 100 +const int DEFAULT_WEB_PORT = 80; +const int DEFAULT_DATA_PORT = 8888; //sizes -#define EEPROM_SIZE 256 //max is 512 +#define EEPROM_SIZE 256 //max is 512 #define MAX_SSID_LENGH 32 #define MIN_SSID_LENGH 1 #define MAX_PASSWORD_LENGH 64 #define MIN_PASSWORD_LENGH 8 -#define IP_LENGH 4 -#define BAUD_LENGH 4 +#define IP_LENGH 4 +#define INTEGER_LENGH 4 class CONFIG { public: - static bool read_string(word pos, char byte_buffer[], word size_max); - static bool read_buffer(word pos, byte byte_buffer[], word size_buffer); - static bool read_byte(word pos, byte * value); - static bool write_string(word pos, const char * byte_buffer, word size_buffer); - static bool write_buffer(word pos, const byte * byte_buffer, word size_buffer); - static bool write_byte(word pos, const byte value); - static bool reset_config(); - static void print_config(); + static bool read_string(word pos, char byte_buffer[], word size_max); + static bool read_buffer(word pos, byte byte_buffer[], word size_buffer); + static bool read_byte(word pos, byte * value); + static bool write_string(word pos, const char * byte_buffer, word size_buffer); + static bool write_buffer(word pos, const byte * byte_buffer, word size_buffer); + static bool write_byte(word pos, const byte value); + static bool reset_config(); + static void print_config(); }; #endif diff --git a/esp8266/esp8266.ino b/esp8266/esp8266.ino index 6ca80d45..07f75cc1 100644 --- a/esp8266/esp8266.ino +++ b/esp8266/esp8266.ino @@ -42,7 +42,7 @@ extern "C" { #include "user_interface.h" } #define MAX_SRV_CLIENTS 1 -WiFiServer server(8888); +WiFiServer * data_server; WiFiClient serverClients[MAX_SRV_CLIENTS]; void setup() { @@ -56,20 +56,27 @@ void setup() { if (digitalRead(RESET_CONFIG_PIN)==0)breset_config=true;//if requested =>reset settings //default baud rate int baud_rate=0; + //check if EEPROM has value - if ( CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&baud_rate , BAUD_LENGH)) + if ( CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&baud_rate , INTEGER_LENGH)&&CONFIG::read_buffer(EP_WEB_PORT, (byte *)&(wifi_config.iweb_port) , INTEGER_LENGH)&&CONFIG::read_buffer(EP_DATA_PORT, (byte *)&(wifi_config.idata_port) , INTEGER_LENGH)) { //check if baud value is one of allowed ones if ( ! (baud_rate==9600 || baud_rate==19200 ||baud_rate==38400 ||baud_rate==57600 ||baud_rate==115200 ||baud_rate==230400) )breset_config=true;//baud rate is incorrect =>reset settings + if (wifi_config.iweb_port<1 ||wifi_config.iweb_port>65001 || wifi_config.idata_port <1 || wifi_config.idata_port >65001)breset_config=true; //out of range =>reset settings + } else breset_config=true;//cannot access to config settings=> reset settings + + //reset is requested if(breset_config) { //update EEPROM with default settings CONFIG::reset_config(); - //use default baud rate + //use default baud rate and ports baud_rate=DEFAULT_BAUD_RATE; + wifi_config.iweb_port=DEFAULT_WEB_PORT; + wifi_config.idata_port=DEFAULT_DATA_PORT; } //setup serial Serial.begin(baud_rate); @@ -77,9 +84,11 @@ void setup() { wifi_config.Setup(); delay(1000); //start interfaces - web_interface.WebServer.begin(); - server.begin(); - server.setNoDelay(true); + web_interface = new WEBINTERFACE_CLASS(wifi_config.iweb_port); + data_server = new WiFiServer (wifi_config.idata_port); + web_interface->WebServer.begin(); + data_server->begin(); + data_server->setNoDelay(true); } @@ -87,31 +96,31 @@ void setup() { void loop() { #ifdef MDNS_FEATURE // Check for any mDNS queries and send responses - wifi_config.mdns.update(); + wifi_config.Updatemdns(); #endif //web requests -web_interface.WebServer.handleClient(); +web_interface->WebServer.handleClient(); //TODO use a method to handle serial also in class and call it instead of this one uint8_t i; //check if there are any new clients - if (server.hasClient()){ + if (data_server->hasClient()){ for(i = 0; i < MAX_SRV_CLIENTS; i++){ //find free/disconnected spot if (!serverClients[i] || !serverClients[i].connected()){ if(serverClients[i]) serverClients[i].stop(); - serverClients[i] = server.available(); + serverClients[i] = data_server->available(); continue; } } //no free/disconnected spot so reject - WiFiClient serverClient = server.available(); + WiFiClient serverClient = data_server->available(); serverClient.stop(); } //check clients for data for(i = 0; i < MAX_SRV_CLIENTS; i++){ if (serverClients[i] && serverClients[i].connected()){ if(serverClients[i].available()){ - //get data from the telnet client and push it to the UART + //get data from the tpc client and push it to the UART while(serverClients[i].available()) Serial.write(serverClients[i].read()); } } @@ -121,7 +130,7 @@ uint8_t i; size_t len = Serial.available(); uint8_t sbuf[len]; Serial.readBytes(sbuf, len); - //push UART data to all connected telnet clients + //push UART data to all connected tcp clients for(i = 0; i < MAX_SRV_CLIENTS; i++){ if (serverClients[i] && serverClients[i].connected()){ serverClients[i].write(sbuf, len); diff --git a/esp8266/webinterface.cpp b/esp8266/webinterface.cpp index 30e11ecb..c5dc1cef 100644 --- a/esp8266/webinterface.cpp +++ b/esp8266/webinterface.cpp @@ -170,7 +170,6 @@ const char ERROR_QUERY[] PROGMEM = "Error in query!!"; const char ERROR_WRITING_CHANGES[] PROGMEM = "Error in writing changes!!"; const char SAVED_CHANGES[] PROGMEM = "Change saved, restarting module..."; const char SUBMIT_ID[] PROGMEM = "SUBMIT"; -const char SYS_1_ID[] PROGMEM = "SYS1"; const char BAUD_RATE_NAME[] PROGMEM = "Baud rate"; const char NETWORK_NAME[] PROGMEM = "Network"; const char SLEEP_MODE_NAME[] PROGMEM = "Sleep Mode"; @@ -180,8 +179,6 @@ const char VALUE_38400[] PROGMEM = "38400"; const char VALUE_57600[] PROGMEM = "57600"; const char VALUE_115200[] PROGMEM = "115200"; const char VALUE_230400[] PROGMEM = "230400"; -const char SYS_2_ID[] PROGMEM = "SYS2"; -const char SYS_3_ID[] PROGMEM = "SYS3"; const char VALUE_SELECTED[] PROGMEM = "selected"; const char AP_1_ID[] PROGMEM = "AP1"; const char AP_2_ID[] PROGMEM = "AP2"; @@ -211,12 +208,19 @@ const char GATEWAY_NAME[] PROGMEM = "Gateway"; const char SUBNET_NAME[] PROGMEM = "Subnet"; const char ERROR_INCORRECT_SSID[] PROGMEM = "Incorrect SSID :only char and digit, no space, limited to 33 char length"; const char ERROR_INCORRECT_PASSWORD[] PROGMEM = "Incorrect password : space not allowed, limited to 8~64 char length
"; +const char ERROR_INCORRECT_PORT[] PROGMEM = "Incorrect port : 1~65000 only
"; +const char ERROR_INCORRECT_PORT2[] PROGMEM = "Incorrect port : web port aannot be same as data port
"; const char ERROR_INCORRECT_IP_FORMAT[] PROGMEM = "Incorrect IP format, should be : xxx.xxx.xxx.xxx
"; const char SHOW_IP_BLOCK[] PROGMEM = "
"; const char HIDE_IP_BLOCK[] PROGMEM = "
"; const char AVAILABLE_APS[] PROGMEM = " AP(s) available"; const char RSSI_NAME[] PROGMEM = "Signal"; const char PROTECTED_NAME[] PROGMEM = "Protected"; +const char WEB_PORT_TITLE[] PROGMEM = "Web port:"; +const char DATA_PORT_TITLE[] PROGMEM = "Data port:"; +const char WEB_PORT_ID[] PROGMEM = "WEBPORT"; +const char DATA_PORT_ID[] PROGMEM = "DATAPORT"; +const char PORT_DESC[]PROGMEM = "1~65000"; #define MSG_SUCCESS(msg) buffer2send+=(PROGMEM2CHAR(ALERT_SUCCESS));buffer2send+=(msg);buffer2send+=(PROGMEM2CHAR(DIV_E)); #define MSG_ERROR(msg) buffer2send+=(PROGMEM2CHAR(ALERT_ERROR));buffer2send+=(msg);buffer2send+=(PROGMEM2CHAR(DIV_E)); @@ -315,10 +319,15 @@ void handle_web_interface_root() String sstatus; struct softap_config apconfig; struct ip_info info; - int istatus; + int istatus; uint8_t mac [WL_MAC_ADDR_LENGTH]; if (wifi_get_opmode()==WIFI_STA ) IP=wifi_config.ip2str(WiFi.localIP()); else IP=wifi_config.ip2str(WiFi.softAPIP()); + if (wifi_config.iweb_port!=80) + { + IP+=":"; + IP+=String(wifi_config.iweb_port); + } buffer2send+=(PROGMEM2CHAR(PAGE_HEAD_1)); buffer2send+=(PROGMEM2CHAR(PAGE_HEAD_2)); //top bar @@ -332,9 +341,12 @@ void handle_web_interface_root() LABEL_UNITS(PROGMEM2CHAR(FREE_MEM_TITLE),String(system_get_free_heap_size()).c_str(),PROGMEM2CHAR(UNIT_OCTET)) LABEL(PROGMEM2CHAR(SDK_VERSION_TITLE),system_get_sdk_version()) #ifdef MDNS_FEATURE - sstatus = PROGMEM2CHAR(HTTP_START); - sstatus+=PROGMEM2CHAR(LOCAL_NAME); - LABEL_UNITS(PROGMEM2CHAR(HTTP_MDNS_NAME),sstatus.c_str(),PROGMEM2CHAR(HTTP_END)) + if (wifi_get_opmode()==WIFI_STA ) + { + sstatus = PROGMEM2CHAR(HTTP_START); + sstatus+=PROGMEM2CHAR(LOCAL_NAME); + LABEL_UNITS(PROGMEM2CHAR(HTTP_MDNS_NAME),sstatus.c_str(),PROGMEM2CHAR(HTTP_END)) + } #endif istatus = wifi_get_phy_mode(); if (istatus==PHY_MODE_11B) sstatus=PROGMEM2CHAR(VALUE_11B); @@ -349,8 +361,14 @@ void handle_web_interface_root() //LABEL(sbuf,"Boot mode: ",String(system_get_boot_mode())) //no meaning so far LABEL(PROGMEM2CHAR(BOOT_VERSION_TITLE),String(system_get_boot_version()).c_str()) istatus=0; - if (!CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&istatus , BAUD_LENGH))istatus=0; + if (!CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&istatus , INTEGER_LENGH))istatus=0; LABEL(PROGMEM2CHAR(BAUD_RATE_TITLE),String(istatus).c_str()) + istatus=0; + if (!CONFIG::read_buffer(EP_WEB_PORT, (byte *)&istatus , INTEGER_LENGH))istatus=0; + LABEL(PROGMEM2CHAR(WEB_PORT_TITLE),String(istatus).c_str()) + istatus=0; + if (!CONFIG::read_buffer(EP_DATA_PORT, (byte *)&istatus , INTEGER_LENGH))istatus=0; + LABEL(PROGMEM2CHAR(DATA_PORT_TITLE),String(istatus).c_str()) buffer2send+=(PROGMEM2CHAR(PANEL_END)); //access point buffer2send+=(PROGMEM2CHAR(PANEL_TOP)); @@ -456,7 +474,7 @@ void handle_web_interface_root() } buffer2send+=(PROGMEM2CHAR(PANEL_END)); buffer2send+=(PROGMEM2CHAR(PAGE_BOTTOM)); - web_interface.WebServer.send(200, "text/html", buffer2send); + web_interface->WebServer.send(200, "text/html", buffer2send); } void handle_web_interface_configSys() @@ -465,20 +483,35 @@ void handle_web_interface_configSys() String buffer2send =""; int istatus=0; byte bflag=0; + char error_display[4]={0,0,0,0}; bool msg_alert_error=false; bool msg_alert_success=false; int ibaud=0; - byte bnetwork=0; + int iweb_port =0; + int idata_port =0; byte bsleepmode=0; //check is it is a submission or a display - if (web_interface.WebServer.hasArg(PROGMEM2CHAR(SUBMIT_ID))) + if (web_interface->WebServer.hasArg(PROGMEM2CHAR(SUBMIT_ID))) { //is there a correct list of values? - if (web_interface.WebServer.hasArg(PROGMEM2CHAR(BAUD_RATE_ID)) && web_interface.WebServer.hasArg(PROGMEM2CHAR(SLEEP_MODE_ID))) + if (web_interface->WebServer.hasArg(PROGMEM2CHAR(BAUD_RATE_ID)) && web_interface->WebServer.hasArg(PROGMEM2CHAR(SLEEP_MODE_ID))&& web_interface->WebServer.hasArg(PROGMEM2CHAR(WEB_PORT_ID))&& web_interface->WebServer.hasArg(PROGMEM2CHAR(DATA_PORT_ID))) { //is each value correct ? - ibaud = atoi(web_interface.WebServer.arg(PROGMEM2CHAR(BAUD_RATE_ID)).c_str()); - bsleepmode = atoi(web_interface.WebServer.arg(PROGMEM2CHAR(SLEEP_MODE_ID)).c_str()); + ibaud = atoi(web_interface->WebServer.arg(PROGMEM2CHAR(BAUD_RATE_ID)).c_str()); + iweb_port = atoi(web_interface->WebServer.arg(PROGMEM2CHAR(WEB_PORT_ID)).c_str()); + idata_port = atoi(web_interface->WebServer.arg(PROGMEM2CHAR(DATA_PORT_ID)).c_str()); + bsleepmode = atoi(web_interface->WebServer.arg(PROGMEM2CHAR(SLEEP_MODE_ID)).c_str()); + if (!(iweb_port>0 && iweb_port<65001) || + !(idata_port>0 && idata_port<65001)) + { + msg_alert_error=true; + smsg=PROGMEM2CHAR(ERROR_INCORRECT_PORT); + } + if (iweb_port== idata_port) + { + msg_alert_error=true; + smsg=PROGMEM2CHAR(ERROR_INCORRECT_PORT2); + } if (!(ibaud==9600 || ibaud==19200|| ibaud==38400|| ibaud==57600|| ibaud==115200|| ibaud==230400) || - !(bsleepmode==NONE_SLEEP_T ||bsleepmode==LIGHT_SLEEP_T ||bsleepmode==MODEM_SLEEP_T )) + !(bsleepmode==NONE_SLEEP_T ||bsleepmode==LIGHT_SLEEP_T ||bsleepmode==MODEM_SLEEP_T )) { msg_alert_error=true; smsg=PROGMEM2CHAR(ERROR_QUERY); @@ -492,7 +525,7 @@ void handle_web_interface_configSys() //if no error apply the changes if (msg_alert_error!=true) { - if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&ibaud,BAUD_LENGH)||!CONFIG::write_byte(EP_SLEEP_MODE,bsleepmode)) + if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&ibaud,INTEGER_LENGH)||!CONFIG::write_buffer(EP_WEB_PORT,(const byte *)&iweb_port,INTEGER_LENGH)||!CONFIG::write_buffer(EP_DATA_PORT,(const byte *)&idata_port,INTEGER_LENGH)||!CONFIG::write_byte(EP_SLEEP_MODE,bsleepmode)) { msg_alert_error=true; smsg=PROGMEM2CHAR(ERROR_WRITING_CHANGES); @@ -501,14 +534,27 @@ void handle_web_interface_configSys() if (!msg_alert_error) { msg_alert_success=true; + wifi_config.iweb_port=iweb_port; + wifi_config.idata_port=idata_port; smsg=PROGMEM2CHAR(SAVED_CHANGES); } } } - if (!CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&istatus , BAUD_LENGH))istatus=0; + else + { + if (!CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&ibaud , INTEGER_LENGH))ibaud=DEFAULT_BAUD_RATE; + if (!CONFIG::read_byte(EP_SLEEP_MODE, &bsleepmode ))bsleepmode=DEFAULT_SLEEP_MODE; + if (!CONFIG::read_buffer(EP_WEB_PORT, (byte *)&iweb_port , INTEGER_LENGH))ibaud=DEFAULT_WEB_PORT; + if (!CONFIG::read_buffer(EP_DATA_PORT, (byte *)&idata_port , INTEGER_LENGH))ibaud=DEFAULT_DATA_PORT; + } if (wifi_get_opmode()==WIFI_STA ) stmp=wifi_config.ip2str(WiFi.localIP()); else stmp=wifi_config.ip2str(WiFi.softAPIP()); + if (wifi_config.iweb_port!=80) + { + stmp+=":"; + stmp+=String(wifi_config.iweb_port); + } buffer2send+=(PROGMEM2CHAR(PAGE_HEAD_1)); buffer2send+=(PROGMEM2CHAR(PAGE_HEAD_2)); TOPBAR(stmp.c_str()) @@ -516,43 +562,61 @@ void handle_web_interface_configSys() buffer2send+=(PROGMEM2CHAR(TITLE_SYSTEM)); buffer2send+=(PROGMEM2CHAR(PANEL_START)); buffer2send+=(PROGMEM2CHAR(FORM_START)); - - SELECT_START(PROGMEM2CHAR(SYS_1_ID),PROGMEM2CHAR(BAUD_RATE_NAME),PROGMEM2CHAR(BAUD_RATE_ID)) - if (istatus==9600)stmp = PROGMEM2CHAR(VALUE_SELECTED); + //baud rate + SELECT_START(PROGMEM2CHAR(AP_1_ID),PROGMEM2CHAR(BAUD_RATE_NAME),PROGMEM2CHAR(BAUD_RATE_ID)) + if (ibaud==9600)stmp = PROGMEM2CHAR(VALUE_SELECTED); else stmp=""; OPTION(PROGMEM2CHAR(VALUE_9600), stmp.c_str(),PROGMEM2CHAR(VALUE_9600)) - if (istatus==19200)stmp = PROGMEM2CHAR(VALUE_SELECTED); + if (ibaud==19200)stmp = PROGMEM2CHAR(VALUE_SELECTED); else stmp=""; OPTION(PROGMEM2CHAR(VALUE_19200), stmp.c_str(),PROGMEM2CHAR(VALUE_19200)) - if (istatus==38400)stmp = PROGMEM2CHAR(VALUE_SELECTED); + if (ibaud==38400)stmp = PROGMEM2CHAR(VALUE_SELECTED); else stmp=""; OPTION(PROGMEM2CHAR(VALUE_38400), stmp.c_str(),PROGMEM2CHAR(VALUE_38400)) - if (istatus==57600)stmp = PROGMEM2CHAR(VALUE_SELECTED); + if (ibaud==57600)stmp = PROGMEM2CHAR(VALUE_SELECTED); else stmp=""; OPTION(PROGMEM2CHAR(VALUE_57600), stmp.c_str(),PROGMEM2CHAR(VALUE_57600)) - if (istatus==115200)stmp = PROGMEM2CHAR(VALUE_SELECTED); + if (ibaud==115200)stmp = PROGMEM2CHAR(VALUE_SELECTED); else stmp=""; OPTION(PROGMEM2CHAR(VALUE_115200), stmp.c_str(),PROGMEM2CHAR(VALUE_115200)) - if (istatus==230400)stmp = PROGMEM2CHAR(VALUE_SELECTED); + if (ibaud==230400)stmp = PROGMEM2CHAR(VALUE_SELECTED); else stmp=""; OPTION(PROGMEM2CHAR(VALUE_230400), stmp.c_str(),PROGMEM2CHAR(VALUE_230400)) SELECT_END // buffer2send+=(PROGMEM2CHAR(BR)); - if (!CONFIG::read_byte(EP_SLEEP_MODE, &bflag ))bflag=0; - SELECT_START(PROGMEM2CHAR(SYS_3_ID),PROGMEM2CHAR(SLEEP_MODE_NAME),PROGMEM2CHAR(SLEEP_MODE_ID)) - if (bflag==NONE_SLEEP_T)stmp = PROGMEM2CHAR(VALUE_SELECTED); + //sleep mode + SELECT_START(PROGMEM2CHAR(AP_2_ID),PROGMEM2CHAR(SLEEP_MODE_NAME),PROGMEM2CHAR(SLEEP_MODE_ID)) + if (bsleepmode==NONE_SLEEP_T)stmp = PROGMEM2CHAR(VALUE_SELECTED); else stmp=""; OPTION(String(NONE_SLEEP_T).c_str(), stmp.c_str(),PROGMEM2CHAR(VALUE_NONE)) - if (bflag==LIGHT_SLEEP_T)stmp = PROGMEM2CHAR(VALUE_SELECTED); + if (bsleepmode==LIGHT_SLEEP_T)stmp = PROGMEM2CHAR(VALUE_SELECTED); else stmp=""; OPTION(String(LIGHT_SLEEP_T).c_str(), stmp.c_str(),PROGMEM2CHAR(VALUE_LIGHT)) - if (bflag==MODEM_SLEEP_T)stmp = PROGMEM2CHAR(VALUE_SELECTED); + if (bsleepmode==MODEM_SLEEP_T)stmp = PROGMEM2CHAR(VALUE_SELECTED); else stmp=""; OPTION(String(MODEM_SLEEP_T).c_str(), stmp.c_str(),PROGMEM2CHAR(VALUE_MODEM)) SELECT_END + //web port + if(error_display[2]==0) + { + INPUT_TEXT( PROGMEM2CHAR(AP_3_ID),PROGMEM2CHAR(WEB_PORT_TITLE), PROGMEM2CHAR(WEB_PORT_ID),PROGMEM2CHAR(PORT_DESC),String(iweb_port).c_str()) + } + else + { + INPUT_TEXT_ERROR( PROGMEM2CHAR(AP_3_ID),PROGMEM2CHAR(WEB_PORT_TITLE), PROGMEM2CHAR(WEB_PORT_ID),PROGMEM2CHAR(PORT_DESC),String(iweb_port).c_str()) + } + //data port + if(error_display[3]==0) + { + INPUT_TEXT( PROGMEM2CHAR(AP_4_ID),PROGMEM2CHAR(DATA_PORT_TITLE), PROGMEM2CHAR(DATA_PORT_ID),PROGMEM2CHAR(PORT_DESC),String(idata_port).c_str()) + } + else + { + INPUT_TEXT_ERROR( PROGMEM2CHAR(AP_4_ID),PROGMEM2CHAR(DATA_PORT_TITLE), PROGMEM2CHAR(DATA_PORT_ID),PROGMEM2CHAR(PORT_DESC),String(idata_port).c_str()) + } if(msg_alert_error) { MSG_ERROR(smsg.c_str()) @@ -567,7 +631,7 @@ void handle_web_interface_configSys() buffer2send+=(PROGMEM2CHAR(FORM_END)); buffer2send+=(PROGMEM2CHAR(PANEL_END)); buffer2send+=(PROGMEM2CHAR(PAGE_BOTTOM)); - web_interface.WebServer.send(200, "text/html", buffer2send); + web_interface->WebServer.send(200, "text/html", buffer2send); if (msg_alert_success && !msg_alert_error) { system_restart(); @@ -599,46 +663,46 @@ void handle_web_interface_configAP() bool msg_alert_success=false; //check is it is a submission or a display smsg=""; - if (web_interface.WebServer.hasArg(PROGMEM2CHAR(SUBMIT_ID))) + if (web_interface->WebServer.hasArg(PROGMEM2CHAR(SUBMIT_ID))) { //is there a correct list of values? - if (web_interface.WebServer.hasArg(PROGMEM2CHAR(SSID_ID)) && web_interface.WebServer.hasArg(PROGMEM2CHAR(PASSWORD_ID))&& web_interface.WebServer.hasArg(PROGMEM2CHAR(NETWORK_ID))&& web_interface.WebServer.hasArg(PROGMEM2CHAR(AUTENTIFICATION_ID))&& web_interface.WebServer.hasArg(PROGMEM2CHAR(IP_NAME))&& web_interface.WebServer.hasArg(PROGMEM2CHAR(GATEWAY_ID))&& web_interface.WebServer.hasArg(PROGMEM2CHAR(SUBNET_ID))&& web_interface.WebServer.hasArg(PROGMEM2CHAR(CHANNEL_ID))) + if (web_interface->WebServer.hasArg(PROGMEM2CHAR(SSID_ID)) && web_interface->WebServer.hasArg(PROGMEM2CHAR(PASSWORD_ID))&& web_interface->WebServer.hasArg(PROGMEM2CHAR(NETWORK_ID))&& web_interface->WebServer.hasArg(PROGMEM2CHAR(AUTENTIFICATION_ID))&& web_interface->WebServer.hasArg(PROGMEM2CHAR(IP_NAME))&& web_interface->WebServer.hasArg(PROGMEM2CHAR(GATEWAY_ID))&& web_interface->WebServer.hasArg(PROGMEM2CHAR(SUBNET_ID))&& web_interface->WebServer.hasArg(PROGMEM2CHAR(CHANNEL_ID))) { //ssid - if (web_interface.WebServer.arg(PROGMEM2CHAR(SSID_ID)).length() > MAX_SSID_LENGH) + if (web_interface->WebServer.arg(PROGMEM2CHAR(SSID_ID)).length() > MAX_SSID_LENGH) { - stmp = web_interface.WebServer.arg(PROGMEM2CHAR(SSID_ID)).substring(0,MAX_SSID_LENGH); + stmp = web_interface->WebServer.arg(PROGMEM2CHAR(SSID_ID)).substring(0,MAX_SSID_LENGH); msg_alert_error=true; error_display[0]=1; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_SSID); - web_interface.urldecode(ssid_buf,stmp.c_str()); + web_interface->urldecode(ssid_buf,stmp.c_str()); } else - web_interface.urldecode(ssid_buf,web_interface.WebServer.arg(PROGMEM2CHAR(SSID_ID)).c_str()); - if (!web_interface.isSSIDValid(ssid_buf)) + web_interface->urldecode(ssid_buf,web_interface->WebServer.arg(PROGMEM2CHAR(SSID_ID)).c_str()); + if (!web_interface->isSSIDValid(ssid_buf)) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_SSID); error_display[0]=1; } - if (web_interface.WebServer.arg(PROGMEM2CHAR(PASSWORD_ID)).length() > MAX_PASSWORD_LENGH) + if (web_interface->WebServer.arg(PROGMEM2CHAR(PASSWORD_ID)).length() > MAX_PASSWORD_LENGH) { - stmp = web_interface.WebServer.arg(PROGMEM2CHAR(PASSWORD_ID)).substring(0,MAX_PASSWORD_LENGH); + stmp = web_interface->WebServer.arg(PROGMEM2CHAR(PASSWORD_ID)).substring(0,MAX_PASSWORD_LENGH); msg_alert_error=true; error_display[0]=2; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_PASSWORD); - web_interface.urldecode(password_buf,stmp.c_str()); + web_interface->urldecode(password_buf,stmp.c_str()); } else - web_interface.urldecode(password_buf,web_interface.WebServer.arg(PROGMEM2CHAR(PASSWORD_ID)).c_str()); + web_interface->urldecode(password_buf,web_interface->WebServer.arg(PROGMEM2CHAR(PASSWORD_ID)).c_str()); Serial.println(password_buf); - if (!web_interface.isPasswordValid(password_buf)) + if (!web_interface->isPasswordValid(password_buf)) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_PASSWORD); error_display[2]=1; } //ssid visible ? - if (web_interface.WebServer.hasArg(PROGMEM2CHAR(VISIBLE_NAME))) + if (web_interface->WebServer.hasArg(PROGMEM2CHAR(VISIBLE_NAME))) { visible_buf=1; } @@ -647,28 +711,28 @@ void handle_web_interface_configAP() visible_buf=0; } //phy mode - phy_mode_buf = atoi(web_interface.WebServer.arg(PROGMEM2CHAR(NETWORK_ID)).c_str()); + phy_mode_buf = atoi(web_interface->WebServer.arg(PROGMEM2CHAR(NETWORK_ID)).c_str()); if (!(phy_mode_buf==PHY_MODE_11B||phy_mode_buf==PHY_MODE_11G) ) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_QUERY); } //channel - channel_buf = atoi(web_interface.WebServer.arg(PROGMEM2CHAR(CHANNEL_ID)).c_str()); + channel_buf = atoi(web_interface->WebServer.arg(PROGMEM2CHAR(CHANNEL_ID)).c_str()); if (channel_buf< 1|| channel_buf>11) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_QUERY); } //authentification - auth_buf = atoi(web_interface.WebServer.arg(PROGMEM2CHAR(AUTENTIFICATION_ID)).c_str()); + auth_buf = atoi(web_interface->WebServer.arg(PROGMEM2CHAR(AUTENTIFICATION_ID)).c_str()); if (!(auth_buf==AUTH_OPEN||auth_buf==AUTH_WEP||auth_buf==AUTH_WPA_PSK||auth_buf==AUTH_WPA2_PSK||auth_buf==AUTH_WPA_WPA2_PSK||auth_buf==AUTH_MAX) ) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_QUERY); } //Static IP ? - if (web_interface.WebServer.hasArg(PROGMEM2CHAR(STATIC_IP_NAME))) + if (web_interface->WebServer.hasArg(PROGMEM2CHAR(STATIC_IP_NAME))) { static_ip_buf=STATIC_IP_MODE; } @@ -678,17 +742,17 @@ void handle_web_interface_configAP() } //IP - if (web_interface.WebServer.arg(PROGMEM2CHAR(IP_NAME)).length() > MAX_SSID_LENGH) + if (web_interface->WebServer.arg(PROGMEM2CHAR(IP_NAME)).length() > MAX_SSID_LENGH) { - stmp = web_interface.WebServer.arg(PROGMEM2CHAR(IP_NAME)).substring(0,MAX_SSID_LENGH); + stmp = web_interface->WebServer.arg(PROGMEM2CHAR(IP_NAME)).substring(0,MAX_SSID_LENGH); msg_alert_error=true; error_display[6]=1; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_IP_FORMAT); - web_interface.urldecode(ip_buf,stmp.c_str()); + web_interface->urldecode(ip_buf,stmp.c_str()); } else - web_interface.urldecode(ip_buf,web_interface.WebServer.arg(PROGMEM2CHAR(IP_NAME)).c_str()); - if (!web_interface.isIPValid(ip_buf)) + web_interface->urldecode(ip_buf,web_interface->WebServer.arg(PROGMEM2CHAR(IP_NAME)).c_str()); + if (!web_interface->isIPValid(ip_buf)) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_IP_FORMAT); @@ -696,34 +760,34 @@ void handle_web_interface_configAP() } //Gateway - if (web_interface.WebServer.arg(PROGMEM2CHAR(GATEWAY_ID)).length() > MAX_SSID_LENGH) + if (web_interface->WebServer.arg(PROGMEM2CHAR(GATEWAY_ID)).length() > MAX_SSID_LENGH) { - stmp = web_interface.WebServer.arg(PROGMEM2CHAR(GATEWAY_ID)).substring(0,MAX_SSID_LENGH); + stmp = web_interface->WebServer.arg(PROGMEM2CHAR(GATEWAY_ID)).substring(0,MAX_SSID_LENGH); msg_alert_error=true; error_display[7]=1; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_IP_FORMAT); - web_interface.urldecode(gw_buf,stmp.c_str()); + web_interface->urldecode(gw_buf,stmp.c_str()); } else - web_interface.urldecode(gw_buf,web_interface.WebServer.arg(PROGMEM2CHAR(GATEWAY_ID)).c_str()); - if (!web_interface.isIPValid(gw_buf)) + web_interface->urldecode(gw_buf,web_interface->WebServer.arg(PROGMEM2CHAR(GATEWAY_ID)).c_str()); + if (!web_interface->isIPValid(gw_buf)) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_IP_FORMAT); error_display[7]=1; } //subnet - if (web_interface.WebServer.arg(PROGMEM2CHAR(SUBNET_ID)).length() > MAX_SSID_LENGH) + if (web_interface->WebServer.arg(PROGMEM2CHAR(SUBNET_ID)).length() > MAX_SSID_LENGH) { - stmp = web_interface.WebServer.arg(PROGMEM2CHAR(SUBNET_ID)).substring(0,MAX_SSID_LENGH); + stmp = web_interface->WebServer.arg(PROGMEM2CHAR(SUBNET_ID)).substring(0,MAX_SSID_LENGH); msg_alert_error=true; error_display[8]=1; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_IP_FORMAT); - web_interface.urldecode(msk_buf,stmp.c_str()); + web_interface->urldecode(msk_buf,stmp.c_str()); } else - web_interface.urldecode(msk_buf,web_interface.WebServer.arg(PROGMEM2CHAR(SUBNET_ID)).c_str()); - if (!web_interface.isIPValid(msk_buf)) + web_interface->urldecode(msk_buf,web_interface->WebServer.arg(PROGMEM2CHAR(SUBNET_ID)).c_str()); + if (!web_interface->isIPValid(msk_buf)) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_IP_FORMAT); @@ -803,6 +867,11 @@ void handle_web_interface_configAP() //display page if (wifi_get_opmode()==WIFI_STA ) stmp=wifi_config.ip2str(WiFi.localIP()); else stmp=wifi_config.ip2str(WiFi.softAPIP()); + if (wifi_config.iweb_port!=80) + { + stmp+=":"; + stmp+=String(wifi_config.iweb_port); + } buffer2send+=(PROGMEM2CHAR(PAGE_HEAD_1)); buffer2send+=(PROGMEM2CHAR(PAGE_HEAD_2)); TOPBAR(stmp.c_str()) @@ -924,7 +993,7 @@ void handle_web_interface_configAP() buffer2send+=(PROGMEM2CHAR(FORM_END)); buffer2send+=(PROGMEM2CHAR(PANEL_END)); buffer2send+=(PROGMEM2CHAR(PAGE_BOTTOM)); - web_interface.WebServer.send(200, "text/html", buffer2send); + web_interface->WebServer.send(200, "text/html", buffer2send); if (msg_alert_success && !msg_alert_error) { system_restart(); @@ -958,53 +1027,53 @@ void handle_web_interface_configSTA() bool msg_alert_success=false; //check is it is a submission or a display smsg=""; - if (web_interface.WebServer.hasArg(PROGMEM2CHAR(SUBMIT_ID))) + if (web_interface->WebServer.hasArg(PROGMEM2CHAR(SUBMIT_ID))) { //is there a correct list of values? - if (web_interface.WebServer.hasArg(PROGMEM2CHAR(SSID_ID)) && web_interface.WebServer.hasArg(PROGMEM2CHAR(PASSWORD_ID))&& web_interface.WebServer.hasArg(PROGMEM2CHAR(NETWORK_ID))&& web_interface.WebServer.hasArg(PROGMEM2CHAR(IP_NAME))&& web_interface.WebServer.hasArg(PROGMEM2CHAR(GATEWAY_ID))&& web_interface.WebServer.hasArg(PROGMEM2CHAR(SUBNET_ID))) + if (web_interface->WebServer.hasArg(PROGMEM2CHAR(SSID_ID)) && web_interface->WebServer.hasArg(PROGMEM2CHAR(PASSWORD_ID))&& web_interface->WebServer.hasArg(PROGMEM2CHAR(NETWORK_ID))&& web_interface->WebServer.hasArg(PROGMEM2CHAR(IP_NAME))&& web_interface->WebServer.hasArg(PROGMEM2CHAR(GATEWAY_ID))&& web_interface->WebServer.hasArg(PROGMEM2CHAR(SUBNET_ID))) { //ssid - if (web_interface.WebServer.arg(PROGMEM2CHAR(SSID_ID)).length() > MAX_SSID_LENGH) + if (web_interface->WebServer.arg(PROGMEM2CHAR(SSID_ID)).length() > MAX_SSID_LENGH) { - stmp = web_interface.WebServer.arg(PROGMEM2CHAR(SSID_ID)).substring(0,MAX_SSID_LENGH); + stmp = web_interface->WebServer.arg(PROGMEM2CHAR(SSID_ID)).substring(0,MAX_SSID_LENGH); msg_alert_error=true; error_display[0]=1; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_SSID); - web_interface.urldecode(ssid_buf,stmp.c_str()); + web_interface->urldecode(ssid_buf,stmp.c_str()); } else - web_interface.urldecode(ssid_buf,web_interface.WebServer.arg(PROGMEM2CHAR(SSID_ID)).c_str()); - if (!web_interface.isSSIDValid(ssid_buf)) + web_interface->urldecode(ssid_buf,web_interface->WebServer.arg(PROGMEM2CHAR(SSID_ID)).c_str()); + if (!web_interface->isSSIDValid(ssid_buf)) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_SSID); error_display[0]=1; } - if (web_interface.WebServer.arg(PROGMEM2CHAR(PASSWORD_ID)).length() > MAX_PASSWORD_LENGH) + if (web_interface->WebServer.arg(PROGMEM2CHAR(PASSWORD_ID)).length() > MAX_PASSWORD_LENGH) { - stmp = web_interface.WebServer.arg(PROGMEM2CHAR(PASSWORD_ID)).substring(0,MAX_PASSWORD_LENGH); + stmp = web_interface->WebServer.arg(PROGMEM2CHAR(PASSWORD_ID)).substring(0,MAX_PASSWORD_LENGH); msg_alert_error=true; error_display[0]=2; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_PASSWORD); - web_interface.urldecode(password_buf,stmp.c_str()); + web_interface->urldecode(password_buf,stmp.c_str()); } else - web_interface.urldecode(password_buf,web_interface.WebServer.arg(PROGMEM2CHAR(PASSWORD_ID)).c_str()); + web_interface->urldecode(password_buf,web_interface->WebServer.arg(PROGMEM2CHAR(PASSWORD_ID)).c_str()); Serial.println(password_buf); - if (!web_interface.isPasswordValid(password_buf)) + if (!web_interface->isPasswordValid(password_buf)) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_PASSWORD); error_display[2]=1; } //phy mode - phy_mode_buf = atoi(web_interface.WebServer.arg(PROGMEM2CHAR(NETWORK_ID)).c_str()); + phy_mode_buf = atoi(web_interface->WebServer.arg(PROGMEM2CHAR(NETWORK_ID)).c_str()); if (!(phy_mode_buf==PHY_MODE_11B||phy_mode_buf==PHY_MODE_11G ||phy_mode_buf==PHY_MODE_11N)) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_QUERY); } //Static IP ? - if (web_interface.WebServer.hasArg(PROGMEM2CHAR(STATIC_IP_NAME))) + if (web_interface->WebServer.hasArg(PROGMEM2CHAR(STATIC_IP_NAME))) { static_ip_buf=STATIC_IP_MODE; } @@ -1014,17 +1083,17 @@ void handle_web_interface_configSTA() } //IP - if (web_interface.WebServer.arg(PROGMEM2CHAR(IP_NAME)).length() > MAX_SSID_LENGH) + if (web_interface->WebServer.arg(PROGMEM2CHAR(IP_NAME)).length() > MAX_SSID_LENGH) { - stmp = web_interface.WebServer.arg(PROGMEM2CHAR(IP_NAME)).substring(0,MAX_SSID_LENGH); + stmp = web_interface->WebServer.arg(PROGMEM2CHAR(IP_NAME)).substring(0,MAX_SSID_LENGH); msg_alert_error=true; error_display[6]=1; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_IP_FORMAT); - web_interface.urldecode(ip_buf,stmp.c_str()); + web_interface->urldecode(ip_buf,stmp.c_str()); } else - web_interface.urldecode(ip_buf,web_interface.WebServer.arg(PROGMEM2CHAR(IP_NAME)).c_str()); - if (!web_interface.isIPValid(ip_buf)) + web_interface->urldecode(ip_buf,web_interface->WebServer.arg(PROGMEM2CHAR(IP_NAME)).c_str()); + if (!web_interface->isIPValid(ip_buf)) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_IP_FORMAT); @@ -1032,34 +1101,34 @@ void handle_web_interface_configSTA() } //Gateway - if (web_interface.WebServer.arg(PROGMEM2CHAR(GATEWAY_ID)).length() > MAX_SSID_LENGH) + if (web_interface->WebServer.arg(PROGMEM2CHAR(GATEWAY_ID)).length() > MAX_SSID_LENGH) { - stmp = web_interface.WebServer.arg(PROGMEM2CHAR(GATEWAY_ID)).substring(0,MAX_SSID_LENGH); + stmp = web_interface->WebServer.arg(PROGMEM2CHAR(GATEWAY_ID)).substring(0,MAX_SSID_LENGH); msg_alert_error=true; error_display[7]=1; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_IP_FORMAT); - web_interface.urldecode(gw_buf,stmp.c_str()); + web_interface->urldecode(gw_buf,stmp.c_str()); } else - web_interface.urldecode(gw_buf,web_interface.WebServer.arg(PROGMEM2CHAR(GATEWAY_ID)).c_str()); - if (!web_interface.isIPValid(gw_buf)) + web_interface->urldecode(gw_buf,web_interface->WebServer.arg(PROGMEM2CHAR(GATEWAY_ID)).c_str()); + if (!web_interface->isIPValid(gw_buf)) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_IP_FORMAT); error_display[7]=1; } //subnet - if (web_interface.WebServer.arg(PROGMEM2CHAR(SUBNET_ID)).length() > MAX_SSID_LENGH) + if (web_interface->WebServer.arg(PROGMEM2CHAR(SUBNET_ID)).length() > MAX_SSID_LENGH) { - stmp = web_interface.WebServer.arg(PROGMEM2CHAR(SUBNET_ID)).substring(0,MAX_SSID_LENGH); + stmp = web_interface->WebServer.arg(PROGMEM2CHAR(SUBNET_ID)).substring(0,MAX_SSID_LENGH); msg_alert_error=true; error_display[8]=1; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_IP_FORMAT); - web_interface.urldecode(msk_buf,stmp.c_str()); + web_interface->urldecode(msk_buf,stmp.c_str()); } else - web_interface.urldecode(msk_buf,web_interface.WebServer.arg(PROGMEM2CHAR(SUBNET_ID)).c_str()); - if (!web_interface.isIPValid(msk_buf)) + web_interface->urldecode(msk_buf,web_interface->WebServer.arg(PROGMEM2CHAR(SUBNET_ID)).c_str()); + if (!web_interface->isIPValid(msk_buf)) { msg_alert_error=true; smsg+=PROGMEM2CHAR(ERROR_INCORRECT_IP_FORMAT); @@ -1131,6 +1200,11 @@ void handle_web_interface_configSTA() //display page if (wifi_get_opmode()==WIFI_STA ) stmp=wifi_config.ip2str(WiFi.localIP()); else stmp=wifi_config.ip2str(WiFi.softAPIP()); + if (wifi_config.iweb_port!=80) + { + stmp+=":"; + stmp+=String(wifi_config.iweb_port); + } buffer2send+=(PROGMEM2CHAR(PAGE_HEAD_1)); buffer2send+=(PROGMEM2CHAR(PAGE_HEAD_2)); TOPBAR(stmp.c_str()) @@ -1258,7 +1332,7 @@ void handle_web_interface_configSTA() buffer2send+=(PROGMEM2CHAR(FORM_END)); buffer2send+=(PROGMEM2CHAR(PANEL_END)); buffer2send+=(PROGMEM2CHAR(PAGE_BOTTOM)); - web_interface.WebServer.send(200, "text/html", buffer2send); + web_interface->WebServer.send(200, "text/html", buffer2send); if (msg_alert_success && !msg_alert_error) { system_restart(); @@ -1272,10 +1346,15 @@ void handle_not_found() String buffer2send =""; if (wifi_get_opmode()==WIFI_STA ) IP=wifi_config.ip2str(WiFi.localIP()); else IP=wifi_config.ip2str(WiFi.softAPIP()); - buffer2send+=(PROGMEM2CHAR(T404_PAGE)); - buffer2send+=(IP.c_str()); - buffer2send+=(PROGMEM2CHAR(T404_PAGE_2)); - web_interface.WebServer.send(200, "text/html", buffer2send); + if (wifi_config.iweb_port!=80) + { + IP+=":"; + IP+=String(wifi_config.iweb_port); + } + buffer2send+=(PROGMEM2CHAR(T404_PAGE)); + buffer2send+=(IP.c_str()); + buffer2send+=(PROGMEM2CHAR(T404_PAGE_2)); + web_interface->WebServer.send(200, "text/html", buffer2send); } //URI Decoding function @@ -1325,5 +1404,5 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port) WebServer.onNotFound( handle_not_found); } -WEBINTERFACE_CLASS web_interface(80); +WEBINTERFACE_CLASS * web_interface; diff --git a/esp8266/webinterface.h b/esp8266/webinterface.h index 80f10c0b..192dae57 100644 --- a/esp8266/webinterface.h +++ b/esp8266/webinterface.h @@ -28,7 +28,7 @@ class WEBINTERFACE_CLASS { public: - WEBINTERFACE_CLASS (int port = 82); + WEBINTERFACE_CLASS (int port = 80); ESP8266WebServer WebServer; void urldecode(char *dst, const char *src); bool isSSIDValid(const char * ssid); @@ -38,6 +38,6 @@ class WEBINTERFACE_CLASS }; -extern WEBINTERFACE_CLASS web_interface; +extern WEBINTERFACE_CLASS * web_interface; #endif diff --git a/esp8266/wifi.cpp b/esp8266/wifi.cpp index 3bb28bdc..d26898a0 100644 --- a/esp8266/wifi.cpp +++ b/esp8266/wifi.cpp @@ -83,6 +83,7 @@ bool WIFI_CONFIG::Setup() if (!CONFIG::read_byte(EP_WIFI_MODE, &bflag ) || !CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGH) ||!CONFIG::read_string(EP_PASSWORD, pwd , MAX_PASSWORD_LENGH)) return false; //disconnect if connected WiFi.disconnect(); + current_mode=bflag; //this is AP mode if (bflag==AP_MODE) { @@ -160,5 +161,10 @@ bool WIFI_CONFIG::Setup() #endif return true; } - +#ifdef MDNS_FEATURE +void WIFI_CONFIG::Updatemdns() +{ + if(current_mode==CLIENT_MODE)mdns.update(); +} +#endif WIFI_CONFIG wifi_config; diff --git a/esp8266/wifi.h b/esp8266/wifi.h index f34b23be..67d46e7e 100644 --- a/esp8266/wifi.h +++ b/esp8266/wifi.h @@ -35,7 +35,11 @@ class WIFI_CONFIG // multicast DNS responder feature #ifdef MDNS_FEATURE MDNSResponder mdns; + void Updatemdns(); #endif + byte current_mode; + int iweb_port; + int idata_port; bool Setup(); char * mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH]); char * ip2str(IPAddress Ip );