Please? how do i set analog value from a http string?

Hi hi there i need a little kick in the right direction for my home automation project
I need to set "int analog " value to the number in my string ( http://10.1.2.169/?form=695 ) ie the 695

heres my test code so far

//*******************************

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

int analog ;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 10,1,1,177 }; // ip in lan
byte gateway[] = { 10,1,2,169 }; // the IP of the router or acsesspoint
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask (i dont think this is neccesary
Server server(80); // server port (change this if you are having a local webserver else than the arduino)

int ledPin = 4; // LED pin

int sensorPin = A0; // analog in 0 for testing
int sensorValue = 0; // integer for the analog sensor

String readString = String(30); // string for fetching data from address

boolean LEDON = false; // LED status flag

void setup()
{
Serial.begin (9600);
Ethernet.begin(mac, ip, gateway, subnet); //start Ethernet

pinMode(ledPin, OUTPUT); //Set pin 4 to output

analog = 100;
}

void loop(){

Client client = server.available(); // Create a client connection
if (client) {
while (client.connected()) {
if (client.available()) {

char c = client.read();

if (readString.length() < 30) { //read char by char HTTP request
readString += c; } //store characters to string

if (c == '\n') { //if HTTP request has ended

int stringthing = readString.indexOf("="); //here is a key component of where the status is being read by the arduino
Serial.println (readString);

if (stringthing > 1){

if (readString.indexOf ("on")>0) { //led has to be turned ON
digitalWrite(ledPin, HIGH); // set the LED on

LEDON = true;
}

if (readString.indexOf( "off") >0) {
//led has to be turned OFF
digitalWrite(ledPin, LOW); // set the LED OFF

LEDON = false;
}

}

client.println("HTTP/1.1 200 OK"); //output HTML data starting with standart header
client.println("Content-Type: text/html");
client.println();

client.print("LED . ");

//client.println (""); //submit button
client.print("LED status: ");

if (LEDON == true) {
client.println("ON");

}
else {
client.println("OFF");

}

client.print ("

");
client.print ("<form name=input action= method= get >");

client.print ("

");

client.print ( analog );

client.println("");

readString=""; //clearing string for next read

client.stop(); //stopping client

}}}}}

Any help will be greatly apreciated , Cheers , corey

upload.pde (2.94 KB)

Any help will be greatly apreciated

Somehow, I doubt it, but, here goes.

First, your code is posted improperly. You should be using the # icon (and see [ code ][ /code ] tags (without the spaces)), not the quote icon.

Second, the useless white space in your program makes it hard to read, as does stuff like this:

}}}}}

Each { and } should be on its own line. You need to use Tools + Auto format then to fix the oddball indenting, so the code is readable.

Third, meaningful variable names are important.

       int stringthing = readString.indexOf("="); //here is a key component of where the status is being read by the arduino

That comment means nothing. stringthing? Something more useful, like equalPos, would make it clear that you know what the code is doing.

client.print ("<form name=input action= method= get ><input type= text  name= form  value= 'analog'  /><input type= submit  value= Submit  /></form>");

There is too much wrong with this line to know where to begin. As with code, one statement per line makes reading a lot easier. There are quotes missing from this statement. That the compiler complains when they are added is no excuse for leaving them out. You need to escape them, instead (").

That statement starts and ends the form.

client.print ( analog );

This, then, just puts an unidentified number on the page, below the form. Why?

After you find the equal position (stringthing?), the rest of the string is the value of interest. String::substring() and String::toInt() bear looking at.

Someone else here with a very similar problem