2 Replies Latest reply on Jul 23, 2015 2:55 AM by fgarcia.autis

    Serial to Ethernet converter Intel Galileo Gen2




      I have been trying to create via Arduino IDE with one sketch a Serial to Ethernet converter (the code is below). First of all I've tried to communicate from the Serial port to the Ethernet and everything was ok, via telnet. After this I've tried to communicate from Ethernet to Serial and it was also ok, without any kind of delay. However, when I joined both solutions I found one problem: the serial to ethernet information is received as a burst not continuosly. After some debugging I detected that the method client.available() is the one that introduces a delay, I assume that is a timeout delay waiting for  the client and after this delay I receive all the information buffered in the serial port. The question is that I want to receive in continuously in both directions, so my questions are:

      Is there any way to modify the timeout of the different functions such as client.available()?

      If there is no way to modify this timeout, can I execute in a parallel way both recepcion and transmission in order not to block non of the processes? In other words, can I handle independently the Serial to Ethernet and the Ethernet to Serial in order not to block with the timeout of the Ethernet functions the serial ones?

      Sorry if it's and easy question but I am starting with Intel Galileo, Arduino IDE an sketch.

      Thank you very much in advance.

      Note: I am using the serial interface to debug and serial1 to connect the a physical serial port (that's why everything is related to Serial1, but with Serial works exactly the same)

      Best regards,


      #include <SPI.h>

      #include <Ethernet.h>



      byte mac[] = {0x98, 0x4F, 0xEE, 0x05, 0xA3, 0xD3};

      IPAddress ip(192,168,1, 20);

      IPAddress gateway(192,168,1, 1);

      IPAddress subnet(255, 255, 0, 0);

      EthernetServer server(23);

      boolean alreadyConnected = false; // whether or not the client was connected previously



      void setup() {



        pinMode(5, OUTPUT);//Select the multiplexor to choose the RS232 Slot of Cooking hack's

        system("ifdown eth0");//I have to do this in order to make Ethernet work

        system("ifup eth0");//I have to do this in order to make Ethernet work

        delay(3000); // Delay to check in the serial port the IP

        // initialize the ethernet device

        Ethernet.begin(mac);// IP with DHCP

        // start listening for clients


      // Open serial communications and wait for port to open:

        Serial.begin(9600);//Initialize debugging port

        Serial1.begin(9600);//Initialize Cooking Hacks port

         while (!Serial) {

          ; // wait for serial port to connect. Needed for Leonardo only


        Serial.print("Chat server address:"); //To debugging port

        Serial1.print("Chat server address:");//To Cooking Hacks port

        Serial.println(Ethernet.localIP()); //To debugging port

        Serial1.println(Ethernet.localIP());//To Cooking Hacks port




      void loop() {


        // wait for a new client:

        EthernetClient client = server.available();

        digitalWrite(5, HIGH);//Select the multiplexor to choose the RS232 Slot of Cooking hack


        //--------------------------------------From Ethernet to Serial-----------------------

        // when the client sends the first byte, say hello:

        if (client) {  

          if (!alreadyConnected) {

            // clead out the input buffer:


            Serial.println("We have a new client");//To debugging port

            Serial1.println("We have a new client");//To Cooking Hacks port

            client.println("Hello, client!");

            alreadyConnected = true;




          /*if (client.available() > 0) { // HERE is where the process is blocked (with the client.available), if there is no reception via Ethernet the From Serial to Ethernet is not executed until the timeout expires.

         //When the timeout   

            // read the bytes incoming from the client:

            char thisChar = client.read();

           // echo the bytes to the serial ports:

           Serial.print(thisChar);//To debugging port

           Serial1.print(thisChar);//To Cooking Hacks port


          //--------------------------------------From Serial to Ethernet-----------------------

          //if (Serial.available())


          //  delay(10);

          //  char inByte;

          //  inByte = Serial.read();

          //  Serial.write(inByte);


          if (client.available() > 0) {           

            // read the bytes incoming from the client:

            char thisChar = client.read();

            // echo the bytes back to the client:


            // echo the bytes to the server as well:


            Serial1.print(thisChar);//To Cooking Hacks port      






              while (Serial1.available()) {


                char inChar = char(Serial1.read());


                Serial1.write(inChar);//To Cooking Hacks port




            Serial1.print("\n");//To Cooking Hacks port