mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-06-30 04:05:25 +08:00
Allow to disable TCP data feature
minor fixes: -Correct logic for web ports due to refactoring -Duplicate data read from serial if multiple clients -Improve reliability to reconnect to AP after a restart -Typo issues
This commit is contained in:
parent
535f26cdf5
commit
e4af1950eb
@ -375,14 +375,16 @@ void CONFIG::print_config()
|
||||
} else {
|
||||
Serial.println(F("Error reading web port"));
|
||||
}
|
||||
|
||||
Serial.print(F("Data port: "));
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
if (CONFIG::read_buffer(EP_DATA_PORT, (byte *)&ibuf , INTEGER_LENGTH)) {
|
||||
Serial.print(F("Data port: "));
|
||||
Serial.println(ibuf);
|
||||
} else {
|
||||
Serial.println(F("Error reading data port"));
|
||||
}
|
||||
|
||||
#else
|
||||
Serial.println(F("Disabled"));
|
||||
#endif
|
||||
if (CONFIG::read_byte(EP_REFRESH_PAGE_TIME, &bbuf )) {
|
||||
Serial.print(F("Web page refresh time: "));
|
||||
Serial.println(byte(bbuf));
|
||||
|
@ -38,6 +38,9 @@
|
||||
//SERIAL_COMMAND_FEATURE: allow to send command by serial
|
||||
#define SERIAL_COMMAND_FEATURE
|
||||
|
||||
//TCP_IP_DATA_FEATURE: allow to connect serial from TCP/IP
|
||||
#define TCP_IP_DATA_FEATURE
|
||||
|
||||
#ifndef CONFIG_h
|
||||
#define CONFIG_h
|
||||
|
||||
|
@ -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$"><label class="control-label" for="CONFIG4">Data port:</label><br>
|
||||
<div 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$
|
||||
|
@ -60,7 +60,7 @@ void setup()
|
||||
// init:
|
||||
web_interface = NULL;
|
||||
data_server = NULL;
|
||||
// ESP.wdtDisable();
|
||||
WiFi.disconnect();
|
||||
system_update_cpu_freq(SYS_CPU_160MHZ);
|
||||
delay(8000);
|
||||
bool breset_config=false;
|
||||
@ -117,17 +117,20 @@ void setup()
|
||||
wifi_config.Safe_Setup();
|
||||
}
|
||||
delay(1000);
|
||||
//start interfaces
|
||||
//start web interface
|
||||
web_interface = new WEBINTERFACE_CLASS(wifi_config.iweb_port);
|
||||
data_server = new WiFiServer (wifi_config.idata_port);
|
||||
//here the list of headers to be recorded
|
||||
const char * headerkeys[] = {"Cookie"} ;
|
||||
size_t headerkeyssize = sizeof(headerkeys)/sizeof(char*);
|
||||
//ask server to track these headers
|
||||
web_interface->WebServer.collectHeaders(headerkeys, headerkeyssize );
|
||||
web_interface->WebServer.begin();
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
//start TCP/IP interface
|
||||
data_server = new WiFiServer (wifi_config.idata_port);
|
||||
data_server->begin();
|
||||
data_server->setNoDelay(true);
|
||||
#endif
|
||||
|
||||
#ifdef MDNS_FEATURE
|
||||
// Check for any mDNS queries and send responses
|
||||
@ -177,6 +180,7 @@ void loop()
|
||||
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
|
||||
//check if there are any new clients
|
||||
if (data_server->hasClient()) {
|
||||
for(i = 0; i < MAX_SRV_CLIENTS; i++) {
|
||||
@ -206,19 +210,23 @@ void loop()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//check UART for data
|
||||
if(Serial.available()) {
|
||||
size_t len = Serial.available();
|
||||
uint8_t sbuf[len];
|
||||
Serial.readBytes(sbuf, len);
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
//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);
|
||||
delay(1);
|
||||
}
|
||||
COMMAND::read_buffer_serial(sbuf, len);
|
||||
}
|
||||
#endif
|
||||
//process data if any
|
||||
COMMAND::read_buffer_serial(sbuf, len);
|
||||
}
|
||||
if (web_interface->restartmodule) {
|
||||
Serial.flush();
|
||||
|
@ -206,6 +206,7 @@ const char MISSING_DATA [] PROGMEM = "Error: Missing data";
|
||||
const char EEPROM_NOWRITE [] PROGMEM = "Error: Cannot write to EEPROM";
|
||||
const char KEY_WEB_UPDATE [] PROGMEM = "$WEB_UPDATE_VISIBILITY$";
|
||||
const char KEY_STA_SIGNAL [] PROGMEM = "$STA_SIGNAL$";
|
||||
const char KEY_DATA_PORT_VISIBILITY [] PROGMEM = "$DATA_PORT_VISIBILITY$";
|
||||
|
||||
bool WEBINTERFACE_CLASS::isHostnameValid(const char * hostname)
|
||||
{
|
||||
@ -594,7 +595,14 @@ void GetPorts(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList)
|
||||
ValuesList.add(intTostr(wifi_config.iweb_port));
|
||||
//Data port
|
||||
KeysList.add(FPSTR(KEY_DATA_PORT));
|
||||
KeysList.add(FPSTR(KEY_DATA_PORT_VISIBILITY));
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
ValuesList.add(intTostr(wifi_config.idata_port));
|
||||
ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE));
|
||||
#else
|
||||
ValuesList.add(FPSTR(VALUE_NONE));
|
||||
ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN));
|
||||
#endif
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
// Helper for Page properties
|
||||
@ -1060,11 +1068,18 @@ void handle_web_interface_configSys()
|
||||
//check is it is a submission or a display
|
||||
if (web_interface->WebServer.hasArg("SUBMIT")) {
|
||||
//is there a correct list of values?
|
||||
if (web_interface->WebServer.hasArg("BAUD_RATE") && web_interface->WebServer.hasArg("SLEEP_MODE")&& web_interface->WebServer.hasArg("DATAPORT")&& web_interface->WebServer.hasArg("WEBPORT")) {
|
||||
if (web_interface->WebServer.hasArg("BAUD_RATE")
|
||||
&& web_interface->WebServer.hasArg("SLEEP_MODE")
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
&& web_interface->WebServer.hasArg("DATAPORT")
|
||||
#endif
|
||||
&& web_interface->WebServer.hasArg("WEBPORT")) {
|
||||
//is each value correct ?
|
||||
ibaud = web_interface->WebServer.arg("BAUD_RATE").toInt();
|
||||
iweb_port = web_interface->WebServer.arg("WEBPORT").toInt();
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
idata_port = web_interface->WebServer.arg("DATAPORT").toInt();
|
||||
#endif
|
||||
bsleepmode = web_interface->WebServer.arg("SLEEP_MODE").toInt();
|
||||
|
||||
if (!(iweb_port>0 && iweb_port<65001)) {
|
||||
@ -1073,12 +1088,14 @@ void handle_web_interface_configSys()
|
||||
KeysList.add(FPSTR(KEY_WEB_PORT_STATUS));
|
||||
ValuesList.add(FPSTR(VALUE_HAS_ERROR));
|
||||
}
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
if (!(idata_port>0 && idata_port<65001)) {
|
||||
msg_alert_error=true;
|
||||
smsg.concat("Error: invalid port value for data port<BR>");
|
||||
KeysList.add(FPSTR(KEY_DATA_PORT_STATUS));
|
||||
ValuesList.add(FPSTR(VALUE_HAS_ERROR));
|
||||
}
|
||||
#endif
|
||||
if (iweb_port== idata_port) {
|
||||
msg_alert_error=true;
|
||||
smsg.concat("Error: web port and data port cannot be identical<BR>");
|
||||
@ -1105,12 +1122,19 @@ 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,INTEGER_LENGTH)||!CONFIG::write_buffer(EP_WEB_PORT,(const byte *)&iweb_port,INTEGER_LENGTH)||!CONFIG::write_buffer(EP_DATA_PORT,(const byte *)&idata_port,INTEGER_LENGTH)||!CONFIG::write_byte(EP_SLEEP_MODE,bsleepmode)) {
|
||||
if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&ibaud,INTEGER_LENGTH)
|
||||
||!CONFIG::write_buffer(EP_WEB_PORT,(const byte *)&iweb_port,INTEGER_LENGTH)
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
||!CONFIG::write_buffer(EP_DATA_PORT,(const byte *)&idata_port,INTEGER_LENGTH)
|
||||
#endif
|
||||
||!CONFIG::write_byte(EP_SLEEP_MODE,bsleepmode)) {
|
||||
msg_alert_error=true;
|
||||
smsg = FPSTR(EEPROM_NOWRITE);
|
||||
} else {
|
||||
msg_alert_success=true;
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
wifi_config.iweb_port=iweb_port;
|
||||
#endif
|
||||
wifi_config.idata_port=idata_port;
|
||||
smsg = F("Changes saved to EEPROM, restarting....");
|
||||
}
|
||||
@ -1125,10 +1149,12 @@ void handle_web_interface_configSys()
|
||||
if (!CONFIG::read_buffer(EP_WEB_PORT, (byte *)&iweb_port , INTEGER_LENGTH)) {
|
||||
iweb_port=DEFAULT_WEB_PORT;
|
||||
}
|
||||
wifi_config.iweb_port=iweb_port;
|
||||
if (!CONFIG::read_buffer(EP_DATA_PORT, (byte *)&idata_port , INTEGER_LENGTH)) {
|
||||
idata_port=DEFAULT_DATA_PORT;
|
||||
}
|
||||
}
|
||||
wifi_config.idata_port=idata_port;
|
||||
};
|
||||
//Baud rate list
|
||||
istatus = 0;
|
||||
stmp="";
|
||||
|
@ -215,6 +215,7 @@ bool WIFI_CONFIG::Setup()
|
||||
return false;
|
||||
}
|
||||
wifi_set_phy_mode((phy_mode)bflag);
|
||||
delay(500);
|
||||
byte i=0;
|
||||
//try to connect
|
||||
while (WiFi.status() != WL_CONNECTED && i<40) {
|
||||
|
@ -17,11 +17,11 @@ $CHIP_ID$ : Chip ID
|
||||
$CPU_FREQ$ : CPU Frequency
|
||||
$FREE_MEM$ : Free memory on heap
|
||||
$SDK_VER$ : SDK version
|
||||
$MDNS_VISIBLE$: set to hidden is no MDNS and visible if present
|
||||
$MDNS_VISIBLE$: set to hidden if no MDNS and visible if present
|
||||
$MDNS_NAME$ : mDNS name if enabled or "Not enabled" if not enabled
|
||||
$SSDP_VISIBLE$ : set to hidden is no MDNS and visible if present
|
||||
$SSDP_VISIBLE$ : set to hidden if no MDNS and visible if present
|
||||
$SSDP_STATUS$ : set to Enabled / Not enabled according compilation settings
|
||||
$CAPTIVE_PORTAL_VISIBLE$: set to hidden is no Captive portal and visible if present
|
||||
$CAPTIVE_PORTAL_VISIBLE$: set to hidden if no Captive portal and visible if present
|
||||
$CAPTIVE_PORTAL_STATUS$: set to Enabled / Not enabled according compilation settings
|
||||
$NET_PHY$ : Network type (b/g/n)
|
||||
$SLEEP_MODE$ : Sleep Mode
|
||||
@ -29,6 +29,7 @@ $BOOT_VER$ : Boot version
|
||||
$BAUD_RATE$ : Baud rates for serial communication
|
||||
$WEB_PORT$ : Port for web access
|
||||
$DATA_PORT$ : Port for tcp ip connection
|
||||
$DATA_PORT_VISIBILITY$ : set to hidden if no enabled and visible if enabled
|
||||
|
||||
$AP_STATUS_ENABLED$ : is Access Point enabled or disabled
|
||||
$AP_VISIBILITY$ : if Access Point is enabled set visible, else set to hidden
|
||||
@ -72,6 +73,7 @@ $SLEEP_MODE_OPTIONS_LIST$ : Sleep mode list
|
||||
$POLLING_OPTIONS_LIST$ : Refresh delay list
|
||||
$WEB_PORT$ : Port for web access
|
||||
$DATA_PORT$ : Port for tcp ip connection
|
||||
$DATA_PORT_VISIBILITY$ : set to hidden if no enabled and visible if enabled
|
||||
$ERROR_MSG$ : Error message if any
|
||||
$SUCCESS_MSG$ : Success message announcing restart
|
||||
$ERROR_MSG_VISIBILITY$ : Show/Hide Error message
|
||||
|
Loading…
x
Reference in New Issue
Block a user