Sorry but I'm new at this and I ran into a problem that has stumped me.
I have a new MEGA 2560 with a Ethernet Shield. Works fine with DHCP. Does not connect using a Static. I have the IP Info displaying in the serial output and it looks like I got everything in the correct place. I did a lot of cut and paste to get this together so I'm guessing I did something wrong. Here is the two outputs:
*** Initializing Ethernet ***
Setting Default IP Address
My IP address: 192.168.1.200.
My Subnet Mask: 255.255.255.0.
My Gateway: 192.168.1.1.
My DNS: 192.168.1.5.
Connecting to External Gateway 192.168.1.1 on port 80
connection failed
Closing Connection
*** Initializing Sump Tank ***
First Sump Tank Reading: 577
*** Initializing Alarm ***
Alarm Silence Set to 2
with boolean useDHCP = true;
*** Initializing Ethernet ***
Attempting to get a DHCP address
My IP address: 192.168.1.70.
My Subnet Mask: 255.255.255.0.
My Gateway: 192.168.1.1.
My DNS: 192.168.1.5.
Connecting to External Gateway 192.168.1.1 on port 80
connected
Closing Connection
*** Initializing Sump Tank ***
First Sump Tank Reading: 570
*** Initializing Alarm ***
Alarm Silence Set to 2
Here is a stripped down version that just has the network part.
#include <SPI.h>
#include <Ethernet.h>
// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// assign an IP address for the controller:
IPAddress ip(192,168,1,200);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
IPAddress dnsserver(192,168,1,5);
IPAddress externalGateway(192,168,1,1);
boolean useDHCP = true;
char google[] = "www.google.com";
EthernetClient client;
EthernetServer server(80);
void setup()
{
Serial.begin(9600);
// Ethernet Start
Serial.println("");
Serial.println("*** Initializing Ethernet ***");
if (useDHCP) {
Serial.println("Attempting to get a DHCP address");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Serial.println("Setting Default IP Address");
Ethernet.begin(mac, ip, dnsserver, gateway, subnet);
//Ethernet.begin(mac, ip);
}
} else {
Serial.println("Setting Default IP Address");
Ethernet.begin(mac, ip, dnsserver, gateway, subnet);
//Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println("");
Serial.print("My Subnet Mask: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.subnetMask()[thisByte], DEC);
Serial.print(".");
}
Serial.println("");
Serial.print("My Gateway: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.gatewayIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println("");
Serial.print("My DNS: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.dnsServerIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println("");
Serial.println("");
Serial.print("Connecting to External Gateway ");
Serial.print(externalGateway);
Serial.println(" on port 80");
// if you get a connection, report back via serial:
if (client.connect(externalGateway, 80)) {
Serial.println("connected");
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
Serial.println("Closing Connection");
client.stop();
Serial.println("");
Serial.println("");
Serial.print("Connecting to Google ");
Serial.println("on port 80");
// if you get a connection, report back via serial:
if (client.connect(google, 80)) {
Serial.println("connected");
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
Serial.println("Closing Connection");
client.stop();
}
void loop()
{
}
Thanks for any help you can provide!!!!