3 Replies Latest reply on Mar 18, 2015 11:40 AM by JPMontero_Intel

    Ethernet access problem in visual studio

    SantoMecoide

      Hi

       

      I have a issue when connect galileo gen 1 to internet with ethernet using Visual Studio 2013 (Glileo Wiring App).

      I tried using DHCP and static IP but the app never connect

       

      In the next code, I use "OR" referring to choices already used and end with the same issue

       

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

      #include "stdafx.h"

      #include "arduino.h"

      #include <SPI.h>

      #include <Ethernet.h>

       

      int _tmain(int argc, _TCHAR* argv[])

      {

          return RunArduinoSketch();

      }

       

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

      char server[] = "www.google.com";

      byte ip[] = { 192, 168, 0, 12 };    OR    IPAddress ip(192, 168, 0, 12);

       

      EthernetClient client;

       

      void setup()

      {

        Serial.begin(9600);

       

        while(Ethernet.begin(mac) != 1) {                                                                              if (Ethernet.begin(mac) == 0) {

            Log(L"Failed to configure Ethernet using DHCP \n");                  OR                    Log(L"Failed to configure Ethernet using DHCP \n");                                                                                                         delay(5000);                                                                                                                  Ethernet.begin(mac,ip);   

         }                                                                                                                               }

       

        if (client.connect(server, 80)) {

            Serial.println("connected");

            client.println("GET /search?q=arduino HTTP/1.1");

            client.println("Host: www.google.com");

            client.println("Connection: close");

            client.println();

        }

        else {

            Log(L"connection failed \n");

        }

      }

       

      void loop()

      {

        if (client.available()) {

            char c = client.read();

            Log(L"%i \n", c);

        }

       

        if (!client.connected()) {

            Log(L"disconnecting. \n");

            client.stop();

            while (true);

        }

      }

       

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

       

      I Think the code have a problem in the first while routine in void setup()

      Visual Studio dont post mistakes when compiling

       

      When I use the same code with native arduino (connect galileo to usb and work with Arduini ID) the code dont have problems

        • 1. Re: Ethernet access problem in visual studio
          JPMontero_Intel

          Hi SantoMecoide,

           

          I haven’t used it with Visual Studio, but have you tried configuring it by using Linux commands? For example in Arduino IDE you can use system() function to run Linux commands from your Arduino sketch. Then you can try using ifconfig command to set up the IP address, in case you haven’t used it take a look at these examples. To connect with DHCP i'd suggest you to use the commands of this guide. I hope this helps.

           

          Regards,
          JPMontero_Intel

          • 2. Re: Ethernet access problem in visual studio
            SantoMecoide

            Hi JPMontero_Intel

             

            Thanks for the interest, but in Visual Studio C++ only can use the windows prompt command.

             

            I tried configure the net characteristics with "ipconfig" and "netsh" commands but I've had no luck.

             

            I tink the problem is a dark conflict with the dhcp of galileo windows and the Ethernet.begin(mac) function.

             

            Look I tried with this code

             

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

             

            #include "stdafx.h"

            #include "arduino.h"

            #include <SPI.h>

            #include <Ethernet.h>

             

            int _tmain(int argc, _TCHAR* argv[])

            {

              return RunArduinoSketch();

            }

             

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

            byte ip[] = { 192, 168, 0, 12 };

            EthernetServer server(80);

             

            void setup() {

             

              Serial.begin(9600);

              Ethernet.begin(mac);

             

              delay(10000);

             

              Log(L"IP address: ");

              for (byte thisByte = 0; thisByte < 4; thisByte++) {

              Log(L"%i", Ethernet.localIP()[thisByte], DEC);

              Log(L".");

              }

              Log(L"\n");

             

              Log(L"DNS address: ");

              for (byte thisByte = 0; thisByte < 4; thisByte++) {

              Log(L"%i", Ethernet.dnsServerIP()[thisByte], DEC);

              Log(L".");

              }

              Log(L"\n");

             

              Log(L"Gateway address: ");

              for (byte thisByte = 0; thisByte < 4; thisByte++) {

              Log(L"%i", Ethernet.gatewayIP()[thisByte], DEC);

              Log(L".");

              }

              Log(L"\n");

             

              Log(L"SubNetMask: ");

              for (byte thisByte = 0; thisByte < 4; thisByte++) {

              Log(L"%i", Ethernet.subnetMask()[thisByte], DEC);

              Log(L".");

              }

              Log(L"\n");

             

            void loop() {

             

            }

             

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

             

            And the output says:

             

            IP address: 255.255.255.255.

            DNS address: 255.255.255.255.

            Gateway address: 255.255.255.255.

            SubNetMask: 255.255.255.255.

            • 3. Re: Ethernet access problem in visual studio
              JPMontero_Intel

              Hi SantoMecoide,

               

              I apologize for the delay. We don’t support Windows image in here, maybe you could get a more accurate response in the windows on devices forums. If you decide to try Yocto image, here is a plugin for Visual Studio similar to the one you are using and additionally I’d suggest you to try adding a line into your code to see what is configured in the Linux side. You can use the following line:

              system(“ifconfig eth0 > /dev/ttyGS0”);

               

              That should send the Ethernet connection information to the Serial Monitor. I hope you find this helpful.

               

              Regards,
              JPMontero_Intel