Speeding Up WiFi Client Prints on ESP32-S3
Posted: Tue Jul 02, 2024 2:53 pm
Hello,
I am using an esp32-s3 to do analog reads and send the data over WiFi to my laptop. When I read 4 sensors, I get a frequency > 1kHz, but with 6 sensors it drops below 1kHz.
What is slowing it down and how to fix it?
Thank you
Here is my esp32 code:
And here is the python code running on PC:
I am using an esp32-s3 to do analog reads and send the data over WiFi to my laptop. When I read 4 sensors, I get a frequency > 1kHz, but with 6 sensors it drops below 1kHz.
What is slowing it down and how to fix it?
Thank you
Here is my esp32 code:
Code: Select all
#include <WiFi.h>
// Replace with your network credentials
const char* ssid = "AndroidAP";
const char* password = "kesy1320";
WiFiServer server(80);
unsigned long start = 0;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Print the IP address
Serial.print("ESP32 IP Address: ");
Serial.println(WiFi.localIP());
server.begin();
}
void loop() {
WiFiClient client = server.available(); // Listen for incoming clients
if (client) {
while (client.connected()) {
// Send data at 1 kHz (1000 times per second)
start = micros();
client.println((String) start + " " + analogRead(14) + " " + analogRead(13) + " " + analogRead(12) + " " + analogRead(11) + " " + analogRead(10) + " " + analogRead(9));
/*while (micros() - start < 625) {
// wait for the next 1 ms
}*/
}
client.stop();
Serial.println("Client disconnected");
}
}
Code: Select all
import socket
import time
# Replace with your ESP32's IP address
ESP32_IP = '192.168.225.242'
ESP32_PORT = 80
def main():
# Create a socket object
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect to the ESP32 server
client_socket.connect((ESP32_IP, ESP32_PORT))
print("Connected to ESP32")
try:
with open("received_data.log", "w") as log_file:
while True:
data = client_socket.recv(1024).decode() # Receive data from ESP32
if data:
log_file.write(f"{data.strip()}\n")
log_file.flush() # Ensure data is written to the file immediately
except KeyboardInterrupt:
print("Interrupted")
except Exception as e:
print(f"Error: {e}")
finally:
client_socket.close()
print("Connection closed")
if __name__ == "__main__":
main()