Go Down

Topic: Sending to client (Read 480 times) previous topic - next topic

kensington

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 :
 ");
client.println(" Homerseklet :
 ");
client.println(" Beallitas :
 ");
client.println("</FIELDSET> ");
client.println("
 ");
client.println("
 ");
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\">
 ");
client.println("  21 celsius fok : <INPUT type=\"radio\" name=\"beall\" value=\"21\">
 ");
client.println("  20 celsius fok : <INPUT type=\"radio\" name=\"beall\" value=\"20\">
 ");
client.println("  19 celsius fok : <INPUT type=\"radio\" name=\"beall\" value=\"19\">
 ");
client.println("  18 celsius fok : <INPUT type=\"radio\" name=\"beall\" value=\"18\">
 ");
client.println("  17 celsius fok : <INPUT type=\"radio\" name=\"beall\" value=\"17\">
 ");
client.println("  Kikapcsol : <INPUT type=\"radio\" name=\"beall\" value=\"0\">
 ");
client.println("  Vissza : <INPUT type=\"radio\" name=\"beall\" value=\"-\">
 ");
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!

MarkT

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.
[ I won't respond to messages, use the forum please ]

gardner

What model of Arduino is this on?

I suspect you are running out of memory.

Code: [Select]
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.

zoomkat

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?
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Go Up