Hello.
I am porting a PC application to communicate my Core as TCPServer with one TCPClient. I use on the PC original software a blocking function to receive data -I know the client is sending data constantly- and I have tried to port it to my core using
int receiveData(int len, unsigned char *buffer)
{
int tam = 0;
Serial.println("Waiting to read");
while(!app.available());
Serial.println("Have data");
while(app.available() && (tam < len))
buffer[tam++] = app.read();
Serial.println("Data read");
return tam;
}
where app is the TCPClient that I guarantee to be conected, and the prints are for debugging reasons.
The funcion hangs at random in the while(!app.available()); although I force the client to send data. When testing the same client against my PC server, everything works ok. I know I could implement a non-blocking receive function, and it may solve the problem, but my question is whether is it dangerous -or plainly wrong- to place such a while loop inside the loop() function. That is, if the firmware needs the loop function to end to perform its housekeeping tasks.
Thank you very much for your help.
Regards,
Germán