Pages: [1]   Go Down
Author Topic: ethnet shield and big page html to send  (Read 514 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 112
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

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);
« Last Edit: December 15, 2013, 04:59:19 pm by tymop » Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 112
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 76
Posts: 2247
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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;
};
Logged


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

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

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

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
Logged

Pages: [1]   Go Up
Jump to: