esp32AP getrequest

mehrdadco
Posts: 8
Joined: Tue Jun 11, 2019 8:53 am

esp32AP getrequest

Postby mehrdadco » 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
  1. const char *ssid = "MyESP";
  2. 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>";
  3.  
  4. AsyncWebServer server(80);
  5. void setup() {
  6.     Serial.begin(115200);
  7.     WiFi.softAP(ssid); 
  8.     Serial.println();
  9.     Serial.print("IP address: ");
  10.     Serial.println(WiFi.softAPIP());
  11.     server.on("/Cfig", HTTP_GET, [](AsyncWebServerRequest *request) {
  12.         request->send(200, "text/html", HTML);});
  13.     server.begin();
  14.     HTTPClient http;
  15.     http.begin("http://192.168.1.87");  
  16.     http.addHeader("Content-Type", "text/plain");      
  17.     int httpResponseCode = http.POST("POSTING from ESP32");
  18.     if (httpResponseCode > 0) {
  19.         String response = http.getString();                      
  20.         Serial.println(httpResponse);  
  21.         Serial.println(response);      }
  22.     else {Serial.print("Error on sending POST: ");
  23.         Serial.println(httpResponse);}
  24.     http.end();}
iwant to save ssid ,pass in esp32
Last edited by mehrdadco on Tue Jun 11, 2019 2:02 pm, edited 2 times in total.

ESP_Sprite
Posts: 9762
Joined: Thu Nov 26, 2015 4:08 am

Re: esp32AP getrequest

Postby ESP_Sprite » Tue Jun 11, 2019 9:16 am

Moved to Arduino, as it seems to be for the webserver for that platform.

Who is online

Users browsing this forum: No registered users and 38 guests