Pages: [1]   Go Down
Author Topic: Arduino Ethernet - Problem setting fixed IP address  (Read 629 times)
0 Members and 1 Guest are viewing this topic.
Asnieres sur Seine - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Ethernet.begin(mac);
I can then read the received IP address.
Ethernet.localIP();
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:
#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
  Serial.begin(9600);
  // Wait 3 seconds
  delay(3000);

  // 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:
  delay(1000);
  Serial.println("Connecting...\n");
 
  // Local IP address
  Serial.println("Local IP info : ");
  Serial.print("IP address : ");
  Serial.print(Ethernet.localIP());
  Serial.print("\nSubnet : ");
  PrintIP(bySubnet);
  Serial.print("\nGateway : ");
  PrintIP(byGateway);
  Serial.print("\nDNS : ");
  PrintIP(byDNS);
}

void loop() {
}

void PrintIP(byte byArr[]) {
  Serial.print(byArr[0]);
  Serial.print(".");
  Serial.print(byArr[1]);
  Serial.print(".");
  Serial.print(byArr[2]);
  Serial.print(".");
  Serial.print(byArr[3]);
}

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.

Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks like you mis-typed your IP address:
Code:
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:

196.168.0.1

Without a valid DNS server and Gateway you won't get much done.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Asnieres sur Seine - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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!
Logged

Pages: [1]   Go Up
Jump to: