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) sleep $(ESPDELAY)
$(Q) $(ESPTOOL) -cp $(ESPPORT) -cb $(ESPBAUD) -ca 0x40000 -cf firmware/0x40000.bin -v $(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 .. cd html; find | ../mkespfsimage/mkespfsimage > ../webpages.espfs; cd ..
mkespfsimage/mkespfsimage: mkespfsimage/ mkespfsimage/mkespfsimage: mkespfsimage/

@ -65,6 +65,9 @@ window.onload=function(e) {
<p> <p>
Current WiFi mode: %WiFiMode% Current WiFi mode: %WiFiMode%
</p> </p>
<p>
Note: %WiFiapwarn%
</p>
<form name="wifiform" action="connect.cgi" method="post"> <form name="wifiform" action="connect.cgi" method="post">
<p> <p>
To connect to a WiFi network, please select one of the detected networks...<br> 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 //Schedule disconnect/connect
os_timer_disarm(&reassTimer); os_timer_disarm(&reassTimer);
os_timer_setfn(&reassTimer, reassTimerCb, NULL); 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); os_timer_arm(&reassTimer, 1000, 0);
httpdRedirect(connData, "connecting.html"); httpdRedirect(connData, "connecting.html");
@ -220,6 +221,27 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
return HTTPD_CGI_DONE; 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. //Template code for the WLAN page.
void ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg) { void ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg) {
char buff[1024]; char buff[1024];
@ -238,6 +260,13 @@ void ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg)
os_strcpy(buff, (char*)stconf.ssid); os_strcpy(buff, (char*)stconf.ssid);
} else if (os_strcmp(token, "WiFiPasswd")==0) { } else if (os_strcmp(token, "WiFiPasswd")==0) {
os_strcpy(buff, (char*)stconf.password); 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)); 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); void tplWlan(HttpdConnData *connData, char *token, void **arg);
int cgiWiFi(HttpdConnData *connData); int cgiWiFi(HttpdConnData *connData);
int cgiWiFiConnect(HttpdConnData *connData); int cgiWiFiConnect(HttpdConnData *connData);
int cgiWifiSetMode(HttpdConnData *connData);
#endif #endif

@ -32,7 +32,9 @@ HttpdBuiltInUrl builtInUrls[]={
{"/wifi/", cgiRedirect, "/wifi/wifi.tpl"}, {"/wifi/", cgiRedirect, "/wifi/wifi.tpl"},
{"/wifi/wifiscan.cgi", cgiWiFiScan, NULL}, {"/wifi/wifiscan.cgi", cgiWiFiScan, NULL},
{"/wifi/wifi.tpl", cgiEspFsTemplate, tplWlan}, {"/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 {"*", cgiEspFsHook, NULL}, //Catch-all cgi function for the filesystem
{NULL, NULL, NULL} {NULL, NULL, NULL}

Loading…
Cancel
Save