diff --git a/esp-link/cgitelnet.c b/esp-link/cgitelnet.c index 1ffe3f9..c3a8c00 100644 --- a/esp-link/cgitelnet.c +++ b/esp-link/cgitelnet.c @@ -28,12 +28,16 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) { return HTTPD_CGI_DONE; // Connection aborted } - char *coll; int8_t ok = 0; uint16_t port1, port2; ok |= getUInt16Arg(connData, "port1", &port1); ok |= getUInt16Arg(connData, "port2", &port2); - if (ok < 0) { coll = "Failed to fetch ports. Are they valid?"; goto collision; } + if (ok <= 0) { //If we get at least one good value, this should be >= 1 + os_printf("Unable to fetch telnet ports.\n Received: port1=%d port2=%d\n", + flashConfig.telnet_port1, flashConfig.telnet_port2); + errorResponse(connData, 400, buff); + return HTTPD_CGI_DONE; + } if (ok > 0) { // fill both port variables from flash or ajax provided value @@ -41,13 +45,18 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) { if (!port2) port2 = flashConfig.telnet_port2; // check whether ports are different - if (port1 == port2) { coll = "Ports cannot be the same!"; goto collision; } + if (port1 == port2) { + os_printf("Ports cannot be the same.\n Tried to set: port1=%d port2=%d\n", + flashConfig.telnet_port1, flashConfig.telnet_port2); + errorResponse(connData, 400, buff); + return HTTPD_CGI_DONE; + } // we're good, set flashconfig flashConfig.telnet_port1 = port1; flashConfig.telnet_port2 = port2; os_printf("Telnet ports changed: port1=%d port2=%d\n", - flashConfig.telnet_port1, flashConfig.telnet_port2); + flashConfig.telnet_port1, flashConfig.telnet_port2); // save to flash if (configSave()) { @@ -60,16 +69,13 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) { } // apply the changes - serbridgeInit(flashConfig.telnet_port1, flashConfig.telnet_port2); + serbridgeInit(); + serbridgeStart(1, flashConfig.telnet_port1, flashDefault.telnet_port1mode); + serbridgeStart(2, flashConfig.telnet_port2, flashDefault.telnet_port2mode); + } return HTTPD_CGI_DONE; - collision: { - char buff[128]; - os_sprintf(buff, "Ports assignment for %s collides with another assignment", coll); - errorResponse(connData, 400, buff); - return HTTPD_CGI_DONE; - } } int ICACHE_FLASH_ATTR cgiTelnet(HttpdConnData *connData) { diff --git a/esp-link/config.c b/esp-link/config.c index 8afedbc..bb31af5 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -37,6 +37,8 @@ FlashConfig flashDefault = { .stop_bits = ONE_STOP_BIT, .telnet_port1 = 23, .telnet_port2 = 2323, + .telnet_port1Mode = 0, + .telnet_port2Mode = 0, }; typedef union { @@ -163,6 +165,9 @@ bool ICACHE_FLASH_ATTR configRestore(void) { flashConfig.parity = flashDefault.parity; flashConfig.stop_bits = flashDefault.stop_bits; } + + if (flashConfig.telnet_port1 == 0) { flashConfig.telnet_port1 = flashDefault.telnet_port1; } + if (flashConfig.telnet_port2 == 0) { flashConfig.telnet_port2 = flashDefault.telnet_port2; } return true; } diff --git a/esp-link/config.h b/esp-link/config.h index 2f5aede..c1c1f68 100644 --- a/esp-link/config.h +++ b/esp-link/config.h @@ -41,8 +41,10 @@ typedef struct { int8_t data_bits; int8_t parity; int8_t stop_bits; - uint16_t telnet_port1, // Telnet port settings + uint16_t telnet_port1, // Telnet port settings telnet_port2; + int8_t telnet_port1mode, + telnet_port2mode; } FlashConfig; extern FlashConfig flashConfig; diff --git a/esp-link/main.c b/esp-link/main.c index d70e86a..54fa075 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -181,7 +181,10 @@ user_init(void) { WEB_Init(); // init the wifi-serial transparent bridge (port 23) - serbridgeInit(flashConfig.telnet_port1, flashConfig.telnet_port1); + serbridgeInit(); + serbridgeStart(1, flashConfig.telnet_port1, flashDefault.telnet_port1mode); + serbridgeStart(2, flashConfig.telnet_port2, flashDefault.telnet_port2mode); + uart_add_recv_cb(&serbridgeUartCb); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); diff --git a/html/home.html b/html/home.html index d2c9791..a3d2b87 100644 --- a/html/home.html +++ b/html/home.html @@ -50,7 +50,7 @@ the online README for up-to-date help.
-There are two ports available for telnet to use by default: 23 & 2323
Note - this time, only port1 may be changed & used sucessfully.