EtherCard: relationship between Stash and ether.buffer – JeeLabs Café – JeeLabs . net

I’d like to understand the EtherCard Stash concept better. I’ve read the source code enough that I think I understand the concept, but I’m more of a C guy than a C++ guy so I get a little bit lost in the inheritance from Print. My understanding is that it is meant to store the body of a TCP packet (e.g. an HTTP POST) in the ENC28J60’s RAM. I’ve recently written some EtherCard code that tries to take advantage of it by doing something like the following code snippet:

  byte Ethernet::buffer[800];
  Stash stash;
  byte session_id = 0;

  void postToWeb(){

    byte sd = stash.create();

    for(int ii = 0; ii < SOME_NUMBER; ii++){
      stash.println(ii);
    }

    stash.save();
    Stash::prepare(PSTR("POST /blah HTTP/1.1\r\n"
                        "Host: $F" "\r\n"
                        "Content-Length: $D" "\r\n"
                        "\r\n"
                        "$H"),
                   PSTR("google.com"), stash.size(), sd); 

    session_id = ether.tcpSend();  
    Serial.println(F(" >>> Message Sent"));
  }

  // the usual controller setup and loop: 
  //   ether.packetLoop(ether.packetReceive());
  //   const char* reply = ether.tcpReply(session_id);
  //   if(reply != 0) Serial.println(F(" <<< Response Received"));

Now, seemingly, depending on the size of SOME_NUMBER the tcpSend() doesn’t actually result in a transmission on the wire. There is rather some semblance of a TCP connection starting up, but it never establishes, and I get some pretty interesting side effects. For example, ether.isLinkUp() will start reporting false, suggesting that I’ve really made the ENC28J60 unhappy, and the only way back is a restart. When I was printing out stash.size() before sending, the point of no return seemed to be related to the Ethernet::buffer size, but I didn’t see how.

So, please when you have some spare time, could you try and explain the Stash concept in more detail, how it relates to the Ethernet::buffer and/or the BufferFiller class if at all, what kind of limitations need to be respected and in what way my code snippet above is violating them? I hesitated to write this up as an issue on git-hub until I really understood what was happening and that it wasn’t PEBKAC.

Thanks and Merry Christmas!

Vic

Source: EtherCard: relationship between Stash and ether.buffer – JeeLabs Café – JeeLabs . net

EtherCard: relationship between Stash and ether.buffer – JeeLabs Café – JeeLabs . net was last modified: July 13th, 2017 by Jovan Stosic