updated configure()

This commit is contained in:
Gregg 2020-09-04 22:19:14 -05:00
parent de897557eb
commit af3c093cdc
3 changed files with 36 additions and 5 deletions

View File

@ -18,10 +18,15 @@ void Configure::processRequest(WiFiClient &client, char *body, char *formData){
LOG1("In Post Configure...\n"); LOG1("In Post Configure...\n");
getFormValue(formData,"network",wifiData.ssid,MAX_SSID);
getFormValue(formData,"pwd",wifiData.pwd,MAX_PWD);
getFormValue(formData,"code",setupCode,8);
timer=millis();
WiFi.begin(wifiData.ssid,wifiData.pwd);
responseBody+="<meta http-equiv = \"refresh\" content = \"2; url = /wifi-status\" />" responseBody+="<meta http-equiv = \"refresh\" content = \"5; url = /wifi-status\" />"
"<p>Initiating WiFi Connection...</p>"; "<p>Initiating WiFi connection to:</p><p>" + String(wifiData.ssid) + "</p>";
} else } else
@ -29,8 +34,12 @@ void Configure::processRequest(WiFiClient &client, char *body, char *formData){
LOG1("In Get WiFi Status...\n"); LOG1("In Get WiFi Status...\n");
if(WiFi.status()!=WL_CONNECTED){
responseHead+="Refresh: 5\r\n"; responseHead+="Refresh: 5\r\n";
responseBody+="<p>Trying to Connect (" + String(millis()/1000) + "sec)...</p>"; responseBody+="<p>Re-trying (" + String((millis()-timer)/1000) + "sec) connection to:</p><p>" + String(wifiData.ssid) + "</p>";
} else {
responseBody+="<p>SUCCESS! Connected to:</p><p>" + String(wifiData.ssid) + "</p>";
}
} else { // LOGIN PAGE } else { // LOGIN PAGE
@ -87,6 +96,27 @@ void Configure::processRequest(WiFiClient &client, char *body, char *formData){
int Configure::getFormValue(char *formData, char *tag, char *value, int maxSize){ int Configure::getFormValue(char *formData, char *tag, char *value, int maxSize){
char *s=strstr(formData,tag); // find start of tag
if(!s) // if not found, return -1
return(-1);
char *v=index(s,'='); // find '='
if(!v) // if not found, return -1 (this should not happen)
return(-1);
v++; // point to begining of value
int len=0; // track length of value
while(*v!='\0' && *v!='&' && len<maxSize){ // copy the value until null, '&', or maxSize is reached
len++;
*value++=*v++;
}
*value='\0'; // add terminating null
return(len);
} }
////////////////////////////////////// //////////////////////////////////////

View File

@ -12,6 +12,7 @@ struct Configure {
} wifiData; } wifiData;
char setupCode[9]; char setupCode[9];
unsigned long timer; // time of trying to connect to WiFi
void processRequest(WiFiClient &client, char *body, char *formData); void processRequest(WiFiClient &client, char *body, char *formData);
int getFormValue(char *formData, char *tag, char *value, int maxSize); int getFormValue(char *formData, char *tag, char *value, int maxSize);

View File

@ -346,7 +346,7 @@ void Span::configure(char *apName){
IPAddress apIP(192, 168, 4, 1); IPAddress apIP(192, 168, 4, 1);
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);
WiFi.softAP(apName,"homespan"); WiFi.softAP(apName,"homespan",1,false,1);
dnsServer.start(DNS_PORT, "*", apIP); dnsServer.start(DNS_PORT, "*", apIP);
apServer.begin(); apServer.begin();