I have an arduino attached with a RGB-Shield. I want to query my server for the RGB values periodically. I basically got it working using the Ethernet Shield but it takes too long to get the value (~500ms}. I really want to read the values from my server really really fast in an endless loop.
Can you give me any hints on how I can improve my code?
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(192,168,1,151);
IPAddress ip(192, 168, 1, 177);
EthernetClient client;
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Ethernet.begin(mac, ip);
}
delay(1000);
if (client.connect(server, 80)) {
client.println("GET /rgb.php HTTP/1.1");
client.println("Host: 192.168.1.151");
client.println("Connection: close");
client.println();
}
else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
... read from Server
}
if (!client.connected()) {
client.stop();
if (client.connect(server, 80)) {
client.println("GET /rgb.php HTTP/1.1");
client.println("Host: 192.168.1.151");
client.println("Connection: close");
client.println();
}
}
}