With this sketch you can already fill out the form and it will stay in the ARduino's memory. You can follow what's happening on the Serial Monitor.
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
//CHANGE THIS TO MAKE THIS SKETCH WORK
byte IP1 = 192;//the first part of the IP-address
byte IP2 = 168; //the second part of the IP-address
byte IP3 = 1; //the thirth part of the IP-address
byte IP4 = 2; //the fourth part of the IP-address
byte GW1 = 192; //the first part of the GATEWAY
byte GW2 = 168; //the second part of the GATEWAY
byte GW3 = 1; //the thirth part of the GATEWAY
byte GW4 = 1; //the fourth part of the GATEWAY
byte SUB1 = 255; //first part of the SUBNETMASK
byte SUB2 = 255; //the second part of the SUBNETMASK
byte SUB3 = 255; //the thirth part of the SUBNETMASK
byte SUB4 = 0; //the fourth part of the SUBNETMASK
byte TYPE = 1; //the type is set to 1 = static
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {IP1,IP2,IP3,IP4};
byte gateway[] = {GW1,GW2,GW3,GW4};
byte subnet[] = {SUB1,SUB2,SUB3,SUB4};
Server server(80);
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.println("ready");
}
void loop()
{
Client client = server.available();
if (client) {
TextFinder finder(client );
while (client.connected()) {
if (client.available()) {
if( finder.find("GET /") ) {
Serial.println("connection has been made");
if (finder.findUntil("ST", "\n\r")){
Serial.println("found static or dhcp");
TYPE = finder.getValue();
while(finder.findUntil("DT", "\n\r")){
int val = finder.getValue();
if(val >= 0 && val <= 3) {
ip[val] = finder.getValue();
}
if(val >= 4 && val <= 7) {
subnet[val - 4] = finder.getValue();
}
if(val >= 8 && val <= 11) {
gateway[val - 8] = finder.getValue();
}
}
}
Serial.println();
if ( TYPE == 1 ){
Serial.print("type is static");
}
if ( TYPE == 2 ){
Serial.print("type is dhcp");
}
Serial.println();
Serial.print("The IP address is:");
Serial.print(ip[0],DEC);
for (int i= 1; i < 4; i++){
Serial.print(".");
Serial.print(ip[i],DEC);
}
Serial.println();
Serial.print("The Subnet is:");
Serial.print(subnet[0],DEC);
for (int i= 1; i < 4; i++){
Serial.print(".");
Serial.print(subnet[i],DEC);
}
Serial.println();
Serial.print("The gateway is:");
Serial.print(gateway[0],DEC);
for (int i= 1; i < 4; i++){
Serial.print(".");
Serial.print(gateway[i],DEC);
}
Serial.println();
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<html><body><table><form><tr><td>TYPE: <select name=\"ST\">");
client.print("<option value=\"1\">static</option><option value=\"2\">dhcp</option></select></td></tr>");
client.print("<tr><td>IP: <input type=\"text\" size=\"1\" maxlength=\"3\" name=\"DT0\" value=\"");
client.print(ip[0],DEC);
client.print("\">.<input type=\"text\" size=\"1\" maxlength=\"3\" name=\"DT1\" value=\"");
client.print(ip[1],DEC);
client.print("\">.<input type=\"text\" size=\"1\" maxlength=\"3\" name=\"DT2\" value=\"");
client.print(ip[2],DEC);
client.print("\">.<input type=\"text\" size=\"1\" maxlength=\"3\" name=\"DT3\" value=\"");
client.print(ip[3],DEC);
client.print("\"></td></tr><tr><td>MASK: <input type=\"text\" size=\"1\" maxlength=\"3\" name=\"DT4\" value=\"");
client.print(subnet[0],DEC);
client.print("\">.<input type=\"text\" size=\"1\" maxlength=\"3\" name=\"DT5\" value=\"");
client.print(subnet[1],DEC);
client.print("\">.<input type=\"text\" size=\"1\" maxlength=\"3\" name=\"DT6\" value=\"");
client.print(subnet[2],DEC);
client.print("\">.<input type=\"text\" size=\"1\" maxlength=\"3\" name=\"DT7\" value=\"");
client.print(subnet[3],DEC);
client.print("\"></td></tr><tr><td>GW: <input type=\"text\" size=\"1\" maxlength=\"3\" name=\"DT8\" value=\"");
client.print(gateway[0],DEC);
client.print("\">.<input type=\"text\" size=\"1\" maxlength=\"3\" name=\"DT9\" value=\"");
client.print(gateway[1],DEC);
client.print("\">.<input type=\"text\" size=\"1\" maxlength=\"3\" name=\"DT10\" value=\"");
client.print(gateway[2],DEC);
client.print("\">.<input type=\"text\" size=\"1\" maxlength=\"3\" name=\"DT11\" value=\"");
client.print(gateway[3],DEC);
client.print("\">.</td></tr><tr><td><input type=\"submit\" value=\"SUBMIT\"></td></tr>");
client.print("</form></table>
<FORM>");
client.print("'\"></FORM></body></html>");
client.print("free test SRAM = ");
client.print(availableMemory());
client.print(" / SRAM used = ");
client.print(2048-availableMemory());
break;
}
}
delay(1);
client.stop();
}
}
int availableMemory()
{
int size = 2048;
byte *buf;
while ((buf = (byte *) malloc(--size)) == NULL);
free(buf);
return size;
}