View Single Post
  #7   Spotlight this post!  
Unread 06-08-2013, 18:31
jwallace15's Avatar
jwallace15 jwallace15 is offline
What am I going to do with my life?
AKA: Wally
FRC #0068 (Truck Town Thunder)
Team Role: College Student
 
Join Date: Aug 2012
Rookie Year: 2013
Location: Michigan
Posts: 435
jwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud ofjwallace15 has much to be proud of
Re: Arduino + Ethernet Shield Help

Here is the final working code;

Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1,130 };

const int MAX_PAGENAME_LEN = 8;
char buffer[MAX_PAGENAME_LEN+1];

EthernetServer server(80);

void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  server.begin();
  delay(2000);
}

void loop()
{
  EthernetClient client = server.available();
  if (client)
  {
    int type = 0;
    while (client.connected())
    {
      if (client.available())
      {
        memset(buffer,0, sizeof(buffer));
        //if(client.find("/"))
          if(client.readBytesUntil('/', buffer,sizeof(buffer)))
          {
            Serial.println(buffer);
            if(strcmp(buffer,"POST ") == 0)
            {
              client.find("\n\r");
              while(client.findUntil("PinD", "\n\r"))
              {
                int pin = client.parseInt();
                int val = client.parseInt();
                pinMode(pin, OUTPUT);
                digitalWrite(pin, val);
              }
            }
            sendHeader(client,"Post example");
            client.println("<h2>Click buttons to turn pin 8 on or off</h2>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD8'");
            client.println(" value='0'><input type='submit' value='Off'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD8'");
            client.println(" value='1'><input type='submit' value='On'/></form>");
            client.println("</body></html>");
            client.stop();
          }
          break;
        }
      }
      delay(1);
      client.stop();
    }
  }
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>");
}
__________________
J Wallace IV
Truck Town Thunder
Just a college student now.