I'm doing a program that receives data from a web page every so often, but only receives the data once and then receives everything blank. I need help to receive the data every time indefinitely. I am using arduino uno with arduino etherner shield
My code:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 177);
EthernetClient client;
int REDLed= 2;
int GREENLed= 3;
int BLUELed= 4;
void setup()
{
pinMode(REDLed, OUTPUT);
pinMode(GREENLed, OUTPUT);
pinMode(GREENLed, OUTPUT);
Ethernet.begin(mac, ip);
Serial.begin(9600);
Serial.println("power up" );
delay(3000);
}
void loop()
{
Serial.println("SubmitHttpRequest - started" );
SubmitHttpRequest();
Serial.println("SubmitHttpRequest - finished" );
delay(10000);
}
void SubmitHttpRequest()
{
if (client.connect(server, 80))
{
Serial.println("connected");
client.println("GET /arduino/getstate.php?color=All HTTP/1.1");
client.println("Host: cybertodo.mx");
client.println("Connection: close");
client.println();
}
else
{
Serial.println("connection failed");
}
delay(100);
changeLed();
}
void changeLed()
{
String content = "";
Serial.println(client.available());
while(client.available()!=0)
{
content = content + String(char (client.read()));
}
Serial.println(content);
if(content.substring(30,31)== "1")
{
digitalWrite(REDLed, HIGH);
}
else if (content.substring(30,31)== "0")
{
digitalWrite(REDLed, LOW);
}
if(content.substring(31,32)== "1")
{
digitalWrite(GREENLed, HIGH);
}
else if (content.substring(31,32)== "0")
{
digitalWrite(GREENLed, LOW);
}
if(content.substring(32,33)== "1")
{
digitalWrite(BLUELed, HIGH);
}
else if (content.substring(32,33)== "0")
{
digitalWrite(BLUELed, LOW);
}
content = "";
}