Skip to content

Commit 3829b17

Browse files
committed
Fixed a connection reset during updating. #325
1 parent faab808 commit 3829b17

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/AutoConnectUpdate.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* AutoConnectUpdate class implementation.
33
* @file AutoConnectUpdate.cpp
44
5-
* @version 1.3.5
6-
* @date 2022-04-22
5+
* @version 1.3.6
6+
* @date 2022-07-25
77
* @copyright MIT license.
88
*/
99

@@ -104,15 +104,6 @@ typename std::enable_if<!AutoConnectUtil::has_func_onProgress<T>::value, AutoCon
104104
}
105105
}
106106

107-
/**
108-
* Definitions of notification commands to synchronize update processing
109-
* with the Web client.
110-
*/
111-
#define UPDATE_NOTIFY_START "#s"
112-
#define UPDATE_NOTIFY_PROGRESS "#p"
113-
#define UPDATE_NOTIFY_END "#e"
114-
#define UPDATE_NOTIFY_REBOOT "#r"
115-
116107
/**
117108
* A destructor. Release the update processing dialogue page generated
118109
* as AutoConnectAux.
@@ -555,7 +546,7 @@ void AutoConnectUpdateAct::_progress(void) {
555546
reqOperand = _webServer->arg(reqOperation);
556547
switch (_status) {
557548
case UPDATE_IDLE:
558-
if (reqOperand == String(UPDATE_NOTIFY_START)) {
549+
if (reqOperand == String(AUTOCONNECT_UPDATE_NOTIFY_START)) {
559550
httpCode = 200;
560551
_status = UPDATE_START;
561552
}
@@ -565,7 +556,7 @@ void AutoConnectUpdateAct::_progress(void) {
565556
}
566557
break;
567558
case UPDATE_SUCCESS:
568-
if (reqOperand == String(UPDATE_NOTIFY_REBOOT)) {
559+
if (reqOperand == String(AUTOCONNECT_UPDATE_NOTIFY_REBOOT)) {
569560
_status = UPDATE_RESET;
570561
httpCode = 200;
571562
}
@@ -583,14 +574,14 @@ void AutoConnectUpdateAct::_progress(void) {
583574
case HTTP_GET:
584575
switch (_status) {
585576
case UPDATE_PROGRESS:
586-
payload = String(UPDATE_NOTIFY_PROGRESS) + ',' + String(_amount) + ':' + String(_binSize);
577+
payload = String(AUTOCONNECT_UPDATE_NOTIFY_PROGRESS) + ',' + String(_amount) + ':' + String(_binSize);
587578
httpCode = 200;
588579
break;
589580
case UPDATE_IDLE:
590581
case UPDATE_SUCCESS:
591582
case UPDATE_NOAVAIL:
592583
case UPDATE_FAIL:
593-
payload = String(UPDATE_NOTIFY_END);
584+
payload = String(AUTOCONNECT_UPDATE_NOTIFY_END);
594585
httpCode = 200;
595586
break;
596587
default:

src/AutoConnectUpdatePage.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
* AutoConnectUpdate class.
44
* @file AutoConnectUpdatePage.h
55
6-
* @version 1.3.5
7-
* @date 2022-04-22
6+
* @version 1.3.6
7+
* @date 2022-07-25
88
* @copyright MIT license.
99
*/
1010

1111
#ifndef _AUTOCONNECTUPDATEPAGE_H_
1212
#define _AUTOCONNECTUPDATEPAGE_H_
1313

14+
/**
15+
* Definitions of notification commands to synchronize update processing
16+
* with the Web client.
17+
*/
18+
#define AUTOCONNECT_UPDATE_NOTIFY_START "#s"
19+
#define AUTOCONNECT_UPDATE_NOTIFY_PROGRESS "#p"
20+
#define AUTOCONNECT_UPDATE_NOTIFY_END "#e"
21+
#define AUTOCONNECT_UPDATE_NOTIFY_REBOOT "#r"
22+
1423
// Define the AUTOCONNECT_URI_UPDATE page to select the sketch binary
1524
// for update and order update execution.
1625
const AutoConnectAux::ACElementProp_t AutoConnectUpdateAct::_elmCatalog[] PROGMEM = {
@@ -38,9 +47,9 @@ const AutoConnectAux::ACElementProp_t AutoConnectUpdateAct::_elmProgress[] PROGM
3847
{ AC_Element, "progress_loader", "<div id=\"ld\" />", nullptr },
3948
{ AC_Element, "c4", "</span></div>", nullptr },
4049
{ AC_Text, "status", nullptr, nullptr },
41-
{ AC_Element, "c5", "<script type=\"text/javascript\">var lap,cls;function rd(){clearInterval(lap),location.href=\"" AUTOCONNECT_URI_UPDATE_RESULT "\"}function bar(){var t=new FormData;t.append(\"op\",\"#s\");var e=new XMLHttpRequest;e.timeout=" AUTOCONNECT_STRING_DEPLOY(AUTOCONNECT_UPDATE_TIMEOUT) ",e.open(\"POST\",\"" AUTOCONNECT_URI_UPDATE_PROGRESS "\",!0),e.onreadystatechange=function(){4==e.readyState&&(200==e.status?(cls=!1,lap=setInterval(upd," AUTOCONNECT_STRING_DEPLOY(AUTOCONNECT_UPDATE_INTERVAL) ")):document.getElementById(\"status\").textContent=\"Could not start (\"+e.status+\"): \"+e.responseText)},e.send(t)}function upd(){if(!cls){var t=new XMLHttpRequest;t.onload=function(){var t=this.responseText.split(\",\");\"#s\"==t[0]?(window.setTimeout(rd()," AUTOCONNECT_STRING_DEPLOY(AUTOCONNECT_UPDATE_DURATION) ")", nullptr },
50+
{ AC_Element, "c5", "<script type=\"text/javascript\">var lap,cls;function rd(){clearInterval(lap),location.href=\"" AUTOCONNECT_URI_UPDATE_RESULT "\"}function bar(){var t=new FormData;t.append(\"op\",\"" AUTOCONNECT_UPDATE_NOTIFY_START "\");var e=new XMLHttpRequest;e.timeout=" AUTOCONNECT_STRING_DEPLOY(AUTOCONNECT_UPDATE_TIMEOUT) ",e.open(\"POST\",\"" AUTOCONNECT_URI_UPDATE_PROGRESS "\",!0),e.onreadystatechange=function(){4==e.readyState&&(200==e.status?(cls=!1,lap=setInterval(upd," AUTOCONNECT_STRING_DEPLOY(AUTOCONNECT_UPDATE_INTERVAL) ")):document.getElementById(\"status\").textContent=\"Could not start (\"+e.status+\"): \"+e.responseText)},e.send(t)}function upd(){if(!cls){var t=new XMLHttpRequest;t.onload=function(){var t=this.responseText.split(\",\");\"" AUTOCONNECT_UPDATE_NOTIFY_START "\"==t[0]?(window.setTimeout(rd()," AUTOCONNECT_STRING_DEPLOY(AUTOCONNECT_UPDATE_DURATION) ")", nullptr },
4251
{ AC_Element, "enable_loader", ",document.getElementById(\"ld\").className=\"loader\"", nullptr },
43-
{ AC_Element, "c6", "):\"#e\"==t[0]?(cls=!0,rd()):\"#p\"==t[0]&&incr(t[1])},t.onerror=function(){document.getElementById(\"status\").textContent=\"Failed to update: \"+t.status,console.log(\"http err:%d %s\",t.status,t.responseText),clearInterval(lap)},t.open(\"GET\",\"" AUTOCONNECT_URI_UPDATE_PROGRESS "\",!0),t.send()}}function incr(t){", nullptr },
52+
{ AC_Element, "c6", "):\"" AUTOCONNECT_UPDATE_NOTIFY_END "\"==t[0]?(cls=!0,rd()):\"" AUTOCONNECT_UPDATE_NOTIFY_PROGRESS "\"==t[0]&&incr(t[1])},t.onerror=function(){\"0\"!=t.status&&(document.getElementById(\"status\").textContent=\"" AUTOCONNECT_TEXT_OTAFAILURE "\"+t.status,console.log(\"http err:%d %s\",t.status,t.responseText),clearInterval(lap))},t.open(\"GET\",\"" AUTOCONNECT_URI_UPDATE_PROGRESS "\",!0),t.send()}}function incr(t){", nullptr },
4453
{ AC_Element, "inprogress_meter", "var e=t.split(\":\"),n=document.getElementById(\"progress\").getElementsByTagName(\"meter\");n[0].setAttribute(\"value\",e[0]),n[0].setAttribute(\"max\",e[1])", nullptr },
4554
{ AC_Element, "c7", "}window.onload=bar;</script>", nullptr }
4655
};
@@ -51,7 +60,7 @@ const AutoConnectAux::ACPage_t AutoConnectUpdateAct::_pageProgress PROGMEM = {
5160
// Definition of the AUTOCONNECT_URI_UPDATE_RESULT page to notify update results
5261
const AutoConnectAux::ACElementProp_t AutoConnectUpdateAct::_elmResult[] PROGMEM = {
5362
{ AC_Text, "status", nullptr, nullptr },
54-
{ AC_Element, "restart", "<script type=\"text/javascript\">window.onload=function(){var e=new FormData;e.append(\"op\",\"#r\");var o=new XMLHttpRequest;o.timeout=" AUTOCONNECT_STRING_DEPLOY(AUTOCONNECT_UPDATE_TIMEOUT) ",o.onloadend=function(){setTimeout(\"location.href='" AUTOCONNECT_HOMEURI "'\"," AUTOCONNECT_STRING_DEPLOY(AUTOCONNECT_UPDATE_WAITFORREBOOT) ")},o.open(\"POST\",\"" AUTOCONNECT_URI_UPDATE_PROGRESS "\",!0),o.send(e)};</script>", nullptr }
63+
{ AC_Element, "restart", "<script type=\"text/javascript\">window.onload=function(){var e=new FormData;e.append(\"op\",\"" AUTOCONNECT_UPDATE_NOTIFY_REBOOT "\");var o=new XMLHttpRequest;o.timeout=" AUTOCONNECT_STRING_DEPLOY(AUTOCONNECT_UPDATE_TIMEOUT) ",o.onloadend=function(){setTimeout(\"location.href='" AUTOCONNECT_HOMEURI "'\"," AUTOCONNECT_STRING_DEPLOY(AUTOCONNECT_UPDATE_WAITFORREBOOT) ")},o.open(\"POST\",\"" AUTOCONNECT_URI_UPDATE_PROGRESS "\",!0),o.send(e)};</script>", nullptr }
5564
};
5665
const AutoConnectAux::ACPage_t AutoConnectUpdateAct::_pageResult PROGMEM = {
5766
AUTOCONNECT_URI_UPDATE_RESULT, AUTOCONNECT_MENULABEL_UPDATE, false, AutoConnectUpdateAct::_elmResult

0 commit comments

Comments
 (0)