I need help about getting data from webpage. I set ESP8266 as AP and I set a webpage which has two input box and a button. User should write network ID and password to these input boxes and i need to get these ID and password then set ESP8266 as STA. I searched a lot and I find substring() to get data from these boxes. I don't know if I did it right but I get datas but not exactly right! If user writes abcenser to ID I get it as abconser or something like that i mean i can't get data right. Password is like that too sometimes it takes all characters but one or two charecters are wrong sometimes can't get all characters just a part of it.. It changes everytime i don't know what should i do so i really need help.. If there is any way other than using substring() that's okay too
The code I use
#include "String.h"
#include "uartWIFI.h"
#define SSID "esp_mod_01"
#define PASSWORD "esp_sifre_01"
String ssid;
String pass;
String readString;
String Getdata;
WIFI wifi;
extern int chlID;
int webtype;
void setup(){
wifi.begin(); //AT+RST ile modul kontrolü
DebugSerial.println("AP modu aciliyor");
setupAP();
}
void setupAP(){
bool b = wifi.Initialize(AP, SSID, PASSWORD, 3 ,0);
if(!b){
DebugSerial.println("Init error");
}
else{
DebugSerial.println("Init OK!");
}
delay(3000);
String ipstring = wifi.showIP();
DebugSerial.println(ipstring);
wifi.confMux(1);
bool c = wifi.confServer(1,80);
if(!c){
DebugSerial.println("SERVER error!");
}
else{
DebugSerial.println("SERVER OK!");
webtype = 1;
}
}
void loop()
{
if (webtype == 1){
setupAPmode();
}
}
void setupAPmode(){
if(_cell.find("+IPD")){
delay(1000);
String cmd;
cmd = "HTTP/1.1 200 OK\r\n";
cmd += "Content-Type: text/html\r\n";
cmd += "Connection: close\r\n";
cmd += "\r\n";
cmd += "<!DOCTYPE HTML>\r\n";
cmd += "<html>\r\n";
cmd += "<form method=get>";
cmd += "<label>SSID</label>
";
cmd += "<input type='text' name='ssid' maxlength='30' size='15'>
";
cmd += "<label>Password</label>
";
cmd += "<input type='password' name='password' maxlength='30' size='15'>
";
cmd += "<input type='submit' value='connect' >";
cmd += "</form>";
cmd += "<html>\r\n";
wifi.Send(chlID,cmd);
wifi.closeMux(chlID);
if(_cell.available()){
Getdata = _cell.readString();
int _referans = Getdata.indexOf("ssid");
int _ssid_num = Getdata.indexOf('=',_referans+1);
int _belirleyici = Getdata.indexOf('&');
int _pass_num = Getdata.indexOf('=',_belirleyici+1);
int _belirleyici2= Getdata.indexOf(' ',_pass_num+1);
String _ssid = Getdata.substring(_ssid_num+1,_belirleyici);
Serial.print("ssid = ");
Serial.println(_ssid);
String _pass = Getdata.substring(_pass_num+1, _belirleyici2);
Serial.print("pass = ");
Serial.println(_pass);
if(_ssid.length()>5 && _pass.length()>5)
webtype=0;
}
}
delay(1000);
}