Pages: [1]   Go Down
Author Topic: Sending to client  (Read 321 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

We have a problem with sending a form to a web-browser client. Our source:

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

void getDeviceNumber(char c,byte* cd,boolean* megvan2){
  static boolean megvan=false;
  static byte kar=0;
  if (!*megvan2){
   if(megvan){
    c-=48;
    *cd=c;
    c+=48;
    megvan=false;
    *megvan2=true;
   }
   switch(kar){
    case 0:
     if (c=='l'){
      kar+=1;
     }
     break;
    case 1:
     if (c=='e'){
      kar+=1;
     }
     else
      kar=0;
     break;
    case 2:
     if (c=='l'){
      kar+=1;
     }
     else
      kar=0;
     break;
    case 3:
     if (c=='i'){
      kar+=1;
     }
     else
      kar=0;
     break;
    case 4:
     if (c=='s'){
      kar+=1;
     }     
     else
      kar=0;
     break;
    case 5:
     if (c=='='){
      kar=0;
      megvan=true;
     }
     else
      kar=0;
     break;
  }
 }
}
 
 // még nem jó
void getSetting(char c,byte* cd,boolean* megvan2){
  static boolean megvan=false;
  static byte kar=0;
  if (!*megvan2){
   if(megvan){
    c-=48;
    *cd=c;
    c+=48;
    megvan=false;
    *megvan2=true;
   }
   switch(kar){
    case 0:
     if (c=='l'){
      kar+=1;
     }
     break;
    case 1:
     if (c=='e'){
      kar+=1;
     }
     else
      kar=0;
     break;
    case 2:
     if (c=='l'){
      kar+=1;
     }
     else
      kar=0;
     break;
    case 3:
     if (c=='i'){
      kar+=1;
     }
     else
      kar=0;
     break;
    case 4:
     if (c=='s'){
      kar+=1;
     }     
     else
      kar=0;
     break;
    case 5:
     if (c=='='){
      kar=0;
      megvan=true;
     }
     else
      kar=0;
     break;
  }
 }
}

void sendHTTPOK(Client& client){
 client.println("HTTP/1.1 200 OK");
 client.println("Content-Type: text/html");
 client.println();
}

void sendDeviceSelection(Client& client){
 String options="";
 options+="<FORM action=\"ardunio\" method=\"GET\">  <FIELDSET style=\"width:150\">  <LEGEND> Valaszd ki az eszkozt:</LEGEND> <SELECT name=\"lelis\" size=\"1\"> <OPTION value=\"0\"> 0 <OPTION value=\"1\"> 1 <OPTION value=\"2\"> 2 <OPTION value=\"3\"> 3 <OPTION value=\"4\"> 4 <OPTION value=\"5\"> 5 </SELECT> &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; <INPUT type=\"submit\" value=\"Mehet!\"> </FIELDSET> </FORM>Ö";
 client.println(options);
 options="";
}

void sendDeviceInfo(Client& client,byte currentDevice,byte* currDev){
 client.println("<FIELDSET style=\"width:150\"> ");
 client.println(" Eszkoz : <br> ");
 client.println(" Homerseklet : <br> ");
 client.println(" Beallitas : <br> ");
 client.println("</FIELDSET> ");
 client.println("<br> ");
 client.println("<br> ");
 client.println("<FORM action=\"myForm\" method=\"GET\"> ");
 client.println(" <FIELDSET style=\"position:absolute; top:8; left:220; width:150;\"> ");
 client.println("  22 celsius fok : <INPUT type=\"radio\" name=\"beall\" value=\"22\"> <br> ");
 client.println("  21 celsius fok : <INPUT type=\"radio\" name=\"beall\" value=\"21\"> <br> ");
 client.println("  20 celsius fok : <INPUT type=\"radio\" name=\"beall\" value=\"20\"> <br> ");
 client.println("  19 celsius fok : <INPUT type=\"radio\" name=\"beall\" value=\"19\"> <br> ");
 client.println("  18 celsius fok : <INPUT type=\"radio\" name=\"beall\" value=\"18\"> <br> ");
 client.println("  17 celsius fok : <INPUT type=\"radio\" name=\"beall\" value=\"17\"> <br> ");
 client.println("  Kikapcsol : <INPUT type=\"radio\" name=\"beall\" value=\"0\"> <br> ");
 client.println("  Vissza : <INPUT type=\"radio\" name=\"beall\" value=\"-\"> <br> ");
 client.println("  <INPUT type=\"submit\" value=\"Beallit!\"> ");
 client.println(" </FIELDSET> ");
 client.println("</FORM> ");
}


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1, 177 };
byte mask[]= {255,255,255,0};
byte gateway[] ={192,168,1,1};
byte currentDevice=0;
boolean megvan=false;
byte currDev[6] = { 0,0,0,0,0,0 };
byte whichForm=1;

Server server(80);

void setup()
{
 Ethernet.begin(mac, ip, gateway, mask);
 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();
       
       if (c == '\n' && current_line_is_blank)
       {
         whichForm=1-whichForm;
         megvan=false;
         sendHTTPOK(client);
         if (whichForm==0)
          sendDeviceSelection(client);         
         else
          sendDeviceInfo(client,currentDevice,currDev);
         break;
       }       
       if (c == '\n')
       {
        current_line_is_blank = true;
       }
       else if (c != '\r')
       {
        if (whichForm==0)
         getDeviceNumber(c,&currentDevice,&megvan);
        else
         //getSetting();
         ;
        current_line_is_blank = false;
       }
     }
   }
   client.stop();
   
 }
}

And the web-browser source:

<FORM action="ardunio" method="GET">  <FIELDSET style="width:150">  <LEGEND> Valaszd ki az eszk#ńŐŐř

The sending fails everytime.
Please help!
Thanks!
Logged

0
Offline Offline
Shannon Member
****
Karma: 162
Posts: 10523
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Firstly I would advise using a decent debugger on the browser - Firebug for Firefox for example - so you can show us the HTTP packets going to and fro.

And liberally add debugging Serial.print statements in the Arduino code to see how its behaving in detail.

And use the '#' button to add code to your postings.
Logged

[ I won't respond to messages, use the forum please ]

Ontario
Offline Offline
God Member
*****
Karma: 20
Posts: 835
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What model of Arduino is this on?

I suspect you are running out of memory.

Code:
String options="";
 options+="<FORM action=\"ardunio\" method=\"GET\">  <FIELDSET style=\"width:150\">  <LEGEND> Valaszd ki az eszkozt:</LEGEND> <SELECT name=\"lelis\" size=\"1\"> <OPTION value=\"0\"> 0 <OPTION value=\"1\"> 1 <OPTION value=\"2\"> 2 <OPTION value=\"3\"> 3 <OPTION value=\"4\"> 4 <OPTION value=\"5\"> 5 </SELECT> &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; <INPUT type=\"submit\" value=\"Mehet!\"> </FIELDSET> </FORM>Ö";

This one string is ~350 bytes, and then you go and make a copy of it in "options".  35% of your memory in one statement.
sendDeviceInfo() burns another approx 840 bytes.

Between them that's 75% of your RAM gone in just a few lines of code.

I would recommend looking up PROGMEM and making an effort to put all your constant strings in flash.  I would also avoid using String myself, but that's just because I deeply distrust anything that uses malloc() in Arduino.
Logged

0
Offline Offline
Tesla Member
***
Karma: 118
Posts: 8967
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
We have a problem with sending a form to a web-browser client.

So what do you expect to happen that is not working? Can you get a simplified version of your code to work?
Logged

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

Pages: [1]   Go Up
Jump to: