From af3c093cdc0e9730445e218605a3788f924a9f40 Mon Sep 17 00:00:00 2001 From: Gregg Date: Fri, 4 Sep 2020 22:19:14 -0500 Subject: [PATCH] updated configure() --- src/Configure.cpp | 38 ++++++++++++++++++++++++++++++++++---- src/Configure.h | 1 + src/HomeSpan.cpp | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/Configure.cpp b/src/Configure.cpp index 9174431..afdff99 100644 --- a/src/Configure.cpp +++ b/src/Configure.cpp @@ -18,10 +18,15 @@ void Configure::processRequest(WiFiClient &client, char *body, char *formData){ 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+="" - "

Initiating WiFi Connection...

"; + responseBody+="" + "

Initiating WiFi connection to:

" + String(wifiData.ssid) + "

"; } else @@ -29,8 +34,12 @@ void Configure::processRequest(WiFiClient &client, char *body, char *formData){ LOG1("In Get WiFi Status...\n"); - responseHead+="Refresh: 5\r\n"; - responseBody+="

Trying to Connect (" + String(millis()/1000) + "sec)...

"; + if(WiFi.status()!=WL_CONNECTED){ + responseHead+="Refresh: 5\r\n"; + responseBody+="

Re-trying (" + String((millis()-timer)/1000) + "sec) connection to:

" + String(wifiData.ssid) + "

"; + } else { + responseBody+="

SUCCESS! Connected to:

" + String(wifiData.ssid) + "

"; + } } else { // LOGIN PAGE @@ -86,6 +95,27 @@ void Configure::processRequest(WiFiClient &client, char *body, char *formData){ ////////////////////////////////////// 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