I have two ESPs that exchnage information - one is the server that is providing a string with sensorvalues and the othe receives that.
Every 10 seconds the client gets the new data from the server and it takes approx 1,5 seconds. Is there a chance to make that faster or make asynchronous? Or any other idea that is faster?
few things you could do here..
first think async on the client..
break this getData into 3 routines..
connect..
send request..
check response..
no waiting, no delays..
might want to use a global client and keep it connected, connecting all by itself eats up time..
or completely rethink things..
instead of querying the server, have the server broadcast the data every 10 seconds..
lose the http,tcp and go udp..
no strings either they will end up fragging your memory..
send the data raw in structures..
good idea - will try that.
I already put in some Serial print statement to the code and the long waiting time is, when the receiver gets the data with 38 bytes. Need to check that more into detail.
Udp is also a possibility and I wil try it.
What do you think about POST method. lient wil post the data to the server. Server is async, so should be no more timing problem then
all the relevant code for that topic was posted in my first message of this topic.
In the meantime I found and solved the problem.
In the code of the recieving ESP32 I inserted some Serial.println("...") to find out where exactly is the delay. It was not in the start of the connection nor when exchanging some header information. But it took 1 sec to get the data string from the server.
Then I inserted a CR or /r at the end of the string, that the server is sending out and now the lag when receiving data is around 50-150 ms and that´s OK.
the change in the code on the server side: (on the client side everything stays as it was)
char end = 13; // ASCII Code for Carriage Return
String transfer2 = "";
transfer2 += "z|" + String(feuchteEG, 0) + "|" + String(tempEG, 1) + "|" + String(measuredValue, 1) + "|";
transfer2 += String(measuredValue2, 1) + "|" + String(measuredValue3,1) +"|" + String(measuredValue,1) + "|";
transfer2 += "26.5|" + String(WiFi.RSSI()) + "|" + end; // string transfer has to be terminated with CR