Go Down

Topic: Arduino Ethernet - Problem setting fixed IP address (Read 922 times) previous topic - next topic


I have an Arduino Ethernet PoE. It took me a few days to get the USB2SERIAL adaptor to start playing with it...

I have no problems in connecting it using DHCP.
I can then read the received IP address.
I can then ping the card from elsewhere on the network using that IP address.
I can renew the DHCP lease with maintain() and everything continues to work as expected and I can ping it again.

When I try to do the same with a fixed IP address I can't see the card on the network. It doesn't show up in the list of connected devices on the switch / router and I can't ping it.

Code: [Select]

#include <SPI.h>
#include <Ethernet.h>

void setup() {
  // Ethernet's MAC
  byte byMAC[] = { 0x90, 0xA2, 0xDA, 0x00, 0xEC, 0x8D };
  // Fixed IP address config
  byte byDNS[] = { 8, 8, 8, 8 };
  byte byGateway[] = { 192, 168, 0, 1 };
  byte bySubnet[] = { 255, 255, 255, 0 };
  IPAddress ip(196,168,0,50);
// Open serial communications
  // Wait 3 seconds

  // Some declaring text
  Serial.println("\nArduino Ethernet - Ethernet Fixed IP Connection");
  Ethernet.begin(byMAC, ip);
  // Ethernet.begin(byMAC, ip, byDNS);
  //  Ethernet.begin(byMAC, ip, byDNS, byGateway);
  // Ethernet.begin(byMAC, ip, byDNS, byGateway, bySubnet);

  // give the Ethernet shield a second to initialize:
  // Local IP address
  Serial.println("Local IP info : ");
  Serial.print("IP address : ");
  Serial.print("\nSubnet : ");
  Serial.print("\nGateway : ");
  Serial.print("\nDNS : ");

void loop() {

void PrintIP(byte byArr[]) {

As you can see I've tried just passing it the MAC and the local IP address, then added the DNS, then added the Gateway, then added the Subnet. None of these combinations makes the card show up on my network.


Looks like you mis-typed your IP address:
Code: [Select]
IPAddress ip(196,168,0,50);

Shouldn't that be 192,168,0,50?

If you get that wrong the presumed DNS and Gateway addresses will also be wrong:

Without a valid DNS server and Gateway you won't get much done.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp



Shouldn't that be 192,168,0,50?

<hiding head in shame>
    Duh.  :smiley-red: Of course that should have been 192 and not 196...
</hiding head in shame>

All of the other values were fine.

Changed the IP address to 192,168,0,50 and EVERYTHING WORKS FINE. I can see the Arduino on the net and ping it correctly.

I should have listened to my own words spoken so often to programmers: Step away from the code for a while, come back to it, read it again, then, and only then, do you consider it a problem.

Thank you for spotting this!

Go Up