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() {
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 <a href=\"http://"+data.ip+"/\">here</a>.";
} 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.<br /><a href=\"wifi.tpl\">Go Back</a>";
} 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>.";
} else {
$("#status").innerHTML="Oops: " + data.status + ". Reason: " + data.reason +
"<br/>Check password and selected AP.<br/><a href=\"wifi.tpl\">Go Back</a>";
}
}
}
@ -28,7 +28,7 @@ function getStatus() {
}
window.onload=function(e) {
getStatus();
window.setTimeout(getStatus, 2000);
};
</script>
</head>
@ -36,8 +36,8 @@ window.onload=function(e) {
<div id="main">
<h1>ESP Link - Connecting</h1>
<h2>Connecting to AP...</h2>
<p>Status:<br />
<div id="status">...</div>
<p>Status:
<span id="status">...</span>
</p>
</div>
</body>

@ -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;
}
}

@ -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);

Loading…
Cancel
Save