From daba5340f7609c45d7efac963be695fa27b89f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Tue, 5 Sep 2017 02:13:16 +0200 Subject: [PATCH] fixes and tweaks. implemented polling reload on HB loss --- esphttpdconfig.mk | 2 +- html_orig/js/app.js | 18 +++++++++++++++--- html_orig/jssrc/term.js | 18 +++++++++++++++--- libesphttpd | 2 +- user/cgi_sockets.c | 2 +- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/esphttpdconfig.mk b/esphttpdconfig.mk index dc03845..981ec4e 100644 --- a/esphttpdconfig.mk +++ b/esphttpdconfig.mk @@ -50,7 +50,7 @@ GLOBAL_CFLAGS = \ -DDEBUG_ANSI=1 \ -DDEBUG_ANSI_NOIMPL=1 \ -DHTTPD_MAX_BACKLOG_SIZE=8192 \ - -DHTTPD_MAX_HEAD_LEN=512 \ + -DHTTPD_MAX_HEAD_LEN=1024 \ -DHTTPD_MAX_POST_LEN=512 \ -DDEBUG_INPUT=0 \ -DDEBUG_HEAP=1 \ diff --git a/html_orig/js/app.js b/html_orig/js/app.js index 33d2510..6095ede 100644 --- a/html_orig/js/app.js +++ b/html_orig/js/app.js @@ -1958,6 +1958,7 @@ var Screen = (function () { var Conn = (function() { var ws; var heartbeatTout; + var pingIv; function onOpen(evt) { console.log("CONNECTED"); @@ -2023,12 +2024,23 @@ var Conn = (function() { function heartbeat() { clearTimeout(heartbeatTout); - heartbeatTout = setTimeout(heartbeatFail, 3000); + heartbeatTout = setTimeout(heartbeatFail, 2000); } function heartbeatFail() { - console.error("Heartbeat lost, reloading..."); - location.reload(); + console.error("Heartbeat lost, probing server..."); + pingIv = setInterval(function() { + console.log("> ping"); + $.get('http://'+_root+'/system/ping', function(resp, status) { + if (status == 200) { + clearInterval(pingIv); + console.info("Server ready, reloading page..."); + location.reload(); + } + }, { + timeout: 100, + }); + }, 500); } return { diff --git a/html_orig/jssrc/term.js b/html_orig/jssrc/term.js index 4686cee..8f90db6 100644 --- a/html_orig/jssrc/term.js +++ b/html_orig/jssrc/term.js @@ -392,6 +392,7 @@ var Screen = (function () { var Conn = (function() { var ws; var heartbeatTout; + var pingIv; function onOpen(evt) { console.log("CONNECTED"); @@ -457,12 +458,23 @@ var Conn = (function() { function heartbeat() { clearTimeout(heartbeatTout); - heartbeatTout = setTimeout(heartbeatFail, 3000); + heartbeatTout = setTimeout(heartbeatFail, 2000); } function heartbeatFail() { - console.error("Heartbeat lost, reloading..."); - location.reload(); + console.error("Heartbeat lost, probing server..."); + pingIv = setInterval(function() { + console.log("> ping"); + $.get('http://'+_root+'/system/ping', function(resp, status) { + if (status == 200) { + clearInterval(pingIv); + console.info("Server ready, reloading page..."); + location.reload(); + } + }, { + timeout: 100, + }); + }, 500); } return { diff --git a/libesphttpd b/libesphttpd index 566e95a..13fa224 160000 --- a/libesphttpd +++ b/libesphttpd @@ -1 +1 @@ -Subproject commit 566e95af0c892576825903303ca7c65710cbbb5e +Subproject commit 13fa224963081e9ff298abd74a59faafcb9bf816 diff --git a/user/cgi_sockets.c b/user/cgi_sockets.c index 23b65d7..f2705d3 100644 --- a/user/cgi_sockets.c +++ b/user/cgi_sockets.c @@ -11,7 +11,7 @@ #define LOOPBACK 0 -#define HB_TIME 1500 +#define HB_TIME 1000 #define SOCK_BUF_LEN 2000