- Wed Mar 17, 2010 3:35 am
#96419
Helo!
I have just bought ethernet shield,but im strugling to make even the simplest code work in the arduino example codes.I have tried both the webclient code and webserver,but i only get connection failed?? I just cant get it work,i have written some comments in the code.My plan is to but sensor data in pachube.com,but first i have to manage to test this basic codes.
by the way im using my schools network to test,if it make difference.
I have just bought ethernet shield,but im strugling to make even the simplest code work in the arduino example codes.I have tried both the webclient code and webserver,but i only get connection failed?? I just cant get it work,i have written some comments in the code.My plan is to but sensor data in pachube.com,but first i have to manage to test this basic codes.
by the way im using my schools network to test,if it make difference.
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };/* i tested it my laptops mac,and plugged the laptop out of the network.
I also tried to give it a random mac. as i have read in the forums.
*/
byte ip[] = { 10, 0, 0, 177 };/* which ip should i use?
i tried my laptops ip and plugged it out of the network.i also tried a random ip.
*/
byte server[] = { 64, 233, 187, 99 }; // Google
Client client(server, 80);
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
} else {
Serial.println("connection failed");//all the time i get this
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
}