Pages: 1 [2]   Go Down
Author Topic: how to get value for textbox  (Read 4078 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
              I change my code as you see but i don't know how to split text .

Quote
void loop()
{
  char* params;
 
if (params = server.serviceRequest())
  {
server.print("<html>");
server.print("<head>");
server.print("<title>My Page</title>");
server.print("</head>");
server.print("<body>");
server.print("<form name=myform  method=get action="">");
server.print("<div align=center>");
server.print("<br><br>");
server.print("<input type=text name=textbox size=2 >");
server.print("<br><input type=submit value=Set><br>");
server.print("</div>");
server.print("</form>");
server.print("</body>");
server.print("</html>");

//uint16_t a=atoi(params);

    server.print("Parasms is :");
    server.print(params);
//display_digit(a);
   server.respond();
  }
This picture


 in picture , I need get "12" only  but how to?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I already get value for textbox by split method  as this code
Quote
void loop()
{
  char* params;
  char piece1[20] = ""
    ,piece2[20] = "";
char * p;
if (params = server.serviceRequest())
  {
server.print("<html>");
server.print("<head>");
server.print("<title>My Page</title>");
server.print("</head>");
server.print("<body>");
server.print("<form name=myform  method=get action="">");
server.print("<br><br>");
server.print("<input type=text name=textbox size=2 >");
server.print("<br><br><input type=submit value=Set><br>");
server.print("</form>");
server.print("</body>");
server.print("</html>");



p = strtok (params,"="); // call the strtok with str as 1st arg for the 1st time.
if (p != NULL) // check if we got a token.
{
    strcpy(piece1,p); // save the token.
    p = strtok (NULL, "="); // subsequent call should have NULL as 1st arg.
    if (p != NULL) // check if we got a token.
        strcpy(piece2,p); // save the token.
}

//uint16_t a=atoi(params);

    server.print("Parasms is :");
   // server.print(params);
   server.print(piece2);
//display_digit(a);
   server.respond();
  }
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You've been at this long enough to have learned how to post code. Use the # button, not the quote button.

Your form definition is still wrong!
server.print("<form name=\"myform\" action=\"\">");
The quotes ARE important! Type, name, and value values ALL need to be in quotes, and the quotes need to be escaped, so that they are no interpreted as the end of the string.

There is nothing in your text box, in your picture. There are no serial print statements to show the value in params or p.
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Text box test code.

Code:
//zoomkat 4-05-12
//web LED 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 ')
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//turns pin 5 on/off

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

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

String readString;

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

void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  //enable serial data print
  Serial.begin(9600);
  Serial.println("servertest1"); // 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); //print what server receives to serial monitor
        }

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

          ///////////////
          Serial.println(readString);

          //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=\"http://192.168.1.102:84\" method=get >");

          client.println("Pin 5 \"on\" or \"off\": <INPUT TYPE=TEXT NAME=\"LED\" VALUE=\"\" SIZE=\"25\" MAXLENGTH=\"50\"><BR>");

          client.println("<INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Change Pin 5!\">");

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

          client.println("<BR>");

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

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

          /////////////////////
          if(readString.indexOf("on") >0)//checks for on
          {
            digitalWrite(5, HIGH);    // set pin 5 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(5, LOW);    // set pin 5 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8695
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  Ethernet.begin(mac, ip, gateway, subnet);

Doesn't Arduino 1.0 require:  Ethernet.begin(mac, ip, DNS_SERVER, gateway, subnet); ?

If you leave out the DNS_SERVER address it's going to use the 'gateway' address for DNS (which will probably work) and the subnet mask for the gateway address (which certainly won't work).

If you specify only MAC address it will use DHCP for everything else.

If you specify MAC address and local IP address (W.X.Y.Z) it will use W.X.Y.1 for DNS and gateway and 255.255.255.0 for the subnet.

If you specify MAC address, local IP address, and DNS address (A.B.C.D)  it will use A.B.C.D for gateway and 255.255.255.0 for the subnet.

If you specify MAC address, local IP, DNS, and gateway it will use 255.255.255.0 for the subnet.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Doesn't Arduino 1.0 require:  Ethernet.begin(mac, ip, DNS_SERVER, gateway, subnet); ?

I tested the code before I posted it and it worked, but YMMV for your setup. I would followup more on this, but my laptop has developed overheating issues that make posting very difficult.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Hi, I have the "
ENC28J60 Ethernet. "As it is for
read and write from the processing?


Logged

0
Offline Offline
Sr. Member
****
Karma: 7
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is a working example showing 3 text boxes for RGB values, when submitted it sets the pwm values of pins 3,5 & 6

This code works on wiznet shield and compiled with IDE_0018, yes its 0018 don't mention Arduino 1.0, if it aint broke why fix it

Code:
#include <Ethernet.h>
#include <WString.h>
#include <Wire.h>
#define maxLength 25

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 2, 20 };
String inString = String(maxLength);
int val;
int r;
int g;
int b;
Server server(80);

void setup()
{
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.begin(9600);
}
void loop()
{
  Client client = server.available();
  if (client) {
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.print(c);
        if (inString.length() < maxLength) {
          inString.append(c);
         }       
        if (c == '\n' && current_line_is_blank) {
          if (inString.contains("?")) {
           int Pos_r = inString.indexOf("r");
           int Pos_g = inString.indexOf("g");
           int Pos_b = inString.indexOf("b");
           int End = inString.indexOf("H");
           r = atoi(inString.substring((Pos_r+2), (Pos_g-1)));
           g = atoi(inString.substring((Pos_g+2), (Pos_b-1)));
           b = atoi(inString.substring((Pos_b+2), (End-1))); 
          analogWrite(6, r);   
          analogWrite(5, g);
          analogWrite(3, b);
         }
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<html><head></head><body>");
          client.println("<h1><CENTER>Aduino & Ethershield Webserver</CENTER></h1>");
          client.println("<CENTER><form method=get>R:<input type=text size=3 name=r>G:<input type=text size=3 name=g>B:<input type=text size=3 name=b>&nbsp;<input type=submit value=submit></form></CENTER></body></html>");     
          break;
        }
        if (c == '\n') {
          current_line_is_blank = true;
        } else if (c != '\r') {
          current_line_is_blank = false;
        }
      }
    }
    delay(1);
    inString = "";
    client.stop();
  }
}
Logged

Pages: 1 [2]   Go Up
Jump to: