Stash command?

Can someone point me in the right direction for info on the stash command. I am using the Ethercard library and trying to modify the example code to work with Thingspeak. I'm a bit lost with the stash command.

 Stash::prepare(PSTR("PUT http://$F/v2/feeds/$F.csv HTTP/1.0" "\r\n"
                        "Host: $F" "\r\n"
                        "X-PachubeApiKey: $F" "\r\n"
                        "Content-Length: $D" "\r\n"
                        "\r\n"
                        "$H"),
            website, PSTR(FEED), website, PSTR(APIKEY), stash.size(), sd);

Are the $F, $D, $H variables? Where do they get defined?

Here's the full code:
https://github.com/jcw/ethercard/blob/master/examples/pachube/pachube.ino

I am trying to modify it to:

POST /update HTTP/1.1
Host: api.thingspeak.com
Connection: close
X-THINGSPEAKAPIKEY: (Write API Key)
Content-Type: application/x-www-form-urlencoded
Content-Length: (number of characters in message)

field1=(Field 1 Data)&field2=(Field 2 Data)

Well it was easier than I thought - still not sure how/why it works but it does :slight_smile:

  Serial.println("Generate data");
    // generate two fake values as payload - by using a separate stash,
    // we can determine the size of the generated message ahead of time
    byte sd = stash.create();

    stash.print("field1=");
    stash.print((word) millis() / 123);
    stash.print("&field2=");
    stash.print((word) millis() / 456);
    
   
    stash.save();
    
    // generate the header with payload - note that the stash size is used,
    // and that a "stash descriptor" is passed in as argument using "$H"
    Stash::prepare(PSTR("POST /update HTTP/1.1" "\r\n"
                        "Host: $F" "\r\n"
                        "Connection: close" "\r\n"
                        "X-THINGSPEAKAPIKEY: $F" "\r\n"
                        "Content-Type: application/x-www-form-urlencoded" "\r\n"
                        "Content-Length: $D" "\r\n"
                        "\r\n"
                        "$H"),
            website, PSTR(APIKEY), stash.size(), sd);

    // send the packet - this also releases all stash buffers once done
    ether.tcpSend();

What does the documentation say? I'm guessing from what I see there that the function arguments (like "website") are substituted in the first string at places like $F.

I can't find any docs which describe the variables.

I thought so too, but then how come the Host and Apikey both use F$?

OK, here's another guess. For every $F it pulls in the next argument in the argument list as a string, and for $D it inserts it as a decimal (number).

It sounds like it's the same as printf(), i.e. $F, $D, etc. specify argument types and for those arguments you list after the format string are replacing the arguments in the given order.

Proper use of terminology IS important. Stash is NOT a command. It's a class. You've not provided a link to the library that contains that class, so, you are on your own figuring out how it works.

so yes… i also stumbled on this stash thing, found out that it is the order of how the variables are provided afterwards. and the different characters tell it what kind of data it is.

i found out that it must be a function in c general not just the arduino. but it is not documented well. seems like kinda the F function, but i didnt bother to find the differencies between them and manuals for it.

i ve made an example for thingspeak enc28j60 connection.
it is working on my arduino pro-mini_5V-16MHz config.

// Simple demo for feeding some random data to Pachube.
// 2011-07-08 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

// Handle returning code and reset ethernet module if needed
// 2013-10-22 hneiraf@gmail.com

// Modifing so that it works on my setup for www.thingspeak.com.
// Arduino pro-mini 5V/16MHz, ETH modul on SPI with CS on pin 10.
// Also added a few changes found on various forums. Do not know what the 
// res variable is for, tweaked it so it works faster for my application
// 2015-11-09 dani.lomajhenic@gmail.com

#include <EtherCard.h>

// change these settings to match your own setup
//#define FEED "000"
#define APIKEY "BEEF1337BEEF1337BEEF"
#define ethCSpin 10

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
const char website[] PROGMEM = "api.thingspeak.com";
byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;
byte session;

//timing variable
int res = 100; // was 0



void setup () {
  Serial.begin(9600);
  Serial.println("\n[ThingSpeak example]");

  //Initialize Ethernet
  initialize_ethernet();
}


void loop () { 
  //if correct answer is not received then re-initialize ethernet module
  if (res > 220){
    initialize_ethernet(); 
  }
  
  res = res + 1;
  
  ether.packetLoop(ether.packetReceive());
  
  //200 res = 10 seconds (50ms each res)
  if (res == 200) {

    
    //Generate random info
    float demo = random(0,500);
    word one = random(0,500);
    String msje;

    if (demo < 250){
      msje = "low";
    }
    else{
      msje = "high";
    }

    // generate two fake values as payload - by using a separate stash,
    // we can determine the size of the generated message ahead of time
    // field1=(Field 1 Data)&field2=(Field 2 Data)&field3=(Field 3 Data)&field4=(Field 4 Data)&field5=(Field 5 Data)&field6=(Field 6 Data)&field7=(Field 7 Data)&field8=(Field 8 Data)&lat=(Latitude in Decimal Degrees)&long=(Longitude in Decimal Degrees)&elevation=(Elevation in meters)&status=(140 Character Message)
    byte sd = stash.create();
    stash.print("field1=");
    stash.print(demo);
    //stash.print("&field2=");
    //stash.print(one);
    //stash.print("&field3=");
    //stash.print(msje);
    stash.save();

    //Display data to be sent
    Serial.println(demo);


    // generate the header with payload - note that the stash size is used,
    // and that a "stash descriptor" is passed in as argument using "$H"
    Stash::prepare(PSTR("POST /update HTTP/1.0" "\r\n"
      "Host: $F" "\r\n"
      "Connection: close" "\r\n"
      "X-THINGSPEAKAPIKEY: $F" "\r\n"
      "Content-Type: application/x-www-form-urlencoded" "\r\n"
      "Content-Length: $D" "\r\n"
      "\r\n"
      "$H"),
    website, PSTR(APIKEY), stash.size(), sd);

    // send the packet - this also releases all stash buffers once done
    session = ether.tcpSend(); 

 // added from: http://jeelabs.net/boards/7/topics/2241
 int freeCount = stash.freeCount();
    if (freeCount <= 3) {   Stash::initMap(56); } 
  }
  
   const char* reply = ether.tcpReply(session);
   
   if (reply != 0) {
     res = 0;
     Serial.println(F(" >>>REPLY recieved...."));
     Serial.println(reply);
   }
   delay(300);
}



void initialize_ethernet(void){  
  for(;;){ // keep trying until you succeed 
    //Reinitialize ethernet module
    //pinMode(5, OUTPUT);  // do notknow what this is for, i ve got something elso on pin5
    //Serial.println("Reseting Ethernet...");
    //digitalWrite(5, LOW);
    //delay(1000);
    //digitalWrite(5, HIGH);
    //delay(500);

    if (ether.begin(sizeof Ethernet::buffer, mymac, ethCSpin) == 0){ 
      Serial.println( "Failed to access Ethernet controller");
      continue;
    }
    
    if (!ether.dhcpSetup()){
      Serial.println("DHCP failed");
      continue;
    }

    ether.printIp("IP:  ", ether.myip);
    ether.printIp("GW:  ", ether.gwip);  
    ether.printIp("DNS: ", ether.dnsip);  

    if (!ether.dnsLookup(website))
      Serial.println("DNS failed");

    ether.printIp("SRV: ", ether.hisip);

    //reset init value
    res = 180;
    break;
  }
}

PaulS
Ow… get real. arduino is also a project for beginners. they do not need proper terminology… but even if…

I was reading nodeMCU community the other day… they are having modules, arduino is having libraries, and in windows its called drivers

and yes he did stated that it is from the enc28j60 library called “ethercard” (.h)

GregM:
Can someone point me in the right direction for info on the stash command. I am using the Ethercard library and trying to modify the example code to work with Thingspeak. I’m a bit lost with the stash command.

 Stash::prepare(PSTR("PUT http://$F/v2/feeds/$F.csv HTTP/1.0" "\r\n"

“Host: $F” “\r\n”
                        “X-PachubeApiKey: $F” “\r\n”
                        “Content-Length: $D” “\r\n”
                        “\r\n”
                        “$H”),
            website, PSTR(FEED), website, PSTR(APIKEY), stash.size(), sd);




Are the $F, $D, $H variables? Where do they get defined?

Here's the full code:
https://github.com/jcw/ethercard/blob/master/examples/pachube/pachube.ino

I am trying to modify it to:



POST /update HTTP/1.1
Host: api.thingspeak.com
Connection: close
X-THINGSPEAKAPIKEY: (Write API Key)
Content-Type: application/x-www-form-urlencoded
Content-Length: (number of characters in message)

field1=(Field 1 Data)&field2=(Field 2 Data)