fix wifi connecting status update

pull/7/head
Thorsten von Eicken 10 years ago
parent 09cac0afc0
commit 1e0e8a4aaf
  1. 24
      html/wifi/connecting.html
  2. 6
      serial/serbridge.c
  3. 18
      user/cgiwifi.c

@ -11,16 +11,16 @@ function getStatus() {
xhr.onreadystatechange=function() { xhr.onreadystatechange=function() {
if (xhr.readyState==4 && xhr.status>=200 && xhr.status<300) { if (xhr.readyState==4 && xhr.status>=200 && xhr.status<300) {
var data=JSON.parse(xhr.responseText); var data=JSON.parse(xhr.responseText);
if (data.status=="idle") { if (data.status=="idle" || data.status=="connecting") {
$("#status").innerHTML="Preparing to connect..."; $("#status").innerHTML="Connecting...";
window.setTimeout(getStatus, 1000); window.setTimeout(getStatus, 1000);
} else if (data.status=="success") { } 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 <a href=\"http://"+data.ip+"/\">here</a>."; $("#status").innerHTML="Connected! Got IP "+data.ip+
} else if (data.status=="working") { ". If you're in the same network, you can access it <a href=\"http://"+data.ip+
$("#status").innerHTML="Trying to connect to selected access point..."; "/\">here</a>.";
window.setTimeout(getStatus, 1000); } else {
} else if (data.status=="fail") { $("#status").innerHTML="Oops: " + data.status + ". Reason: " + data.reason +
$("#status").innerHTML="Connection failed. Check password and selected AP.<br /><a href=\"wifi.tpl\">Go Back</a>"; "<br/>Check password and selected AP.<br/><a href=\"wifi.tpl\">Go Back</a>";
} }
} }
} }
@ -28,7 +28,7 @@ function getStatus() {
} }
window.onload=function(e) { window.onload=function(e) {
getStatus(); window.setTimeout(getStatus, 2000);
}; };
</script> </script>
</head> </head>
@ -36,8 +36,8 @@ window.onload=function(e) {
<div id="main"> <div id="main">
<h1>ESP Link - Connecting</h1> <h1>ESP Link - Connecting</h1>
<h2>Connecting to AP...</h2> <h2>Connecting to AP...</h2>
<p>Status:<br /> <p>Status:
<div id="status">...</div> <span id="status">...</span>
</p> </p>
</div> </div>
</body> </body>

@ -147,6 +147,12 @@ static void ICACHE_FLASH_ATTR serbridgeDisconCb(void *arg) {
if (connData[i].conn != NULL && if (connData[i].conn != NULL &&
(connData[i].conn->state == ESPCONN_NONE || connData[i].conn->state == ESPCONN_CLOSE)) (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; connData[i].conn = NULL;
} }
} }

@ -329,18 +329,16 @@ int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) {
httpdHeader(connData, "Content-Type", "text/json"); httpdHeader(connData, "Content-Type", "text/json");
httpdEndHeaders(connData); httpdEndHeaders(connData);
len = os_sprintf(buff, "{\"status\": \""); len = os_sprintf(buff, "{\"status\": \"%s\"",
if (st > 0 && st < sizeof(connStatuses)) { st > 0 && st < sizeof(connStatuses) ? connStatuses[st] : "unknown");
len += os_sprintf(buff+len, connStatuses[st]);
} else {
len += os_sprintf(buff+len, "unknown");
}
if (wifiReason != 0) { if (wifiReason != 0) {
len += os_sprintf(buff+len, " -- %s", wifiGetReason()); len += os_sprintf(buff+len, ", \"reason\": \"%s\"", wifiGetReason());
} }
if (st == STATION_GOT_IP) { if (st == STATION_GOT_IP) {
wifi_get_ip_info(0, &info); 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>>0)&0xff, (info.ip.addr>>8)&0xff,
(info.ip.addr>>16)&0xff, (info.ip.addr>>24)&0xff); (info.ip.addr>>16)&0xff, (info.ip.addr>>24)&0xff);
if (wifi_get_opmode() != 1) { if (wifi_get_opmode() != 1) {
@ -349,10 +347,10 @@ int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) {
os_timer_setfn(&resetTimer, resetTimerCb, NULL); os_timer_setfn(&resetTimer, resetTimerCb, NULL);
os_timer_arm(&resetTimer, 1000, 0); os_timer_arm(&resetTimer, 1000, 0);
} }
} else {
len+=os_sprintf(buff+len, "\" }\n");
} }
len+=os_sprintf(buff+len, "}\n");
buff[len] = 0; buff[len] = 0;
os_printf(" -> %s\n", buff); os_printf(" -> %s\n", buff);
httpdSend(connData, buff, len); httpdSend(connData, buff, len);

Loading…
Cancel
Save