1

I'm having issues connecting to my arduino mega via ethernet. Its a very basic start to the code just to get the network side up and running, them im going to add in what I actually want it to do. For some reason, even after changing the cables and ethernet ports used, I still get linkStatus() returning LinkOFF? The server starts, and listens for clients, but I can't connect to it from my PC. I'm on the same subnet.

    #include <SPI.h>
    #include <Ethernet.h>
    
    IPAddress ip(10,126,132,32);
    int baud = 9600;
    byte mac[] = {
                   0xA8, 0x61, 0x0A, 0xAE, 0x76, 0x17
                 };
    
    byte subnet[] = {255, 255, 254, 0};
    byte gateway[] = {10, 126, 132, 1};
    
    EthernetServer server(80);
    
    void setup(){
      Serial.begin(baud);
      Serial.print("\n-------------------------");
      Serial.print("\nSerial initialised: ");
      Serial.print(baud);
      Ethernet.begin(mac, ip, gateway, gateway, subnet);
      server.begin();
      Serial.print("\nServer initialised... ");
      Serial.print("\nLocal IP: \t");
      Serial.print(Ethernet.localIP());
      Serial.print("\nDNS Server IP: \t");
      Serial.print(Ethernet.dnsServerIP());
      Serial.print("\nGateway IP: \t");
      Serial.print(Ethernet.gatewayIP());
      Serial.print("\nSubnet Mask: \t");
      Serial.print(Ethernet.subnetMask());
      Serial.print("\nHardware status: ");
      if (Ethernet.hardwareStatus() == EthernetNoHardware){Serial.print("No Hardware Detected");}
      else if (Ethernet.hardwareStatus() == EthernetW5500){Serial.print("W5500 Board Detected");}
      else if (Ethernet.hardwareStatus() == EthernetW5200){Serial.print("W5200 Board Detected");}
      else if (Ethernet.hardwareStatus() == EthernetW5100){Serial.print("W5100 Board Detected");}
      Serial.print("\nLink status: \t");
      if (Ethernet.linkStatus() == LinkON){Serial.print("ON");}
      else if (Ethernet.linkStatus() == LinkOFF){Serial.print("OFF");}
      else if (Ethernet.linkStatus() == Unknown){Serial.print("Unknown");}
      Serial.print("\n-------------------------");
      if(server) { Serial.print("\nServer Available\nWaiting for client..."); }
      else {Serial.print("\nServer not available");}
    }
    
    void loop() 
    {
      Ethernet.maintain();
      EthernetClient client = server.available();
      if (client) 
        {
          Serial.println("Client found...");
          Serial.println(client.read());
      }
    }

When trying to connect via my browser, I get Error: Connection Refused.

Any help is appreciated!

1
  • 1
    the WebClient example works? does it work with DHCP assigned IP address? try to wait half a second and then again test the link status.
    – Juraj
    Aug 25 at 6:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.