How can I parse this string GET /STA/ID=HelloWorld/Pass=Testin123 HTTP/1.1
First I need to check for STA, if it exists, continue to scan the string. Put Value of ID in this case HelloWorld should be store in String data type SSID and Value of Pass, in this case Testin123 should be store in String data type Pass.
It should confirm the presence of STA in string first. If it is not present, do not enter into loop. If it exits, search for ID and Pass. Store it.
The code I used, seems to be not working. It doesn't enter into loop, because it can't search for STA, and even if it does, it does not search for ID and Pass
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
char GetString[100];
String SSID;
String Pass;
String s = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 0\r\n\r\n";
WiFiServer server(80); //Initialize the server on Port 80
void setup()
{
Serial.begin(115200); //Start communication between the ESP8266-12E and the monitor window
WiFi.mode(WIFI_AP); //Our ESP8266-12E is an AccessPoint
WiFi.softAP("Hello_IoT", "12345678"); // Provide the (SSID, password); .
server.begin(); // Start the HTTP Server
IPAddress HTTPS_ServerIP = WiFi.softAPIP(); // Obtain the IP of the Server
Serial.print("\n");
Serial.print("Server IP is: "); // Print the IP to the monitor window
Serial.println(HTTPS_ServerIP);
}
void loop()
{
WiFiClient client = server.available();
if (!client) {
return;
}
//Looking under the hood
Serial.println("Somebody has connected :)");
String incoming = client.readStringUntil('\r');
Serial.println(incoming);
incoming.toCharArray(GetString, 100);
char *get = strtok(GetString, " ");
char *request = strtok(NULL, " ");
char *rtype = strtok(NULL, " ");
Serial.print("\n");
Serial.print("GetString :");
Serial.println(GetString);
Serial.print("\n");
Serial.print("Request :");
Serial.println(request);
Serial.print("\n");
Serial.print("Rtype :");
Serial.println(rtype);
if (request != NULL)
{
char *part = strtok(request, "/");
while (part)
{
if (!strcmp(part, "STA"))
{
if (!strncmp(part, "ID=", 3))
{ // We have the ID
SSID = String(part + 3);
Serial.print("\n");
Serial.print("SSID: ");
Serial.print(SSID);
}
if (!strncmp(part, "Pass=", 5))
{ // We have the password
Pass = String(part + 5);
Serial.print("\n");
Serial.print("PWD: ");
Serial.print(Pass);
}
}
else
{
Serial.print("\n");
Serial.print("Not Found");
}
part = strtok(NULL, "/");
}
}
}