Hello,
I have a new arduino controller and this is really fun working with, but I have a problem with setting op an ethernetconnection. I tried many times but it doesn't work.
This is my code. I have two led's. One that says everything is good and the otherone says there is a problem. The only led that is given light is the one with the error
#include <Ethernet.h>
byte mac[] = { 0x00, 0x1C, 0xF0, 0xFB, 0x6B, 0x8A };
byte ip[] = { 192, 168, 0, 2 }; // this is the ip within my lan
byte gateway[] = { 192, 168, 0, 1 }; // neccessary to get access to the internet via your router
byte subnet[] = { 255, 255, 255, 0 };
byte server[] = { 216, 239, 59, 104 }; // Google.nl
int gledPin = 13; // LED connected to digital pin 13 yellow one
int fledPin = 12; // LED connected to digital pin 12 red one
Client client(server, 80);
void setup()
{
pinMode(gledPin, OUTPUT);
pinMode(fledPin, OUTPUT);
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(9600);
Serial.println("connecting...");
if (client.connect()) {
digitalWrite(gledPin, HIGH); // set the LED on
} else {
Serial.println("connection failed");
digitalWrite(fledPin, HIGH); // set the LED on
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
}
This i a copy of my d-link router
WANConnection Type : DHCP Client .
QoS Engine : Active .
Cable Status : Connected .
DNS Status : Online .
Network Status : Established .
Connection Up Time : 0 Day 9 Hour 19 Min 40 Sec .
MAC Address : 00:1C:F0:FB:6B:8B .
Authentication & Security : .
IP Address : 192.168.0.2 .
Subnet Mask : 255.255.255.0 .
Default Gateway : 192.168.0.1 .
Primary DNS Server : 192.168.0.1 .
Secondary DNS Server : 0.0.0.0 .
.
LANMAC Address : 00:1C:F0:FB:6B:8A .
IP Address : 192.168.1.1 .
Subnet Mask : 255.255.255.0 .
DHCP Server : Enabled .