Problem with TCP/IP communication

Hello guys!

I have a problem, the code below simulate an aquisition of a waveform by a TCP/IP Server, then the results have to be send to a client.

#include <chipKITEthernet.h>
#include <SPI.h>

byte MAC[]= {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
byte IP[]= {192,168,1,3};
Server server (1369);


boolean refresh = LOW;
const float pi = 3.1415;
float t=0, V1[999];

Client client;

void setup()
{
  Ethernet.begin(MAC, IP);
  server.begin();
  Serial.begin(9600);
  delay(1000);
}

void loop()
{
  client = server.available();
  if(client.available())
  {
    Serial.println("Reading client");
    Serial.println(" ");
    char c = client.read();
    Serial.print(c);
    if(c==1)
    {
      refresh = HIGH;
    }
  }
    
  if(client.connected() && refresh)
  {
    refresh = LOW;
    Serial.println("Conectado ao servidor, inciando o envio de dados");
    Serial.println(" ");
    aquisition();    
  }
  Ethernet.PeriodicTasks();
}

void aquisition()
{
  for(int j=0;j<1000;j++)
    {
      V1[j] = 10*sin(2*pi*60*t) + 0.5*sin(3*2*pi*60*t) + 0.7*sin(5*2*pi*60*t) + 1.2*sin(7*2*pi*60*t);
      t = t + 0.0002;
    }
    Serial.println("ADC simulation done, sending data");
    Serial.println(" ");
    
    for(int j=0;j<1000;j++)
    {
      client.println(V1[j]);
    }
    Serial.println("Aquisition done");
    Serial.println(" ");
}

I can only do the routine 3-4 times at the most, then the code is stopped here:

for(int j=0;j<1000;j++)
    {
      client.println(V1[j]); // <--- the code stops here after 3-4 times
    }

I tried almost everything possible, but I can’t figure out what’s going on.

Anything?

Best regards!!!

How many bytes are you transferring this way? Bear in mind that each call to client.println() generates another packet.

for(int j=0;j<1000;j++)
{
   client.println(V1[j]); // <--- the code stops here after 3-4 times
}

Do you want to know? That is 1000 packets for a total of 51,000 bytes. Three characters per packet, and a 48 byte header for each packet. That is a 3000 byte payload carried by 48,000 bytes in the headers.

I recommend sending at least 60 bytes per packet.

Thanks for the answer!

I don't think that the problem the is size of the packts, beacause I already did the code transmit four times 6 waveforms of (1000 samples each). Thats why I don't know what's the problem.
The data that I transmit in client.println is a FLOAT.

Thanks again!

I think you need to rethink that. A thousand packets is too many. You can keep trying other things tho.

But I don't understand, because I send the data and read in the client application, then a new cicle begins, why it can't do the routine again if it did once, twice or three times?

Thanks for helping me!

use client.flush() after you are done with println(). It worked for me.