Any concerns? support@freenove.com
42
43
44
45
46
47
48
49
50
51
52
}
if (Serial.available() > 0) {
delay(20);
String line = Serial.readString();
client.print(line);
}
if (client.connected () == 0) {
client.stop();
WiFi.disconnect();
}
}
Add WiFi function header file.
Enter the actual router name, password, remote server IP address, and port number.
const char *ssid_Router = "********"; //Enter the router name
const char *password_Router = "********"; //Enter the router password
#define REMOTE_IP "********" //input the remote server which is you want to connect
#define REMOTE_PORT 8888 //input the remote port which is the remote provide
Apply for the method class of WiFiClient.
Connect specified WiFi until it is successful. If the name and password of WiFi are correct but it still fails to
connect, please push the reset key.
WiFi.begin(ssid_Router, password_Router);
Serial.print("\nWaiting for WiFi... ");
while (WiFi.status() ! = WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Send connection request to remote server until connect successfully. When connect successfully, print out the
connecting prompt on the serial monitor and send messages to remote server.
while (!client.connect(REMOTE_IP, REMOTE_PORT)) {//Connect to Server
Serial.println("Connection failed.");
Serial.println("Waiting a moment before retrying...");
}
Serial.println("Connected");
client.print("Hello\n");
When ESP32-S3 receive messages from servers, it will print them out via serial port; Users can also send
messages to servers from serial port.
if (client.available() > 0) {
delay(20);
//read back one line from the server
String line = client.readString();
Serial.println(REMOTE_IP + String(":") + line);
}