Skip to content

WifiServer - Connection reset #119

Closed
@Dennis650

Description

@Dennis650

Hi,

i wanted to implement a WifiServer on the ESP32 with Arduino. I tried different examples from ESP8266, but i didn't get it working.

I updated the latest Version of Arduino for ESP32 from github today.

I setup the ESP32 as AccessPoint and startet the WifiServer. I can connect and send a request. The ESP32 sends the response, but then resets the connection, according to curl. So InternetBrowsers and curl are showing me errors.

Can you please have a look what I have done wrong? Or is this a bug?

Error with curl:

curl http://192.168.4.1
<!DOCTYPE HTML>
<html><h1><Hello World!</h1></html>
curl: (56) Recv failure: Connection reset by peer

Here is my Sketch:

#include <WiFi.h>

const char* WIFI_SSID = "ESP-Accesspoint";
const char* WIFI_PASSWORD = "geheimPasswort";
WiFiServer server(80);

void setup(void) {
	Serial.begin(115200);

	WiFi.mode(WIFI_AP);
	WiFi.softAP(WIFI_SSID, WIFI_PASSWORD);

	server.begin();
}

void loop(void) {

	// Check if a client has connected
	WiFiClient client = server.available();
	if (!client) {
		return;
	}

	// Wait until the client sends some data
	Serial.println("New client");
	delay(1);

	// Read the first line of the request
	String request = client.readStringUntil('\r');
	Serial.print("Request: ");
	Serial.println(request);

	client.flush();

	String s = "HTTP/1.1 200 OK\r\n";
	s += "Content-Type: text/html\r\n\r\n";
	s += "<!DOCTYPE HTML>\r\n";
	s += "<html><h1><Hello World!</h1></html>\r\n";

	Serial.println("Response:");
	Serial.println(s);
	client.println(s);
	client.flush();

	delay(1);
	Serial.println("Client disonnected"); //When method ends
}

Thanks in advance and Greetings
Dennis

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions