Added warning about scanning not working in AP mode, possibility to switch modes.

pull/30/head
Jeroen Domburg 10 years ago
parent eda66688d0
commit f1d80059d6
  1. 2
      Makefile
  2. 3
      html/wifi/wifi.tpl
  3. 31
      user/cgiwifi.c
  4. 1
      user/cgiwifi.h
  5. 4
      user/user_main.c

@ -147,7 +147,7 @@ flash: $(FW_FILE_1) $(FW_FILE_2)
$(Q) sleep $(ESPDELAY)
$(Q) $(ESPTOOL) -cp $(ESPPORT) -cb $(ESPBAUD) -ca 0x40000 -cf firmware/0x40000.bin -v
webpages.espfs: html/ mkespfsimage/mkespfsimage
webpages.espfs: html/ html/wifi/ mkespfsimage/mkespfsimage
cd html; find | ../mkespfsimage/mkespfsimage > ../webpages.espfs; cd ..
mkespfsimage/mkespfsimage: mkespfsimage/

@ -65,6 +65,9 @@ window.onload=function(e) {
<p>
Current WiFi mode: %WiFiMode%
</p>
<p>
Note: %WiFiapwarn%
</p>
<form name="wifiform" action="connect.cgi" method="post">
<p>
To connect to a WiFi network, please select one of the detected networks...<br>

@ -210,7 +210,8 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
//Schedule disconnect/connect
os_timer_disarm(&reassTimer);
os_timer_setfn(&reassTimer, reassTimerCb, NULL);
#if 1 //Set to 0 if you want to disable the actual reconnecting bit
//Set to 0 if you want to disable the actual reconnecting bit
#if 1
os_timer_arm(&reassTimer, 1000, 0);
httpdRedirect(connData, "connecting.html");
@ -220,6 +221,27 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
return HTTPD_CGI_DONE;
}
//This cgi uses the routines above to connect to a specific access point with the
//given ESSID using the given password.
int ICACHE_FLASH_ATTR cgiWifiSetMode(HttpdConnData *connData) {
int len;
char buff[1024];
if (connData->conn==NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}
len=httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff));
if (len!=0) {
os_printf("cgiWifiSetMode: %s\n", buff);
wifi_set_opmode(atoi(buff));
system_restart();
}
httpdRedirect(connData, "/wifi");
return HTTPD_CGI_DONE;
}
//Template code for the WLAN page.
void ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg) {
char buff[1024];
@ -238,6 +260,13 @@ void ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg)
os_strcpy(buff, (char*)stconf.ssid);
} else if (os_strcmp(token, "WiFiPasswd")==0) {
os_strcpy(buff, (char*)stconf.password);
} else if (os_strcmp(token, "WiFiapwarn")==0) {
x=wifi_get_opmode();
if (x==2) {
os_strcpy(buff, "<b>Can't scan in this mode.</b> Click <a href=\"setmode.cgi?mode=3\">here</a> to go to STA+AP mode.");
} else {
os_strcpy(buff, "Click <a href=\"setmode.cgi?mode=2\">here</a> to go to standalone AP mode.");
}
}
espconn_sent(connData->conn, (uint8 *)buff, os_strlen(buff));
}

@ -7,5 +7,6 @@ int cgiWiFiScan(HttpdConnData *connData);
void tplWlan(HttpdConnData *connData, char *token, void **arg);
int cgiWiFi(HttpdConnData *connData);
int cgiWiFiConnect(HttpdConnData *connData);
int cgiWifiSetMode(HttpdConnData *connData);
#endif

@ -32,7 +32,9 @@ HttpdBuiltInUrl builtInUrls[]={
{"/wifi/", cgiRedirect, "/wifi/wifi.tpl"},
{"/wifi/wifiscan.cgi", cgiWiFiScan, NULL},
{"/wifi/wifi.tpl", cgiEspFsTemplate, tplWlan},
{"/wifi/connect.cgi", cgiWiFiConnect},
{"/wifi/connect.cgi", cgiWiFiConnect, NULL},
{"/wifi/setmode.cgi", cgiWifiSetMode, NULL},
{"*", cgiEspFsHook, NULL}, //Catch-all cgi function for the filesystem
{NULL, NULL, NULL}

Loading…
Cancel
Save