esp32AP getrequest
Posted: Tue Jun 11, 2019 9:15 am
I started a project that requires communication between esp32 as an AP and pc client. I send the HTML code but there is no idea to receive an answer .looking for any clue or example to receive a data and can see it in the serial monitor.
it's my HTML code
iwant to save ssid ,pass in esp32
it's my HTML code
- const char *ssid = "MyESP";
- const char HTML[] PROGMEM = "<script language=\"JavaScript\">function formToJson(form){var pass=form.pass.value;var ssid=form.ssid.value;var jsonFormInfo=JSON.stringify({pass:pass, ssid: ssid});window.alert('OK');}</script> <form onSubmit=\"event.preventDefault(); formToJson(this);\"> <label class=\"label\">Network Name</label> <input type=\"text\" name=\"ssid\"/> <label>Password</label> <input type=\"text\" name=\pass/> <input type=\"submit\" value=\"Submit\"></form>";
- AsyncWebServer server(80);
- void setup() {
- Serial.begin(115200);
- WiFi.softAP(ssid);
- Serial.println();
- Serial.print("IP address: ");
- Serial.println(WiFi.softAPIP());
- server.on("/Cfig", HTTP_GET, [](AsyncWebServerRequest *request) {
- request->send(200, "text/html", HTML);});
- server.begin();
- HTTPClient http;
- http.begin("http://192.168.1.87");
- http.addHeader("Content-Type", "text/plain");
- int httpResponseCode = http.POST("POSTING from ESP32");
- if (httpResponseCode > 0) {
- String response = http.getString();
- Serial.println(httpResponse);
- Serial.println(response); }
- else {Serial.print("Error on sending POST: ");
- Serial.println(httpResponse);}
- http.end();}