I have my etnernet shield installed on my arduino uno and I am doing some HTTP requests, however I encounter quite a few issues lately.
I am running the same code 3 times and I get 3 different results each time.
I dont understand how is that even possible.
I have made a slightly modfifyed version of the WebClient sample code,which continiously makes requests.
/*
Web client
This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "www.google.com"; // name address for Google (using DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Setting up ethernet..");
// start the Ethernet connection:
while (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP, retrying..");
// try to congifure using IP address instead of DHCP:
//Ethernet.begin(mac, ip);
}
}
void loop() {
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.1");
client.println("Host: www.google.com");
client.println("Connection: close");
client.println();
while (client.connected()) {
char c = client.read();
Serial.print(c);
}
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
// if there are incoming bytes available
// from the server, read them and print them:
}
The first time I connected to the server but got endless "..яяяяяяяяяяяяяяяяяяяяяяяяяяяяяяя"
as a response?Does anyone know what this is?
The second time I failed to connect to the ethernet..
After 3 unseccesful attemts I terminated the program.
The third time was a success, I kept making succesfull http get requests and got the correct response from the server, again containing яяяяяяяяяяяяяяяяяяяяяяяяяяяяяяя..
I attach the serial output from the 3 tries.
Does anyone know how can I keep making succesfull HTTP request over and over ?
result1.txt (14.2 KB)
result2.txt (182 Bytes)
result3.txt (12.2 KB)