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 sensorString 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 EthernetpinMode(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 stringif (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 onLEDON = true;
}if (readString.indexOf( "off") >0) {
//led has to be turned OFF
digitalWrite(ledPin, LOW); // set the LED OFFLEDON = 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)