Telnet Serial-Bridge
There are two ports available for telnet to use by default: 23 & 2323
Note - this time, only port1 may be changed & used sucessfully.
diff --git a/serial/serbridge.c b/serial/serbridge.c
index cebc5615..e82e3b4b 100644
--- a/serial/serbridge.c
+++ b/serial/serbridge.c
@@ -16,8 +16,9 @@
#define syslog(X1...)
#endif
-static struct espconn serbridgeConn1; // plain bridging port
-static struct espconn serbridgeConn2; // programming port
+static struct espconn serbridgeConn[1]; // plain bridging port
+static struct espconn serbridgeConn[2]; // programming port
+static esp_tcp serbridgeTcp[1], serbridgeTcp[2];
static esp_tcp serbridgeTcp1, serbridgeTcp2;
static int8_t mcu_reset_pin, mcu_isp_pin;
@@ -421,7 +422,7 @@ serbridgeConnectCb(void *arg)
connData[i].readytosend = true;
connData[i].conn_mode = cmInit;
// if it's the second port we start out in programming mode
- if (conn->proto.tcp->local_port == serbridgeConn2.proto.tcp->local_port)
+ if (conn->proto.tcp->local_port == serbridgeConn[2].proto.tcp->local_port)
connData[i].conn_mode = cmPGMInit;
espconn_regist_recvcb(conn, serbridgeRecvCb);
@@ -470,35 +471,44 @@ serbridgeInitPins()
// Start transparent serial bridge TCP server on specified port (typ. 23)
void ICACHE_FLASH_ATTR
-serbridgeInit(int port1, int port2)
+serbridgeInit()
{
serbridgeInitPins();
os_memset(connData, 0, sizeof(connData));
- os_memset(&serbridgeTcp1, 0, sizeof(serbridgeTcp1));
- os_memset(&serbridgeTcp2, 0, sizeof(serbridgeTcp2));
-
- // set-up the primary port for plain bridging
- serbridgeConn1.type = ESPCONN_TCP;
- serbridgeConn1.state = ESPCONN_NONE;
- serbridgeTcp1.local_port = port1;
- serbridgeConn1.proto.tcp = &serbridgeTcp1;
-
- espconn_regist_connectcb(&serbridgeConn1, serbridgeConnectCb);
- espconn_accept(&serbridgeConn1);
- espconn_tcp_set_max_con_allow(&serbridgeConn1, MAX_CONN);
- espconn_regist_time(&serbridgeConn1, SER_BRIDGE_TIMEOUT, 0);
-
- // set-up the secondary port for programming
- serbridgeConn2.type = ESPCONN_TCP;
- serbridgeConn2.state = ESPCONN_NONE;
- serbridgeTcp2.local_port = port2;
- serbridgeConn2.proto.tcp = &serbridgeTcp2;
-
- espconn_regist_connectcb(&serbridgeConn2, serbridgeConnectCb);
- espconn_accept(&serbridgeConn2);
- espconn_tcp_set_max_con_allow(&serbridgeConn2, MAX_CONN);
- espconn_regist_time(&serbridgeConn2, SER_BRIDGE_TIMEOUT, 0);
+ os_memset(&serbridgeTcp[1], 0, sizeof(serbridgeTcp[1]));
+ os_memset(&serbridgeTcp[2], 0, sizeof(serbridgeTcp[2]));
+}
+
+// Start transparent serial bridge TCP server on specified port (typ. 23)
+void ICACHE_FLASH_ATTR
+serbridgeStart(int ix, int port, int mode)
+{
+
+ if (ix < 0 || ix > 2) // FIXME hardcoded limit
+ return;
+ if (serbridgeConn[ix] != NULL) { serbridgeCleanup(serbridgeConn[ix]); } //If we are already initialized, let's clean it up.
+ if (0 < port && port < 65536 && port != 80) {
+ serbridgeConn[ix].type = ESPCONN_TCP;
+ serbridgeConn[ix].state = ESPCONN_NONE;
+ serbridgeTcp[ix].local_port = port;
+ serbridgeConn[ix].proto.tcp = &serbridgeTcp[ix];
+
+ espconn_regist_connectcb(&serbridgeConn[ix], serbridgeConnectCb);
+ espconn_accept(&serbridgeConn[ix]);
+ espconn_tcp_set_max_con_allow(&serbridgeConn[ix], MAX_CONN);
+ espconn_regist_time(&serbridgeConn[ix], SER_BRIDGE_TIMEOUT, 0);
+ }
+}
+
+static void ICACHE_FLASH_ATTR
+serbridgeCleanup(void *arg)
+{
+ serbridgeConnData *conn = ((struct espconn*)arg)->reverse;
+ if (conn == NULL) return;
+ // Free memory & set to NULL
+ os_free(conn);
+ conn = NULL;
}
int ICACHE_FLASH_ATTR serbridgeInMCUFlashing()
diff --git a/serial/serbridge.h b/serial/serbridge.h
index ed661e1c..a1122ef7 100644
--- a/serial/serbridge.h
+++ b/serial/serbridge.h
@@ -31,11 +31,11 @@ typedef struct serbridgeConnData {
} serbridgeConnData;
// port1 is transparent&programming, second port is programming only
-void ICACHE_FLASH_ATTR serbridgeInit(int port1, int port2);
+void ICACHE_FLASH_ATTR serbridgeInit();
+void ICACHE_FLASH_ATTR serbridgeStart(int ix, int port, int mode);
void ICACHE_FLASH_ATTR serbridgeInitPins(void);
void ICACHE_FLASH_ATTR serbridgeUartCb(char *buf, short len);
void ICACHE_FLASH_ATTR serbridgeReset();
-
int ICACHE_FLASH_ATTR serbridgeInMCUFlashing();
// callback when receiving UART chars when in programming mode
From 3f161215dd12276db6344758320d466050725bcb Mon Sep 17 00:00:00 2001
From: Alex
Date: Sun, 30 Oct 2016 23:03:43 -0500
Subject: [PATCH 41/64] Fix a few errors..
---
serial/serbridge.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/serial/serbridge.c b/serial/serbridge.c
index e82e3b4b..875481c6 100644
--- a/serial/serbridge.c
+++ b/serial/serbridge.c
@@ -19,7 +19,6 @@
static struct espconn serbridgeConn[1]; // plain bridging port
static struct espconn serbridgeConn[2]; // programming port
static esp_tcp serbridgeTcp[1], serbridgeTcp[2];
-static esp_tcp serbridgeTcp1, serbridgeTcp2;
static int8_t mcu_reset_pin, mcu_isp_pin;
uint8_t in_mcu_flashing; // for disabling slip during MCU flashing
@@ -487,7 +486,7 @@ serbridgeStart(int ix, int port, int mode)
if (ix < 0 || ix > 2) // FIXME hardcoded limit
return;
- if (serbridgeConn[ix] != NULL) { serbridgeCleanup(serbridgeConn[ix]); } //If we are already initialized, let's clean it up.
+ if (serbridgeConn[ix] != NULL) { serbridgeCleanup(ix); } //If we are already initialized, let's clean it up.
if (0 < port && port < 65536 && port != 80) {
serbridgeConn[ix].type = ESPCONN_TCP;
serbridgeConn[ix].state = ESPCONN_NONE;
@@ -502,13 +501,12 @@ serbridgeStart(int ix, int port, int mode)
}
static void ICACHE_FLASH_ATTR
-serbridgeCleanup(void *arg)
+serbridgeCleanup(int ix)
{
- serbridgeConnData *conn = ((struct espconn*)arg)->reverse;
- if (conn == NULL) return;
+ if (serbridgeConn[ix] == NULL) return;
// Free memory & set to NULL
- os_free(conn);
- conn = NULL;
+ os_free(serbridgeConn[ix]);
+ serbridgeConn[ix] = NULL;
}
int ICACHE_FLASH_ATTR serbridgeInMCUFlashing()
From 2458e116b0bbc23ccc8e50f234d37d7086ed8369 Mon Sep 17 00:00:00 2001
From: Alex
Date: Sun, 30 Oct 2016 23:11:04 -0500
Subject: [PATCH 42/64] Serialbridge.c update
---
serial/serbridge.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/serial/serbridge.c b/serial/serbridge.c
index 875481c6..2d63128b 100644
--- a/serial/serbridge.c
+++ b/serial/serbridge.c
@@ -500,7 +500,7 @@ serbridgeStart(int ix, int port, int mode)
}
}
-static void ICACHE_FLASH_ATTR
+void ICACHE_FLASH_ATTR
serbridgeCleanup(int ix)
{
if (serbridgeConn[ix] == NULL) return;
From 27e6b5d4306f216dbc4de1425d48cc26055a0c83 Mon Sep 17 00:00:00 2001
From: dannybackx
Date: Tue, 1 Nov 2016 09:43:24 +0100
Subject: [PATCH 43/64] Fix compile errors
---
serial/serbridge.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/serial/serbridge.c b/serial/serbridge.c
index 2d63128b..74b88464 100644
--- a/serial/serbridge.c
+++ b/serial/serbridge.c
@@ -16,14 +16,14 @@
#define syslog(X1...)
#endif
-static struct espconn serbridgeConn[1]; // plain bridging port
-static struct espconn serbridgeConn[2]; // programming port
-static esp_tcp serbridgeTcp[1], serbridgeTcp[2];
+static struct espconn serbridgeConn[2]; // 0 = plain bridging port, 1 = programming port
+static esp_tcp serbridgeTcp[2];
static int8_t mcu_reset_pin, mcu_isp_pin;
uint8_t in_mcu_flashing; // for disabling slip during MCU flashing
void (*programmingCB)(char *buffer, short length) = NULL;
+void ICACHE_FLASH_ATTR serbridgeCleanup(int ix);
// Connection pool
serbridgeConnData connData[MAX_CONN];
@@ -421,7 +421,7 @@ serbridgeConnectCb(void *arg)
connData[i].readytosend = true;
connData[i].conn_mode = cmInit;
// if it's the second port we start out in programming mode
- if (conn->proto.tcp->local_port == serbridgeConn[2].proto.tcp->local_port)
+ if (conn->proto.tcp->local_port == serbridgeConn[1].proto.tcp->local_port)
connData[i].conn_mode = cmPGMInit;
espconn_regist_recvcb(conn, serbridgeRecvCb);
@@ -475,8 +475,8 @@ serbridgeInit()
serbridgeInitPins();
os_memset(connData, 0, sizeof(connData));
+ os_memset(&serbridgeTcp[0], 0, sizeof(serbridgeTcp[0]));
os_memset(&serbridgeTcp[1], 0, sizeof(serbridgeTcp[1]));
- os_memset(&serbridgeTcp[2], 0, sizeof(serbridgeTcp[2]));
}
// Start transparent serial bridge TCP server on specified port (typ. 23)
@@ -486,7 +486,12 @@ serbridgeStart(int ix, int port, int mode)
if (ix < 0 || ix > 2) // FIXME hardcoded limit
return;
- if (serbridgeConn[ix] != NULL) { serbridgeCleanup(ix); } //If we are already initialized, let's clean it up.
+
+ // If we are already initialized, let's clean it up.
+ if (serbridgeConn[ix].type != 0) {
+ serbridgeCleanup(ix);
+ }
+
if (0 < port && port < 65536 && port != 80) {
serbridgeConn[ix].type = ESPCONN_TCP;
serbridgeConn[ix].state = ESPCONN_NONE;
@@ -503,10 +508,8 @@ serbridgeStart(int ix, int port, int mode)
void ICACHE_FLASH_ATTR
serbridgeCleanup(int ix)
{
- if (serbridgeConn[ix] == NULL) return;
- // Free memory & set to NULL
- os_free(serbridgeConn[ix]);
- serbridgeConn[ix] = NULL;
+ os_memset(&serbridgeTcp[ix], 0, sizeof(serbridgeTcp[ix]));
+ // FIX ME need to clean up the actions in serbridgeStart() ? (e.g. espconn_regist_connectcb)
}
int ICACHE_FLASH_ATTR serbridgeInMCUFlashing()
From 36f15c9baa43a3e242a3533d04f3901b9a3f7e99 Mon Sep 17 00:00:00 2001
From: dannybackx
Date: Tue, 1 Nov 2016 09:45:44 +0100
Subject: [PATCH 44/64] Fix compile errors
---
esp-link/config.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/esp-link/config.c b/esp-link/config.c
index bb31af5a..98fcd218 100644
--- a/esp-link/config.c
+++ b/esp-link/config.c
@@ -37,8 +37,8 @@ FlashConfig flashDefault = {
.stop_bits = ONE_STOP_BIT,
.telnet_port1 = 23,
.telnet_port2 = 2323,
- .telnet_port1Mode = 0,
- .telnet_port2Mode = 0,
+ .telnet_port1mode = 0,
+ .telnet_port2mode = 0,
};
typedef union {
From 59a4707b5e9c1c6769b7381ed4ca45952627f200 Mon Sep 17 00:00:00 2001
From: dannybackx
Date: Tue, 1 Nov 2016 09:45:56 +0100
Subject: [PATCH 45/64] Fix compile errors
---
esp-link/config.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/esp-link/config.h b/esp-link/config.h
index c1c1f68e..6cbff12c 100644
--- a/esp-link/config.h
+++ b/esp-link/config.h
@@ -47,6 +47,7 @@ typedef struct {
telnet_port2mode;
} FlashConfig;
extern FlashConfig flashConfig;
+extern FlashConfig flashDefault;
bool configSave(void);
bool configRestore(void);
From 654f2ef6301e0df5cea714f5e225a5c659464d6d Mon Sep 17 00:00:00 2001
From: dannybackx
Date: Tue, 1 Nov 2016 09:51:40 +0100
Subject: [PATCH 46/64] Fix compile errors
---
esp-link/cgitelnet.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/esp-link/cgitelnet.c b/esp-link/cgitelnet.c
index c3a8c00d..f8d20684 100644
--- a/esp-link/cgitelnet.c
+++ b/esp-link/cgitelnet.c
@@ -7,7 +7,7 @@
int ICACHE_FLASH_ATTR cgiTelnetGet(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted
- char buff[1024];
+ char buff[80];
int len;
os_printf("Current telnet ports: port1=%d port2=%d\n",
@@ -27,15 +27,17 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
if (connData->conn==NULL) {
return HTTPD_CGI_DONE; // Connection aborted
}
-
+
int8_t ok = 0;
uint16_t port1, port2;
ok |= getUInt16Arg(connData, "port1", &port1);
ok |= getUInt16Arg(connData, "port2", &port2);
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",
+ char buf[80];
+ sprintf(buf, "Unable to fetch telnet ports.\n Received: port1=%d port2=%d\n",
flashConfig.telnet_port1, flashConfig.telnet_port2);
- errorResponse(connData, 400, buff);
+ os_printf(buf);
+ errorResponse(connData, 400, buf);
return HTTPD_CGI_DONE;
}
@@ -46,9 +48,11 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
// check whether ports are different
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);
+ char buf[80];
+ sprintf(buf, "Ports cannot be the same.\n Tried to set: port1=%d port2=%d\n",
+ flashConfig.telnet_port1, flashConfig.telnet_port2);
+ os_printf(buf);
+ errorResponse(connData, 400, buf);
return HTTPD_CGI_DONE;
}
@@ -74,6 +78,7 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
serbridgeStart(2, flashConfig.telnet_port2, flashDefault.telnet_port2mode);
}
+
return HTTPD_CGI_DONE;
}
From 4b3293eac441b01da512dde9abecd762fa430f3f Mon Sep 17 00:00:00 2001
From: dannybackx
Date: Tue, 1 Nov 2016 16:30:17 +0100
Subject: [PATCH 47/64] Change comment
---
serial/serbridge.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/serial/serbridge.c b/serial/serbridge.c
index 74b88464..8e9e0411 100644
--- a/serial/serbridge.c
+++ b/serial/serbridge.c
@@ -509,7 +509,7 @@ void ICACHE_FLASH_ATTR
serbridgeCleanup(int ix)
{
os_memset(&serbridgeTcp[ix], 0, sizeof(serbridgeTcp[ix]));
- // FIX ME need to clean up the actions in serbridgeStart() ? (e.g. espconn_regist_connectcb)
+ // Looks like none of the espconn_..() calls in serbridgeStart() needs cleanup here.
}
int ICACHE_FLASH_ATTR serbridgeInMCUFlashing()
From 547540d0d1f445aad08a477508379e15c46ad922 Mon Sep 17 00:00:00 2001
From: dannybackx
Date: Tue, 1 Nov 2016 16:53:45 +0100
Subject: [PATCH 48/64] Fix the build problem : don't call sprintf.
---
esp-link/cgitelnet.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/esp-link/cgitelnet.c b/esp-link/cgitelnet.c
index f8d20684..552f839c 100644
--- a/esp-link/cgitelnet.c
+++ b/esp-link/cgitelnet.c
@@ -5,9 +5,10 @@
// Cgi to return choice of Telnet ports
int ICACHE_FLASH_ATTR cgiTelnetGet(HttpdConnData *connData) {
+ char buff[80];
+
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted
- char buff[80];
int len;
os_printf("Current telnet ports: port1=%d port2=%d\n",
@@ -19,6 +20,7 @@ int ICACHE_FLASH_ATTR cgiTelnetGet(HttpdConnData *connData) {
jsonHeader(connData, 200);
httpdSend(connData, buff, len);
+
return HTTPD_CGI_DONE;
}
@@ -32,12 +34,11 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
uint16_t port1, port2;
ok |= getUInt16Arg(connData, "port1", &port1);
ok |= getUInt16Arg(connData, "port2", &port2);
+
if (ok <= 0) { //If we get at least one good value, this should be >= 1
- char buf[80];
- sprintf(buf, "Unable to fetch telnet ports.\n Received: port1=%d port2=%d\n",
+ os_printf("Unable to fetch telnet ports.\n Received: port1=%d port2=%d\n",
flashConfig.telnet_port1, flashConfig.telnet_port2);
- os_printf(buf);
- errorResponse(connData, 400, buf);
+ errorResponse(connData, 400, "Unable to fetch telnet ports.");
return HTTPD_CGI_DONE;
}
@@ -48,14 +49,12 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
// check whether ports are different
if (port1 == port2) {
- char buf[80];
- sprintf(buf, "Ports cannot be the same.\n Tried to set: port1=%d port2=%d\n",
+ os_printf("Ports cannot be the same.\n Tried to set: port1=%d port2=%d\n",
flashConfig.telnet_port1, flashConfig.telnet_port2);
- os_printf(buf);
- errorResponse(connData, 400, buf);
+ errorResponse(connData, 400, "Ports cannot be the same.");
return HTTPD_CGI_DONE;
}
-
+
// we're good, set flashconfig
flashConfig.telnet_port1 = port1;
flashConfig.telnet_port2 = port2;
@@ -74,13 +73,12 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
// apply the changes
serbridgeInit();
- serbridgeStart(1, flashConfig.telnet_port1, flashDefault.telnet_port1mode);
- serbridgeStart(2, flashConfig.telnet_port2, flashDefault.telnet_port2mode);
+ serbridgeStart(0, flashConfig.telnet_port1, flashDefault.telnet_port1mode);
+ serbridgeStart(1, flashConfig.telnet_port2, flashDefault.telnet_port2mode);
}
return HTTPD_CGI_DONE;
-
}
int ICACHE_FLASH_ATTR cgiTelnet(HttpdConnData *connData) {
From 589158eb5bdd79341c385aa9548b19c66f4db23b Mon Sep 17 00:00:00 2001
From: dannybackx
Date: Tue, 1 Nov 2016 17:14:57 +0100
Subject: [PATCH 49/64] Aha
---
esp-link/cgitelnet.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/esp-link/cgitelnet.c b/esp-link/cgitelnet.c
index 552f839c..0b3d0c9e 100644
--- a/esp-link/cgitelnet.c
+++ b/esp-link/cgitelnet.c
@@ -26,6 +26,8 @@ int ICACHE_FLASH_ATTR cgiTelnetGet(HttpdConnData *connData) {
// Cgi to change choice of Telnet ports
int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
+ char buf[80];
+
if (connData->conn==NULL) {
return HTTPD_CGI_DONE; // Connection aborted
}
@@ -36,9 +38,10 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
ok |= getUInt16Arg(connData, "port2", &port2);
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",
+ ets_sprintf(buf, "Unable to fetch telnet ports.\n Received: port1=%d port2=%d\n",
flashConfig.telnet_port1, flashConfig.telnet_port2);
- errorResponse(connData, 400, "Unable to fetch telnet ports.");
+ os_printf(buf);
+ errorResponse(connData, 400, buf);
return HTTPD_CGI_DONE;
}
@@ -49,9 +52,10 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
// check whether ports are different
if (port1 == port2) {
- os_printf("Ports cannot be the same.\n Tried to set: port1=%d port2=%d\n",
+ os_sprintf(buf, "Ports cannot be the same.\n Tried to set: port1=%d port2=%d\n",
flashConfig.telnet_port1, flashConfig.telnet_port2);
- errorResponse(connData, 400, "Ports cannot be the same.");
+ os_printf(buf);
+ errorResponse(connData, 400, buf);
return HTTPD_CGI_DONE;
}
From f3060e68722811f42b17b06ffcecbb801521a121 Mon Sep 17 00:00:00 2001
From: dannybackx
Date: Tue, 1 Nov 2016 17:22:24 +0100
Subject: [PATCH 50/64] Change call to 0/1 instead of 1/2
---
esp-link/main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/esp-link/main.c b/esp-link/main.c
index 54fa0754..49982f44 100644
--- a/esp-link/main.c
+++ b/esp-link/main.c
@@ -182,8 +182,8 @@ user_init(void) {
// init the wifi-serial transparent bridge (port 23)
serbridgeInit();
- serbridgeStart(1, flashConfig.telnet_port1, flashDefault.telnet_port1mode);
- serbridgeStart(2, flashConfig.telnet_port2, flashDefault.telnet_port2mode);
+ serbridgeStart(0, flashConfig.telnet_port1, flashDefault.telnet_port1mode);
+ serbridgeStart(1, flashConfig.telnet_port2, flashDefault.telnet_port2mode);
uart_add_recv_cb(&serbridgeUartCb);
#ifdef SHOW_HEAP_USE
From 286e8865ebd60d17d050d948160095725a12f897 Mon Sep 17 00:00:00 2001
From: Alex
Date: Thu, 3 Nov 2016 01:49:37 -0500
Subject: [PATCH 51/64] Makefile/Build file changes
---
Makefile | 68 +++++++++++++++++++++++++++++++----------------------
espmake.cmd | 3 ++-
2 files changed, 42 insertions(+), 29 deletions(-)
diff --git a/Makefile b/Makefile
index 4172785d..2a187d7f 100644
--- a/Makefile
+++ b/Makefile
@@ -52,12 +52,13 @@ ESP_HOSTNAME ?= esp-link
# Base directory for the compiler. Needs a / at the end.
# Typically you'll install https://github.com/pfalcon/esp-open-sdk
# IMPORTANT: use esp-open-sdk `make STANDALONE=n`: the SDK bundled with esp-open-sdk will *not* work!
-XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/
+XTENSA_TOOLS_ROOT ?= $(abspath ../espressif/xtensa-lx106-elf/bin)/
+$(warning Using XTENSA TOOLS from $(XTENSA_TOOLS_ROOT))
# Firmware version
# WARNING: if you change this expect to make code adjustments elsewhere, don't expect
# that esp-link will magically work with a different version of the SDK!!!
-SDK_VERS ?= esp_iot_sdk_v2.0.0.p1
+SDK_VERS ?= ESP8266_SDK
# Try to find the firmware manually extracted, e.g. after downloading from Espressif's BBS,
# http://bbs.espressif.com/viewforum.php?f=46
@@ -66,16 +67,17 @@ SDK_BASE ?= $(wildcard ../$(SDK_VERS))
# If the firmware isn't there, see whether it got downloaded as part of esp-open-sdk
# This used to work at some point, but is not supported, uncomment if you feel lucky ;-)
-#ifeq ($(SDK_BASE),)
-#SDK_BASE := $(wildcard $(XTENSA_TOOLS_ROOT)/../../$(SDK_VERS))
-#endif
+ifeq ($(SDK_BASE),)
+SDK_BASE := $(wildcard $(XTENSA_TOOLS_ROOT)/../../$(SDK_VERS))
+endif
# Clean up SDK path
SDK_BASE := $(abspath $(SDK_BASE))
$(warning Using SDK from $(SDK_BASE))
# Path to bootloader file
-BOOTFILE ?= $(SDK_BASE/bin/boot_v1.6.bin)
+BOOTFILE ?= $(SDK_BASE)/bin/boot_v1.6.bin
+$(warning Using boot file-> $(BOOTFILE))
# Esptool.py path and port, only used for 1-time serial flashing
# Typically you'll use https://github.com/themadinventor/esptool
@@ -127,8 +129,10 @@ GZIP_COMPRESSION ?= yes
# http://yui.github.io/yuicompressor/
# enabled by default.
COMPRESS_W_HTMLCOMPRESSOR ?= yes
-HTML_COMPRESSOR ?= htmlcompressor-1.5.3.jar
-YUI_COMPRESSOR ?= yuicompressor-2.4.8.jar
+HTML_COMPRESSOR_VER ?= htmlcompressor-1.5.3.jar
+HTML_COMPRESSOR = tools/$(HTML_COMPRESSOR_VER)
+YUI_COMPRESSOR_VER ?= yuicompressor-2.4.8.jar
+YUI_COMPRESSOR = tools/$(YUI_COMPRESSOR_VER)
# -------------- End of config options -------------
@@ -296,6 +300,13 @@ Q := @
vecho := @echo
endif
+#Fix for issues on some windows systems that call non GNU FIND
+FIND ?= $(which FIND)
+ifeq (,$(findstring system32,$(FIND)))
+ $(warning Non GNU 'find' called. Trying alternate path /usr/bin/find)
+ FIND = /usr/bin/find
+endif
+
ifneq ($(strip $(STA_SSID)),)
CFLAGS += -DSTA_SSID="$(STA_SSID)"
endif
@@ -387,6 +398,7 @@ $(FW_BASE)/user2.bin: $(USER2_OUT) $(FW_BASE)
$(Q) COMPILE=gcc PATH=$(XTENSA_TOOLS_ROOT):$(PATH) python $(APPGEN_TOOL) $(USER2_OUT) 2 $(ESP_FLASH_MODE) $(ESP_FLASH_FREQ_DIV) $(ESP_SPI_SIZE) 1 >/dev/null
$(Q) rm -f eagle.app.v6.*.bin
$(Q) mv eagle.app.flash.bin $@
+ @echo "** user2.bin uses $$(stat -c '%s' $@) bytes of" $(ESP_FLASH_MAX) "available"
$(Q) if [ $$(stat -c '%s' $@) -gt $$(( $(ESP_FLASH_MAX) )) ]; then echo "$@ too big!"; false; fi
$(APP_AR): $(OBJ)
@@ -406,18 +418,18 @@ baseflash: all
flash: all
$(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash -fs $(ET_FS) -ff $(ET_FF) \
- 0x00000 "$(SDK_BASE)/bin/boot_v1.5.bin" 0x01000 $(FW_BASE)/user1.bin \
+ 0x00000 "$(BOOTFILE)" 0x01000 $(FW_BASE)/user1.bin \
$(ET_BLANK) $(SDK_BASE)/bin/blank.bin
tools/$(HTML_COMPRESSOR):
$(Q) echo "The jar files in the tools dir are missing, they should be in the source repo"
$(Q) echo "The following commands can be used to fetch them, but the URLs have changed..."
$(Q) echo mkdir -p tools
- $(Q) echo "cd tools; wget --no-check-certificate https://github.com/yui/yuicompressor/releases/download/v2.4.8/$(YUI_COMPRESSOR) -O $(YUI_COMPRESSOR)"
- $(Q) echo "cd tools; wget --no-check-certificate https://htmlcompressor.googlecode.com/files/$(HTML_COMPRESSOR) -O $(HTML_COMPRESSOR)"
+ $(Q) echo "cd tools; wget --no-check-certificate https://github.com/yui/yuicompressor/releases/download/v2.4.8/$(YUI_COMPRESSOR_VER) -O $(YUI_COMPRESSOR_VER)"
+ $(Q) echo "cd tools; wget --no-check-certificate https://htmlcompressor.googlecode.com/files/$(HTML_COMPRESSOR_VER) -O $(HTML_COMPRESSOR_VER)"
ifeq ("$(COMPRESS_W_HTMLCOMPRESSOR)","yes")
-$(BUILD_BASE)/espfs_img.o: tools/$(HTML_COMPRESSOR)
+$(BUILD_BASE)/espfs_img.o: $(HTML_COMPRESSOR)
endif
$(BUILD_BASE)/espfs_img.o: html/ html/wifi/ espfs/mkespfsimage/mkespfsimage
@@ -428,38 +440,38 @@ $(BUILD_BASE)/espfs_img.o: html/ html/wifi/ espfs/mkespfsimage/mkespfsimage
$(Q) cp -r html/wifi/*.png html_compressed/wifi;
$(Q) cp -r html/wifi/*.js html_compressed/wifi;
ifeq ("$(COMPRESS_W_HTMLCOMPRESSOR)","yes")
- $(Q) echo "Compressing assets with htmlcompressor. This may take a while..."
- $(Q) java -jar tools/$(HTML_COMPRESSOR) \
+ $(Q) echo "Compressing assets with htmlcompressor. This may take a while...";
+ $(Q) java -jar $(HTML_COMPRESSOR) \
-t html --remove-surrounding-spaces max --remove-quotes --remove-intertag-spaces \
-o $(abspath ./html_compressed)/ \
$(HTML_PATH)head- \
$(HTML_PATH)*.html
- $(Q) java -jar tools/$(HTML_COMPRESSOR) \
+ $(Q) java -jar $(HTML_COMPRESSOR) \
-t html --remove-surrounding-spaces max --remove-quotes --remove-intertag-spaces \
-o $(abspath ./html_compressed)/wifi/ \
$(WIFI_PATH)*.html
$(Q) echo "Compressing assets with yui-compressor. This may take a while..."
- $(Q) for file in `find html_compressed -type f -name "*.js"`; do \
- java -jar tools/$(YUI_COMPRESSOR) $$file --line-break 0 -o $$file; \
- done
- $(Q) for file in `find html_compressed -type f -name "*.css"`; do \
- java -jar tools/$(YUI_COMPRESSOR) $$file -o $$file; \
- done
+ $(Q) java -jar $(YUI_COMPRESSOR) ./html_compressed/*.css -o '.css$:.css'
+ $(Q) java -jar $(YUI_COMPRESSOR) ./html_compressed/*.js -o '.js$:.js'
+ $(Q) java -jar $(YUI_COMPRESSOR) ./html_compressed/wifi/*.js -o '.js$:.js'
else
$(Q) cp -r html/head- html_compressed;
$(Q) cp -r html/*.html html_compressed;
$(Q) cp -r html/wifi/*.html html_compressed/wifi;
endif
+
ifeq (,$(findstring mqtt,$(MODULES)))
- $(Q) rm -rf html_compressed/mqtt.html
- $(Q) rm -rf html_compressed/mqtt.js
+ $(Q) rm -rf html_compressed/mqtt.html;
+ $(Q) rm -rf html_compressed/mqtt.js;
endif
- $(Q) for file in `find html_compressed -type f -name "*.htm*"`; do \
+
+ $(Q) for file in `$(FIND) html_compressed -type f -name "*.htm*"`; do \
cat html_compressed/head- $$file >$${file}-; \
mv $$file- $$file; \
done
$(Q) rm html_compressed/head-
- $(Q) cd html_compressed; find . \! -name \*- | ../espfs/mkespfsimage/mkespfsimage > ../build/espfs.img; cd ..;
+ $(Q) echo "Compressing assets into espfs.img with Gzip. This may take a while..."
+ $(Q) cd html_compressed; $(FIND) . \! -name \*- | ../espfs/mkespfsimage/mkespfsimage > ../build/espfs.img; cd ..;
$(Q) ls -sl build/espfs.img
$(Q) cd build; $(OBJCP) -I binary -O elf32-xtensa-le -B xtensa --rename-section .data=.espfs \
espfs.img espfs_img.o; cd ..
@@ -483,7 +495,7 @@ release: all
$(Q) egrep -a 'esp-link [a-z0-9.]+ - 201' $(FW_BASE)/user1.bin | cut -b 1-80
$(Q) egrep -a 'esp-link [a-z0-9.]+ - 201' $(FW_BASE)/user2.bin | cut -b 1-80
$(Q) cp $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin $(SDK_BASE)/bin/blank.bin \
- "$(SDK_BASE)/bin/boot_v1.6.bin" "$(SDK_BASE)/bin/esp_init_data_default.bin" \
+ "$(BOOTFILE)" "$(SDK_BASE)/bin/esp_init_data_default.bin" \
wiflash avrflash release/esp-link-$(BRANCH)
$(Q) tar zcf esp-link-$(BRANCH)-$(SHA).tgz -C release esp-link-$(BRANCH)
$(Q) echo "Release file: esp-link-$(BRANCH)-$(SHA).tgz"
@@ -494,7 +506,7 @@ docker:
clean:
$(Q) rm -f $(APP_AR)
$(Q) rm -f $(TARGET_OUT)
- $(Q) find $(BUILD_BASE) -type f | xargs rm -f
+ $(Q) $(FIND) $(BUILD_BASE) -type f | xargs rm -f
$(Q) make -C espfs/mkespfsimage/ clean
$(Q) rm -rf $(FW_BASE)
$(Q) rm -f webpages.espfs
@@ -502,4 +514,4 @@ ifeq ("$(COMPRESS_W_HTMLCOMPRESSOR)","yes")
$(Q) rm -rf html_compressed
endif
-$(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))
+$(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))
\ No newline at end of file
diff --git a/espmake.cmd b/espmake.cmd
index 42e25a65..f475e01c 100644
--- a/espmake.cmd
+++ b/espmake.cmd
@@ -1,5 +1,6 @@
@echo off
-
+SETLOCAL
+REM LOCAL IS NEEDED ELSE WE KEEP ADDING TO WINDOW PATH EACH TIME SCRIPT IS CALLED.
REM remove automatic created obj folder
rd obj /S /Q >nul 2>&1
From 6596883fb194e58a4ff482959c18ac243b62b48c Mon Sep 17 00:00:00 2001
From: Alex
Date: Thu, 3 Nov 2016 02:01:02 -0500
Subject: [PATCH 52/64] Formatting cleanup
---
Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 2a187d7f..d191e161 100644
--- a/Makefile
+++ b/Makefile
@@ -461,8 +461,8 @@ else
endif
ifeq (,$(findstring mqtt,$(MODULES)))
- $(Q) rm -rf html_compressed/mqtt.html;
- $(Q) rm -rf html_compressed/mqtt.js;
+ $(Q) rm -rf html_compressed/mqtt.html
+ $(Q) rm -rf html_compressed/mqtt.js
endif
$(Q) for file in `$(FIND) html_compressed -type f -name "*.htm*"`; do \
From 0b8368af2401bf21ff00dcf75a030ad0f8bfb749 Mon Sep 17 00:00:00 2001
From: Alex
Date: Thu, 3 Nov 2016 02:02:30 -0500
Subject: [PATCH 53/64] Modify all calls to port variables to match. Espconn1 =
TelnetPort1
Should make code more fluid & inuitive.
All code changes made to reflect javascrupt, html, and C.
---
esp-link/cgi.c | 2 +-
esp-link/cgitelnet.c | 34 +++++++++++++++++-----------------
esp-link/config.c | 8 ++++----
esp-link/config.h | 8 ++++----
esp-link/main.c | 4 ++--
html/home.html | 8 ++++----
html/ui.js | 1 +
7 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/esp-link/cgi.c b/esp-link/cgi.c
index d667be3f..6d0d79e6 100644
--- a/esp-link/cgi.c
+++ b/esp-link/cgi.c
@@ -190,7 +190,7 @@ int ICACHE_FLASH_ATTR printGlobalInfo(char *buff, int buflen, char *token) {
extern char *esp_link_version; // in user_main.c
-int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) {
+int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) { //This is where we can modify the navigation that is auto generated
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
char buff[1024];
// don't use jsonHeader so the response does get cached
diff --git a/esp-link/cgitelnet.c b/esp-link/cgitelnet.c
index 0b3d0c9e..0530fc82 100644
--- a/esp-link/cgitelnet.c
+++ b/esp-link/cgitelnet.c
@@ -11,12 +11,12 @@ int ICACHE_FLASH_ATTR cgiTelnetGet(HttpdConnData *connData) {
int len;
- os_printf("Current telnet ports: port1=%d port2=%d\n",
- flashConfig.telnet_port1, flashConfig.telnet_port2);
+ os_printf("Current telnet ports: port0=%d port1=%d\n",
+ flashConfig.telnet_port0, flashConfig.telnet_port1);
len = os_sprintf(buff,
- "{ \"port1\": \"%d\", \"port2\": \"%d\" }",
- flashConfig.telnet_port1, flashConfig.telnet_port2);
+ "{ \"port0\": \"%d\", \"port1\": \"%d\" }",
+ flashConfig.telnet_port0, flashConfig.telnet_port1);
jsonHeader(connData, 200);
httpdSend(connData, buff, len);
@@ -33,13 +33,13 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
}
int8_t ok = 0;
- uint16_t port1, port2;
+ uint16_t port0, port1;
+ ok |= getUInt16Arg(connData, "port0", &port0);
ok |= getUInt16Arg(connData, "port1", &port1);
- ok |= getUInt16Arg(connData, "port2", &port2);
if (ok <= 0) { //If we get at least one good value, this should be >= 1
- ets_sprintf(buf, "Unable to fetch telnet ports.\n Received: port1=%d port2=%d\n",
- flashConfig.telnet_port1, flashConfig.telnet_port2);
+ ets_sprintf(buf, "Unable to fetch telnet ports.\n Received: port0=%d port1=%d\n",
+ flashConfig.telnet_port0, flashConfig.telnet_port1);
os_printf(buf);
errorResponse(connData, 400, buf);
return HTTPD_CGI_DONE;
@@ -47,23 +47,23 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
if (ok > 0) {
// fill both port variables from flash or ajax provided value
+ if (!port0) port0 = flashConfig.telnet_port0;
if (!port1) port1 = flashConfig.telnet_port1;
- if (!port2) port2 = flashConfig.telnet_port2;
// check whether ports are different
- if (port1 == port2) {
- os_sprintf(buf, "Ports cannot be the same.\n Tried to set: port1=%d port2=%d\n",
- flashConfig.telnet_port1, flashConfig.telnet_port2);
+ if (port0 == port1) {
+ os_sprintf(buf, "Ports cannot be the same.\n Tried to set: port0=%d port1=%d\n",
+ flashConfig.telnet_port0, flashConfig.telnet_port1);
os_printf(buf);
errorResponse(connData, 400, buf);
return HTTPD_CGI_DONE;
}
// we're good, set flashconfig
+ flashConfig.telnet_port0 = port0;
flashConfig.telnet_port1 = port1;
- flashConfig.telnet_port2 = port2;
- os_printf("Telnet ports changed: port1=%d port2=%d\n",
- flashConfig.telnet_port1, flashConfig.telnet_port2);
+ os_printf("Telnet ports changed: port0=%d port1=%d\n",
+ flashConfig.telnet_port0, flashConfig.telnet_port1);
// save to flash
if (configSave()) {
@@ -77,8 +77,8 @@ int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
// apply the changes
serbridgeInit();
- serbridgeStart(0, flashConfig.telnet_port1, flashDefault.telnet_port1mode);
- serbridgeStart(1, flashConfig.telnet_port2, flashDefault.telnet_port2mode);
+ serbridgeStart(0, flashConfig.telnet_port0, flashDefault.telnet_port0mode);
+ serbridgeStart(1, flashConfig.telnet_port1, flashDefault.telnet_port1mode);
}
diff --git a/esp-link/config.c b/esp-link/config.c
index 98fcd218..ab0f385b 100644
--- a/esp-link/config.c
+++ b/esp-link/config.c
@@ -35,10 +35,10 @@ FlashConfig flashDefault = {
.data_bits = EIGHT_BITS,
.parity = NONE_BITS,
.stop_bits = ONE_STOP_BIT,
- .telnet_port1 = 23,
- .telnet_port2 = 2323,
+ .telnet_port0 = 23,
+ .telnet_port1 = 2323,
+ .telnet_port0mode = 0,
.telnet_port1mode = 0,
- .telnet_port2mode = 0,
};
typedef union {
@@ -166,8 +166,8 @@ bool ICACHE_FLASH_ATTR configRestore(void) {
flashConfig.stop_bits = flashDefault.stop_bits;
}
+ if (flashConfig.telnet_port0 == 0) { flashConfig.telnet_port0 = flashDefault.telnet_port0; }
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 6cbff12c..094c044e 100644
--- a/esp-link/config.h
+++ b/esp-link/config.h
@@ -41,10 +41,10 @@ typedef struct {
int8_t data_bits;
int8_t parity;
int8_t stop_bits;
- uint16_t telnet_port1, // Telnet port settings
- telnet_port2;
- int8_t telnet_port1mode,
- telnet_port2mode;
+ uint16_t telnet_port0, // Telnet port settings
+ telnet_port1;
+ int8_t telnet_port0mode,
+ telnet_port1mode;
} FlashConfig;
extern FlashConfig flashConfig;
extern FlashConfig flashDefault;
diff --git a/esp-link/main.c b/esp-link/main.c
index 49982f44..90202fad 100644
--- a/esp-link/main.c
+++ b/esp-link/main.c
@@ -182,8 +182,8 @@ user_init(void) {
// init the wifi-serial transparent bridge (port 23)
serbridgeInit();
- serbridgeStart(0, flashConfig.telnet_port1, flashDefault.telnet_port1mode);
- serbridgeStart(1, flashConfig.telnet_port2, flashDefault.telnet_port2mode);
+ serbridgeStart(0, flashConfig.telnet_port0, flashDefault.telnet_port0mode);
+ serbridgeStart(1, flashConfig.telnet_port1, flashDefault.telnet_port1mode);
uart_add_recv_cb(&serbridgeUartCb);
#ifdef SHOW_HEAP_USE
diff --git a/html/home.html b/html/home.html
index a3d2b87e..5bce56be 100644
--- a/html/home.html
+++ b/html/home.html
@@ -53,19 +53,19 @@ Info
Telnet Serial-Bridge
There are two ports available for telnet to use by default: 23 & 2323
- Note - this time, only port1 may be changed & used sucessfully.
+ Note - this time, only port0 may be changed & used sucessfully.
Current Telnet ports | |
+ Port0 Mode
+
+
+
+
+ |
makeAjaxInput("system", "name");
makeAjaxInput("telnet", "port0");
makeAjaxInput("telnet", "port1");
+ makeAjaxInput("telnet", "port0mode");
fetchPins();
getWifiInfo();
getSystemInfo();
diff --git a/html/ui.js b/html/ui.js
index 5e83babc..3a00ef83 100644
--- a/html/ui.js
+++ b/html/ui.js
@@ -401,7 +401,7 @@ function showNotification(text) {
var el = $("#notification");
el.innerHTML = text;
el.removeAttribute('hidden');
- // window.scrollTo(0, 0); //Uncomment this line so window will scroll up on regular notifications
+ window.scrollTo(0, 0); //Uncomment this line so window will scroll up on regular notifications
if (notifTimeout != null) clearTimeout(notifTimeout);
notifTimout = setTimeout(function() {
el.setAttribute('hidden', '');
From 6fd5938882fe1fa2fcd78f96f0e4d7d242cccb0c Mon Sep 17 00:00:00 2001
From: Alex