Hi all
been stuck trying to connect my uno board with Ethernet shield to the internet using my bt home hub. Have tried the web server sketch which worked fine but the moment i try to go to the internet it refuses to connect.
please see below the code i am trying to run
#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <Udp.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x9C, 0x35 };
byte ip[] = { 192, 168, 1, 97 };
byte gateway[] = { 192, 168, 1, 254 };
byte subnet[] = { 255, 255, 255, 0 };
// www.google.com ip
byte server[] = { 74, 125, 226, 242 };
EthernetClient client;
int loopCount = 0;
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(9600);
pinMode(13,OUTPUT);
if (client.connect(server, 80)) {
Serial.println("connected");
} else {
Serial.println("connection failed");
}
}
void loop()
{
int thisByte;
int newCount = 0;
if(client.connected())
{
newCount = client.available();
// if(newCount > 0) thisByte = client.read();
Serial.print("Available ");
Serial.println(newCount, DEC);
}
else if(loopCount == 0)
{
// if not connected, attempt to reconnect
client.stop();
Serial.print("Connecting...");
delay(10);
if (client.connect(server, 80)) {
Serial.println("ok");
} else {
Serial.println("failed.");
delay(10);
}
}
// heartbeat
if(loopCount > 8)
{
digitalWrite(13,HIGH);
loopCount = 0;
}
else
{
loopCount = loopCount++;
}
if(loopCount == 4)
{
digitalWrite(13,LOW);
}
delay(100);
}
code was taken from surfer tim and modified slightly (orginal code http://arduino.cc/forum/index.php/topic,70988.45.html).
when running code i just get connection failed time and time again
can't help but think it's a problem with my router (bt home hub 3), was wondering if anyone had any experience using this type of router with the ethernet shield?
cheers all
herroc