I am working on a project to connect to a website and read some values but my ethernet shield only connects once then fails.
#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[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
char serverName[] = "
www.bisulco.us";
int x=0;
String s[5];
int y=0;
int control=0;
// 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() {
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
// 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(serverName, 80)) {
client.println("GET
http://bisulco.us/Site/Current.html HTTP/1.0");
Serial.println("connected");
// Make a HTTP request:
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if(control==0){
if (client.available()) {
char c = client.read();
x=x+1;
Serial.print(c);
if(x>40){
s[y]=s[y]+x;
if(c=='\n'){
y=y+1;
}
}
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
control=1;
}
}else if(control==1){
Serial.print(s[0]);
}else{
Serial.println("OYUT");
}
}