Go Down

Topic: Recieve Serial and send out TCP IP (Read 1 time) previous topic - next topic


I have a Sparkfun Pro Ethernet. I have a computer that prints reports for a manufacturing process, each report is about 2000 bytes of text. I have set up Ethernet pro usb as a generic text printer in windows, and the pc prints the report and arduino catches it and sends it over TCP/IP to a Server.  Below is the code i am using.

I was thinking that it would be better to buffer the whole text and try to send it several TCP packets instead of a byte at a time like it is now. And this way I could hold on to it connect to server send and then disconnect. But will i need to get an arduino Mega to be able to do this.  I was just trying to get someone elses thoughts on this.

Code: [Select]
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1,177 };
byte server[] = { 192,168,1,3 };

unsigned long lastconnected;
unsigned long lastdisconnected;
unsigned long currenttime;

int count = 0;

Client client(server, 7000);

void setup()
   Ethernet.begin(mac, ip);


   if (client.connect()) {
      lastconnected = millis();

void loop()
   if (Serial.available() > 0) {            //Resend printed data from Serial out TCP
      char incomingByte = Serial.read();
      if(incomingByte!= 0x0C){
      if (incomingByte == 0x0C){  // Sees Form Feed Stops and disconnects
          client.println("End of Ticket");  // Marks end of print job
          lastdisconnected = millis();
   if (millis() - lastconnected > 540000 && client.connected()){    // Disconnects after connected for nine minutes
     lastdisconnected = millis();
   if (!client.connected() && (millis() - lastdisconnected > 100)){  //If disconnected,  reconnect
     lastconnected = millis();


Why do you care about the network load?  TCP takes care of a packet being missed by resending it.

If there is a load problem or performance problem you could send in packets of say, 10 bytes.  That would reduce your network load a lot and you could keep the same hardware.  You would have to declare a couple of buffers and switch between them, or track buffer usage.
And keep track of any part filled buffers at the end of the transmission and send them.

Also I see your code if tracking an 0x0c for the end of data.  If that is missed, you will cocatanate the next ticket.  Perhaps you should have a timeout in your code as well, in case the 0x0c is dropped.


First your note about putting in a timeout is a good idea. Thank You. 

I guess the only thing that I am really worried about is that if I receive a Print job while not connected. Will I just loose part of it?


I played with a little more and I one major flaw is that the print queue does no wait for it. I am able to send print jobs one after the other and they write over each other. Does arduino need to tell the windows it is busy and when it is ready? Does anyone have experience with this.

I believe if I was able to do this then there would be no need to buffer the print job.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131