Go Down

Topic: ethnet shield and big page html to send (Read 712 times) previous topic - next topic

tymop

Dear all,
I expexct I write this question in the good forum.

I would like to write a big web page to send to a client.
I use the library ETHER_28J60 (this is the ethernet shiels connected : http://www.dipmicro.com/store/ENC28J60-MINI-MOD)

So, I create my answer like that:

Quote
ETHER_28J60 ethernet; // creating the client
ethernet.print("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");// Creating the answer
ethernet.print("..."); //etc ...
ethernet.print("..."); //etc ...
ethernet.print("..."); // etc ...


When the answer is bigger that 500 bytes (aproximately), the answer is not made. I think there is a buffer somewhere which limit the answer size.

So, I would like to know if there is any functions which permit to generate a "Big" answer.

Thanks a lot for your help.

paulinchen

Hi,
i don't use this library, but the "normal" ethernetshield.

You should not use the ethernet.print("...");

Please use instead:

1. define a array:               char buffer [256];
2. fill the array:                  strcpy(buffer, "...");
3. write the array:            ethernet.write(buffer);

Because with the print command you send one packet per char, with the write command you can send many chars with 1 packet, the header-overhead is very reduced.

paulinchen

tymop

#2
Dec 15, 2013, 10:19 pm Last Edit: Dec 15, 2013, 10:59 pm by tymop Reason: 1
OK, I can try what you say, but I don't understand how I can send more than the 256 char of the buffer ?
I have another problem : my shield does not work with the library ethernetshiels, or I do not use it well.

Quote
1. define a array:               char buffer [256];
2. fill the array:                  strcpy(buffer, "...");
3. write the array:            ethernet.write(buffer);

paulinchen

You can make the buffer bigger or you can send also more than 1 buffer:

char buffer [256];

strcpy(buffer, "...");
ethernet.write(buffer);
strcpy(buffer, "...");
ethernet.write(buffer);
strcpy(buffer, "...");
ethernet.write(buffer);
...

paulinchen

pYro_65

I have made a buffered printer class snippet for doing this automatically. It will allow you to still use print/println so you do not need to use strcpy to build strings.

The little snippet above becomes:
Code: [Select]
char buffer [256];
BufferedPrinter Buff( ethernet, buffer, 256 );

Buff.print( "..." );
Buff.print( "..." );
Buff.print( "..." );
Buff.flush();


You only need to call flush at the end. When the buffer is filled through normal printing it will be written out as one chunk automatically ( calls x.write() ).

The best part is print/println support a lot of conversions (integer/float) and the ability to print from PROGMEM. Loosing that functionality removes a significant ease of use.

Here is the class ( I just modified it for large sized buffers ):
Code: [Select]
class BufferedPrinter : public Print{

  public:
 
    BufferedPrinter( Print &p_Out, uint8_t *u_Buff, int i_Len ) : Output( p_Out ), Buff( u_Buff ), Cursor( 0x00 ), Max( i_Len ) {}
     
    ~BufferedPrinter( void ) { flush(); }
     
    void flush()
      {
        if( Cursor )
          Output.write( Buff, Cursor ); 
        Cursor = 0x00;
      }
     
    size_t write( uint8_t u_Data )
      {
        if( Cursor == Max ){
          Output.write( Buff, Cursor );
          Cursor = 0x00;
        }
        Buff[ Cursor++ ] = u_Data;
        return 0x01;
      }
     
  protected:
 
    Print &Output;
    uint8_t *Buff;
    int Cursor;
    int Max;
};

tymop

Thanks all for your answers.
But I think your solutions are not able with my ethernet hardware.

tymop

I found a solution described here for these who will need the same thing:
install the library https://github.com/ntruchsess/arduino_uip : it is compatible with the Enc28J60 http://www.dipmicro.com/store/ENC28J60-MINI-MOD

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy