Skip to content

Commit

Permalink
fix wifi connecting status update
Browse files Browse the repository at this point in the history
  • Loading branch information
tve committed May 24, 2015
1 parent 09cac0a commit 1e0e8a4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
24 changes: 12 additions & 12 deletions html/wifi/connecting.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@
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>";
}
}
}
xhr.send();
}

window.onload=function(e) {
getStatus();
window.setTimeout(getStatus, 2000);
};
</script>
</head>
<body>
<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>
Expand Down
6 changes: 6 additions & 0 deletions serial/serbridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
18 changes: 8 additions & 10 deletions user/cgiwifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 1e0e8a4

Please sign in to comment.