I am having trouble getting started with the Ethernet Shield (http://www.sparkfun.com/products/9026) using the Arduino Decimilia.
I am using a manually configured Ethernet connection sharing on my Mac with the following values
On my computer:
IP: 192.168.1.92
Router: 192.168.1.254
DNS Server: 192.168.2.254
Ethernet shield on Arduino:
IP: 192.168.1.124
MAC Address:
Gateway: 192.168.1.92 (have also tried 192.168.1.254)
Subnet: 255.255.255.0
and then do Ethernet.begin(mac, ip, gateway, subnet)
I can’t ping it and my Client.connect() always returns false in the following code
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x79, 0x4B }; //mac address of the arduino
byte ip[] = { 192, 168, 1, 124 }; //ip address for arduino
byte gateway[] = { 192, 168, 1, 92 }; //ip address of the gateway or router
byte subnet[] = { 255, 255, 255, 0 };
byte server[] = { 74, 125, 224, 72 };
uint8_t connectStatus;
uint8_t closeStatus;
int ignore;
Client client(server, 80);
void setup()
{
Ethernet.begin(mac, ip, gateway);
Serial.begin(9600);
}
void loop()
{
for (int i=1; i<=50; i++) {
Serial.print("Connection Attempt ");
Serial.print(i, DEC);
ConnectToWebserver();
delay(1);
}
// Enter an infinite loop to "stop" the sketch
while (true);
}
void ConnectToWebserver(){
uint8_t connectStatus;
if (client.connect()) {
Serial.print(" - Connected");
// Send the HTTP GET to the server
client.println("GET / HTTP/1.0");
client.println();
// Read the response
Serial.print(" - ");
Serial.print(ReadResponse(), DEC);
Serial.println(" bytes received");
// Disconnect from the server
client.flush();
client.stop();
} else {
// Connection failed
Serial.println(" - CONNECTION FAILED!");
}
}
int ReadResponse(){
int totalBytes=0;
unsigned long startTime = millis();
// First wait up to 5 seconds for the server to return some data.
// If we don't have this initial timeout period we might try to
// read the data "too quickly" before the server can generate the
// response to the request
while ((!client.available()) && ((millis() - startTime ) < 5000));
while (client.available()) {
char c = client.read();
totalBytes+=1;
}
return totalBytes;
}
Would really appreciate some help