0

Im trying to connect my Arduino Mega 2560 to my ethernet shield generic HanRun HR911105A, however im having some troubles, im runing the ethernet example that comes with arduino IDE.

I give arduino an static ip 192.168.215.202, i tried many tutorials and none of them worked.


    #include 
    #include 


    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    byte ip[] = { 192, 168, 215, 203 };
    byte server[] = { 64, 233, 187, 99 }; // Google

    EthernetClient client;

    void setup()
    {
      Ethernet.begin(mac, ip);
      Serial.begin(9600);

      delay(100);

      Serial.println("connecting...");

      if (client.connect(server, 80)) {
        Serial.println("connected");
        client.println("GET /search?q=arduino HTTP/1.0");
        client.println();
      } else {
        Serial.println("connection failed");
      }
    }

    void loop()
    {
      if (client.available()) {
        char c = client.read();
        Serial.print(c);
      }

      if (!client.connected()) {
        Serial.println();
        Serial.println("disconnecting.");
        client.stop();
        for(;;)
          ;
      }
    }

It just prints: connecting.. connection failed.. disconecting...

Im running Ubuntu 16.04, any suggestions? I ran out of ideas

migrated from stackoverflow.com Nov 26 '18 at 17:21

This question came from our site for professional and enthusiast programmers.

  • use the latest version of the Ethernet library and try the WebClient example of it – Juraj Nov 20 '18 at 19:12
  • Same mistake, im using version 2.0.0, it just gave me: Initialize Ethernet with DHCP: Failed to configure Ethernet using DHCP connecting to www.google.com... connection failed disconnecting. Received 0 bytes in 0.0000, rate = 0.00 kbytes/second – Jorge_Garza Nov 20 '18 at 20:52
  • what does the WebClient example print? – Juraj Nov 20 '18 at 20:53
  • Initialize Ethernet with DHCP: Failed to configure Ethernet using DHCP connecting to www.google.com... connection failed disconnecting. Received 0 bytes in 0.0000, rate = 0.00 kbytes/second – Jorge_Garza Nov 20 '18 at 20:53
  • My ethernet shield did not include the mac address sticker, so im using a manual set value byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 0, 177); IPAddress myDns(192, 168, 0, 1); – Jorge_Garza Nov 20 '18 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy