Using a web interface to change variable values

Hello,

I'm not very well versed in programming, but with a little direction I can handle it. I've been searching and haven't found information on this particular subject.

So, what I've already got an arduino sketch set up to feed information to an SQL database on my computer across the LAN. The data thus far is ambient temperature outside. I'm using the data sent to the database and presenting it in a graph on a web page. I'm hoping to further this and be able to change values of a variable using a web interface. For instance changing the number of temperature sensors that are being read.

I'm looking to be able to change these on the fly as opposed to uploading another sketch. Is this possible?

You might in code like below, set the number of channels to read to a variable instead of a static 6 like below. Send a get request with the desired value to the arduino server so the variable channel value will change to what is in the GET request.

          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(analogRead(analogChannel));
            client.println("
");

By the arduino server, do you mean the web server the arduino is interfacing with? Also your code is doing analogreads, forgive me if I'm wrong but doesn't the ethernet shield use digital pins?

Maybe I wasn't entirely clear about what I'm looking to do. I'm hoping to create a web interface that I can manipulate the Arduino with. From further looking around I see that the Yun seems capable of these types of tasks. Is the Arduino Mega even capable of handling this type of functionality?

The arduino with an ethernet shield can act as both a web server and web client. You need to figure out what your server functions and client functions will be.

Is there some examples how to change variable values in Arduino using Ethernet shield?

tolerance_zero:
Is there some examples how to change variable values in Arduino using Ethernet shield?

I think the below pretty much does that.

//zoomkat 6-13-15
//get submit box code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html or use a '
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//Powering a servo from the arduino usually *DOES NOT WORK*.

#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 
//int n; //value to write to servo

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 
  192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 
  192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

String readString, newString;

//////////////////////

void setup(){

  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7, 500, 2500);  //the pin for the servo control, and range if desired
  Serial.println("server text box servo test"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 

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

          ///////////////
          Serial.print(readString); //see what was captured

          //now output HTML data header

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>HTML form GET example</H1>");

          client.println("<FORM ACTION='/' method=get >"); //uses IP/port of web page

          client.println("Set servo position: <INPUT TYPE=TEXT NAME='LED' VALUE='' SIZE='25' MAXLENGTH='50'>
");

          client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='Send servo position'>");

          client.println("</FORM>");

          client.println("
");

          client.println("</BODY>");
          client.println("</HTML>");

          delay(1);
          //stopping client
          client.stop();

          /////////////////////
          if (readString.length() >0) {
            //Serial.println(readString); //prints string to serial port out
            int pos1 = readString.indexOf('=');
            int pos2 = readString.indexOf('&');
            newString = readString.substring(pos1+1, pos2);
            Serial.print("newString is: ");
            Serial.println(newString);
            int n = newString.toInt();
            Serial.print("The value sent is: ");
            Serial.println(n);
            readString=""; //clears variable for new input    
            newString=""; //clears variable for new input
            // auto select appropriate value
            if(n >= 500)
            {
              Serial.print("writing Microseconds: ");
              Serial.println(n);
              myservo.writeMicroseconds(n);
              Serial.println();
            }
            else
            {   
              Serial.print("writing Angle: ");
              Serial.println(n);
              myservo.write(n); 
              Serial.println();
            }
          }           
        }
      }
    }
  }
}

You can implement it looking for the server for new values/config.
Check the logic described here
http://forum.arduino.cc/index.php?topic=161738.msg3141623#msg3141623