From 1e0e8a4aafbc7a06c7a5ff57dde275eb75e31156 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sat, 23 May 2015 19:41:17 -0700 Subject: [PATCH] fix wifi connecting status update --- html/wifi/connecting.html | 24 ++++++++++++------------ serial/serbridge.c | 6 ++++++ user/cgiwifi.c | 18 ++++++++---------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/html/wifi/connecting.html b/html/wifi/connecting.html index 230b26f..3959512 100644 --- a/html/wifi/connecting.html +++ b/html/wifi/connecting.html @@ -11,16 +11,16 @@ function getStatus() { xhr.onreadystatechange=function() { if (xhr.readyState==4 && xhr.status>=200 && xhr.status<300) { var data=JSON.parse(xhr.responseText); - if (data.status=="idle") { - $("#status").innerHTML="Preparing to connect..."; + if (data.status=="idle" || data.status=="connecting") { + $("#status").innerHTML="Connecting..."; window.setTimeout(getStatus, 1000); - } else if (data.status=="success") { - $("#status").innerHTML="Connected! Got IP "+data.ip+". If you're in the same network, you can access it here."; - } else if (data.status=="working") { - $("#status").innerHTML="Trying to connect to selected access point..."; - window.setTimeout(getStatus, 1000); - } else if (data.status=="fail") { - $("#status").innerHTML="Connection failed. Check password and selected AP.
Go Back"; + } else if (data.status=="got IP address") { + $("#status").innerHTML="Connected! Got IP "+data.ip+ + ". If you're in the same network, you can access it here."; + } else { + $("#status").innerHTML="Oops: " + data.status + ". Reason: " + data.reason + + "
Check password and selected AP.
Go Back"; } } } @@ -28,7 +28,7 @@ function getStatus() { } window.onload=function(e) { - getStatus(); + window.setTimeout(getStatus, 2000); }; @@ -36,8 +36,8 @@ window.onload=function(e) {

ESP Link - Connecting

Connecting to AP...

-

Status:
-

...
+

Status: +...

diff --git a/serial/serbridge.c b/serial/serbridge.c index 8241c6b..12cc5a0 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -147,6 +147,12 @@ static void ICACHE_FLASH_ATTR serbridgeDisconCb(void *arg) { if (connData[i].conn != NULL && (connData[i].conn->state == ESPCONN_NONE || connData[i].conn->state == ESPCONN_CLOSE)) { + if (connData[i].conn_mode == cmAVR) { + // send reset to arduino/ARM + GPIO_OUTPUT_SET(MCU_RESET, 0); + os_delay_us(100L); + GPIO_OUTPUT_SET(MCU_RESET, 1); + } connData[i].conn = NULL; } } diff --git a/user/cgiwifi.c b/user/cgiwifi.c index f1d2fb8..c3fb80b 100644 --- a/user/cgiwifi.c +++ b/user/cgiwifi.c @@ -329,18 +329,16 @@ int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) { httpdHeader(connData, "Content-Type", "text/json"); httpdEndHeaders(connData); - len = os_sprintf(buff, "{\"status\": \""); - if (st > 0 && st < sizeof(connStatuses)) { - len += os_sprintf(buff+len, connStatuses[st]); - } else { - len += os_sprintf(buff+len, "unknown"); - } + len = os_sprintf(buff, "{\"status\": \"%s\"", + st > 0 && st < sizeof(connStatuses) ? connStatuses[st] : "unknown"); + if (wifiReason != 0) { - len += os_sprintf(buff+len, " -- %s", wifiGetReason()); + len += os_sprintf(buff+len, ", \"reason\": \"%s\"", wifiGetReason()); } + if (st == STATION_GOT_IP) { wifi_get_ip_info(0, &info); - len+=os_sprintf(buff+len, "\", \"ip\": \"%d.%d.%d.%d\" }\n", + len+=os_sprintf(buff+len, ", \"ip\": \"%d.%d.%d.%d\"", (info.ip.addr>>0)&0xff, (info.ip.addr>>8)&0xff, (info.ip.addr>>16)&0xff, (info.ip.addr>>24)&0xff); if (wifi_get_opmode() != 1) { @@ -349,10 +347,10 @@ int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) { os_timer_setfn(&resetTimer, resetTimerCb, NULL); os_timer_arm(&resetTimer, 1000, 0); } - } else { - len+=os_sprintf(buff+len, "\" }\n"); } + len+=os_sprintf(buff+len, "}\n"); + buff[len] = 0; os_printf(" -> %s\n", buff); httpdSend(connData, buff, len);