Code is below:
if (esp8266.available()) // check if the esp is sending a message
{
if (esp8266.find("+IPD,"))
{
delay(1000);
int connectionId = esp8266.read() - 48;
Serial.println(connectionId);
String sip_keyword = "sid=";
String ssid_keyword = "id=";
String pw_keyword = "pw=";
char* sip_buffer = (char*) malloc(sizeof(char) * sip_keyword.length() + 1);
char* ssid_buffer = (char*) malloc(sizeof(char) * ssid_keyword.length() + 1);
char* pw_buffer = (char*) malloc(sizeof(char) * pw_keyword.length() + 1);
sip_keyword.toCharArray(sip_buffer, sip_keyword.length() + 1);
ssid_keyword.toCharArray(ssid_buffer, ssid_keyword.length() + 1);
pw_keyword.toCharArray(pw_buffer, pw_keyword.length() + 1);
SERVER_IP = findDataFromESP8266(sip_buffer);
WIFI_SSID = findDataFromESP8266(ssid_buffer);
WIFI_PASSWORD = findDataFromESP8266(pw_buffer);
}
}
String findDataFromESP8266(char* keyword) {
String data = "";
int tempASCII = 0;
char tempChar = 0;
boolean check = (tempASCII != 38 && tempASCII != -1 && tempASCII != 32);
//advance to find wanted keyword.
if (esp8266.find(keyword) > -1) {
tempASCII = esp8266.read();
if (check) {
while (check) {
tempChar = tempASCII;
data += tempChar;
tempASCII = esp8266.read(); //iterate
check = (tempASCII != 38 && tempASCII != -1 && tempASCII != 32);
}
} else {
Serial.println(F("SSID empty"));
}
Serial.print(F("Data found with keyword "));
Serial.print(keyword);
Serial.print(F(": "));
Serial.println(data);
delay(200);
}