Hey I am running through the Arduino Cookbook doing examples, this is the code I'm working on atm:
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAD }; //physical mac address
byte ip[] = { 131, 181, 87, 145 }; // ip of arduino in lan
byte gateway[] = { 131, 181, 87, 129 }; // internet access via router
byte subnet[] = { 255, 255, 255, 128 }; //subnet mask
EthernetServer server(80); //server port
char buffer[8];
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.println("Ready");
}
void loop()
{
EthernetClient client = server.available();
if (client) {
TextFinder finder(client);
int type = 0;
while (client.connected()) {
if (client.available()) {
if(finder.getString("","/",buffer,sizeof(buffer))){
Serial.println(buffer);
if(strcmp(buffer, "POST ") ==0){
finder.find("\n\r");
while(finder.findUntil("pinD", "\n\r")){
int pin = finder.getValue();
int val = finder.getValue();
pinMode(pin, OUTPUT);
digitalWrite(pin, val);
}
}
sendHeader(client, "POSTing Stuff");
client.println("<h2>POSTing Stuff</h2>");
client.print("<form action= '/' method = 'POST'><p><input type = 'hidden' name = 'pinD8' value='0'>");
client.println("<input type='submit' value='OFF' /></form>");
client.print("<form action= '/' method = 'POST'><p><input type = 'hidden' name = 'pinD8' value='1'>");
client.println("<input type='submit' value='ON' /></form>");
client.println("</body></html>");
client.stop();
}
break;
}
}
}
}
void sendHeader(EthernetClient client, char *title)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<html><head><title>");
client.print(title);
client.println("</title><body>");
}
For some reason it is ridiculously slow. Watching the serial monitor it gets the "POST" on button click from the web page end but takes a full 4-5 seconds to turn the LED on/off, I removed all the delay() the example had but that didn't change anything. Is TextFinder just really slow or something else afoot?