5 Replies Latest reply on Jan 30, 2014 3:31 AM by LeFelix

    how to initiate EthenretServer librarie

    LeFelix

      hey

       

      i already tried some ethernet client sketches and they all worked. but when i try to use some arduino uno ethernet server sketches i get into trouble.

       

      -is there a way to manually set a IP or s there just the automatic DHCP way?

      -the webduino librabrie runs smooth on my UNO but throws compiler errors on the galileo. will that be fixed by intel or will the webduino makers have to write a new version for the galileo?

      -is there a documentation for the ethernet and ethernetserver lib on how to use and initiate on the galileo?

       

      greetings

        • 1. Re: how to initiate EthenretServer librarie
          Clayton Hofrock

          You can definitely start your Ethernet with a specific IP address:

           

          // The mac address of your Galileo
          byte mac[] = {   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
          // assign an IP address for the controller:
          IPAddress ip(192,168,1,20);
          Ethernet.begin(mac, ip);
          

           

          As for the webduino, I am not sure what the error is that you are getting. Maybe you could post the error? Most likely it is caused by the library using some Arduino specific library? When I install it and try to compile the Hello World example, I get this error:

          C:\Intel\arduino-1.5.3\libraries\Webduino/WebServer.h:428:47: error: 'pgm_read_byte' was not declared in this scope

           

          This error is because the pgmspace.h library is not supported on Galileo. This is a library which allows some of the Arduino sketch to be stored in the Flash ROM rather than take up space in the RAM. This library is specific to the implementation of the Arduino processor, and there is no port of this library for the Galileo.

           

          Will Intel fix this error? In order to do so, they would need to port the pgmspace library. I do not know if they plan to do that or not.

           

          In order to use the Galileo Ethernet, the best place to look is at the Example provided by the IDE. File->Examples->Etherrnet. Most of the Examples work fine as they are.

           

          If you are looking to build a web server, it might be easier to do that using the Linux side of Galileo. There are people who have gotten a web server running using ruby on rails Web Server on Galileo, and there is also a group that has gotten a web server working with libwebsocket. Lyt | Second Story

          1 of 1 people found this helpful
          • 2. Re: how to initiate EthenretServer librarie
            LeFelix

            Ok, i ll work with the webduino later. But i can't  still manage to run my EthernetServer Sketch on the galileo.

            Could you please help me port my arduino uno sketch to the Galileo:

             

            ------------------------------------

             

            #include <SPI.h>

            #include <Ethernet.h>

             

            // Enter a MAC address and IP address for your controller below.

            // The IP address will be dependent on your local network:

            byte mac[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };

            byte ip[]     = {192,168,178, 42};

            byte gateway[]= {192,168,178,  1};

            byte subnet[] = {255,255,255,  0};

             

            // Initialize the Ethernet server library

            // with the IP address and port you want to use

            // (port 80 is default for HTTP):

            EthernetServer server(80);

             

            void setup()

            {

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

              Serial.begin(9600);

              while (!Serial)

              {

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

              }

             

              // start the Ethernet connection and the server:

              Ethernet.begin(mac, ip, gateway, subnet);

              server.begin();

              Serial.print("server is at ");

              Serial.println(Ethernet.localIP());

            }

             

             

            void loop()

            {

              // listen for incoming clients

              EthernetClient client = server.available();

              if (client)

              {

                Serial.println("new client");

                // an http request ends with a blank line

                boolean currentLineIsBlank = true;

                while (client.connected())

                {

                  if (client.available())

                  {

                    char c = client.read();

                    Serial.write(c);

                    // if you've gotten to the end of the line (received a newline

                    // character) and the line is blank, the http request has ended,

                    // so you can send a reply

                    if (c == '\n' && currentLineIsBlank)

                    {

                      // send a standard http response header

                      client.println("HTTP/1.1 200 OK");

                      client.println("Content-Type: text/html");

                      client.println("Connection: close");  // the connection will be closed after completion of the response

                      client.println("Refresh: 5");  // refresh the page automatically every 5 sec

                      client.println();

                      client.println("<!DOCTYPE HTML>");

                      client.println("<html>");

                      // body part der html seite

                     

                      client.println("<b>Hello World - Arduino Edition</b>");

                     

                      //  ende html body

                      client.println("</html>");

                      break;

                    }

                    if (c == '\n')

                    {

                      // you're starting a new line

                      currentLineIsBlank = true;

                    }

                    else if (c != '\r')

                    {

                      // you've gotten a character on the current line

                      currentLineIsBlank = false;

                    }

                  }

                }

                // give the web browser time to receive the data

                delay(1);

                // close the connection:

                client.stop();

                Serial.println("client disonnected");

              }

            }

            • 3. Re: how to initiate EthenretServer librarie
              AlexT_Intel

              Hi LeFelix,

               

              What error do you get specifically? It would help if you could describe the exact manifestation of the problem.

               

              ADDED LATER: Okay, I suspected your Ethernet.begin and looks like it's indeed the reason (or at least one of them). I haven't run a sketch, but by inspecting the code you posted I see the number of arguments to begin() is wrong, there should be a DNS server IP also.

               

              See this Ethernet::begin() description on arduino.cc, Galileo's one is the same: http://arduino.cc/en/Reference/EthernetBegin

               

              With Galileo, as long as there's no actual shield to initialize, you can skip the begin() completely, provided you have a DHCP in your network, which would give out the address to Galileo automatically. If you want to assign an address statically, just use this form of the begin():

              begin(uint8_t *mac_address, IPAddress local_ip);

               

              And one more - after you get past this initial problems, you'll most probably hit the bug described in this thread: Ethernet Library: sketch crashes when remote client closes connection, so make sure to use one of the solutions listed there to overcome it.

              • 4. Re: how to initiate EthenretServer librarie
                AlexT_Intel

                So how is it, have you been able to get it running?

                If not - what errors do you still see?

                 

                If it's all good now, I'd encourage you to mark this question as answered, to indicate to others who may have similar problems in the future that there's a solution in here. You can do that my marking one of the answers to your post as "correct answer" (green star), or marking it as "assumed answered" (at the top of your initial post).

                • 5. Re: how to initiate EthenretServer librarie
                  LeFelix

                  Hey Alex,

                   

                  sorry for not answering, i had had a lot to do in university.

                  I now got a sketch working an online, the last thing is the manual IP adress (the DHCP way works great).

                   

                  Is there a way to get the systems mac adress or do i have to write it manually and then insert it in the begin()?

                   

                  ---------------------------

                  //this works but still needs a dhcp

                   

                  #include <Ethernet.h>

                   

                  EthernetServer server = EthernetServer(80);

                   

                  void setup()

                  {

                    // start listening for clients

                    server.begin();

                    Serial.println(Ethernet.localIP());

                  }

                  .......