diff --git a/esp8266/config.cpp b/esp8266/config.cpp
index 2a47cdb5..f09639a9 100644
--- a/esp8266/config.cpp
+++ b/esp8266/config.cpp
@@ -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));
diff --git a/esp8266/config.h b/esp8266/config.h
index 600be435..55869add 100644
--- a/esp8266/config.h
+++ b/esp8266/config.h
@@ -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
diff --git a/esp8266/data/system.tpl b/esp8266/data/system.tpl
index 2e1c983a..afb89891 100644
--- a/esp8266/data/system.tpl
+++ b/esp8266/data/system.tpl
@@ -26,7 +26,7 @@ $SLEEP_MODE_OPTIONS_LIST$
-
+
$ERROR_MSG$
diff --git a/esp8266/esp8266.ino b/esp8266/esp8266.ino
index 5ef9a906..85d7b203 100644
--- a/esp8266/esp8266.ino
+++ b/esp8266/esp8266.ino
@@ -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();
diff --git a/esp8266/webinterface.cpp b/esp8266/webinterface.cpp
index 8e1f87c1..3835ef80 100644
--- a/esp8266/webinterface.cpp
+++ b/esp8266/webinterface.cpp
@@ -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 ");
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 ");
@@ -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="";
diff --git a/esp8266/wifi.cpp b/esp8266/wifi.cpp
index 410f8d28..f6c09524 100644
--- a/esp8266/wifi.cpp
+++ b/esp8266/wifi.cpp
@@ -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) {
diff --git a/keywords.txt b/keywords.txt
index ba924c1a..277f171d 100644
--- a/keywords.txt
+++ b/keywords.txt
@@ -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