Hi Guys,
I have established the AP (access point) on my esp32 so that i can make a GET request to my PC (connected to AP) and receive the payload. The issue is, the connection only run once and doesn't run again and I have to restart the esp32 or the localhost URL (on my PC) to initiate the connection again.
Can someone help me with the issue?
Is there something that i have to do from the client end (PC)
WiFiServer server1(80);
HTTPClient http;
String seerverini = "http://";
String serverName = ":5000/RRP/";
void setup() {
/*
* initialise the Serial output, the Network connection, the MQTT client
* and specify input/output pins.
*/
// begin the serial monitor.
// Set console and Sim baud rate
SerialMon.begin(115200);
delay(1000);
SerialAT.begin(115200, SERIAL_8N1, 26, 27);
delay(6000);
// You can remove the password parameter if you want the AP to be open.
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
SerialMon.print("AP IP address: ");
SerialMon.println(myIP);
void HTTP() {
server1.begin();
SerialMon.println("Server started");
delay(1000);
WiFiClient client = server1.available(); // listen for incoming clients
SerialMon.println("Client available");
if (client) { // if you get a client,
SerialMon.println("assigned IP address: ");
String Client_Server = client.remoteIP().toString();
//String Client_Server = "192.168.4.2";
while (client.connected()) { // loop while the client's connected
if (client.available()) {
SerialMon.println(Client_Server);
SerialMon.println("establishing API connection");
String serverPath = seerverini+Client_Server+serverName;
Serial.println(serverPath);
http.begin(serverPath.c_str());
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
http.end();
client.stop();
SerialMon.println("Client Disconnected.");
server1.stop();
delay(1000);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
http.end();
client.stop();
server1.stop();
delay(1000);
SerialMon.println("Client Disconnected.");
}
}