Code I am using:
Code: Select all
// code examples from espressif ESP32 examples on github
#include <WiFi.h>
const char* ssid = "myAPssid";
const char* password = "myAPpassword";
WiFiServer server(7777);
void setup()
{
Serial.begin(115200);
pinMode(5, OUTPUT); // set the LED pin mode
delay(10);
// We start by connecting to a WiFi network
Serial.print("Connecting to \""); Serial.print(ssid); Serial.println("\"");
WiFi.disconnect(true); // delete old config
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.print("IP address: "); Serial.println(WiFi.localIP());
server.begin();
server.setNoDelay(true); //reduces latency in connection at the expense of some packet loss? tried with and without (not much change)
Serial.println("waiting for client to connect...");
}
int value = 0; // what is this used for? was in the example
void loop(){
WiFiClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
// Serial.print("New client: "); // print a message out the serial port
// Serial.println(client.remoteIP());
String currentLine = ""; // make a String to hold incoming data from the client
// unsigned long startTime = millis(); // for timing connection length
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
if (c == '\n') { // if the byte is a newline character
// after any data from client is taken care of, send some data to the client
client.println("msg from server12345"); // send 20 bytes and remote on Windows echoes it back
// break out of the while loop:
break;
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
} // end loop: while client is connected
// close the connection:
client.stop();
delay(5);
// Serial.println("\nClient Disconnected.");
// currentLine = String("Elapsed time = ") + (millis() - startTime) + "ms";
// Serial.println(currentLine);
}
}
Thank you for any suggestions!