Moving from Xively to Thingspeak - but need basic code advice...

I am using something called a Nanode (discontinued, but is an ATmega with Ethernet) - it uses the standard Arduino IDE…

My question is about sending Ethernet packets - and examples are here → Revisions · Example to use EtherCard on Nanode to upload data to Pachube · GitHub
but of course its 5 years old, and not been updated - but I feel my question is more basic understanding than library internals…

Q: In the code, there is an Ethernet http GET - based upon a prepare statement - I need to send this to THingSpeak (this code is taken from Squirell, which I’m more familiar with) :

local thingSpeakUrl = “”;
function httpPostToThingSpeak(reading) {
local headers = {
“Content-Type” : “application/x-www-form-urlencoded”,
“X-THINGSPEAKAPIKEY” : “<api_key>”
// build the params to go on the URL
local data = “field1=” + reading.temp;
local fullUrl = thingSpeakUrl+"?"+data;
local request = http.get(fullUrl, headers);

and I need to convert to Arduino code…

    byte sd = stash.create();
    stash.print(F("field1="));   //data

    // 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("GET http://$F/update?field6=" +  PSTR(currentRoomTemp) "HTTP/1.0" "\r\n"
                        "Content-Type” : “application/x-www-form-urlencoded" "\r\n"
                        "X-THINGSPEAKAPIKEY: $F" "\r\n"
                        "Content-Length: $D" "\r\n"
            website, PSTR(APIKEY), stash.size(), sd);

Basically, its the prepare statement I (feel) I fundamentally dont understand - as it refers to &F and D and I know $H is the sd stash …

For the service I simply need to send this :

Any and all help appreciated ! :slight_smile:

All these two code snippets appear to be doing is building an HTTP GET statement for ThingSpeak.

In the second snippet, as far as I can see, the Stash::prepare() method takes 5 arguments. The first is a a basic GET statement skeleton. The following 4 arguments e.g. website etc. replace the “$” variables in the first argument in the order that they appear. That is, the value of website (probably something like replaces the first $F in argument 1 etc.

Thanks for the thoughts 6v6gt…
As you mention I’m struggling with the construct for the prepare function.
Does this function really take five arguments, or is it the inclusion of the other (previously unknown to the code $F, $H etc) that determines the following arguments ? When I remove them and provide a single string with no $F etc …but with concatenated strings the compiler complains (not a helpful message though)…

Do you see what I mean.?

Hi Jonandel,

The SW and HW you refer to is indeed discontinued and outdated. I played with this (and a DINo, pretty similar) several years ago, but honestly, that community is close to disintegrated now. I recommend you ditch this and move to sth more modern. Take a look at ESP8266 or Sonoff as a start.

In case I didn't convince you, and you are ready to invest the 100-500 hours of work needed, assuming you have the coding skills, here are a few historical stuff I remember that could tip you to the next stage.

The "stash" thing comes from the efforts of Jean-Claude Wippler to revive an even older library for the ENC28j60. There is still a lot of documentation online, look for "EtherCard" and "jcw". But to be honest, this is all a dead end for one good reason : the 328 found in the Uno simply hasn't enough memory (2kBytes) to handle a TCP or UDP packet in a half-decent way. So Ethercard made use of a "stash" or kind of scrapbook, because the ENC28j60 had more internal memory (8kB IIRC). The IP packet was prepared and bytes were written in that memory before being sent to the network. This means that the HTTP packets could never support anything like JSON formatting, or any kind of security. Even DNS was "complex" in those days.

Regarding the specific question about the prepare function, it takes n+1 arguments, the first argument being the template string with all the $F etc. to be replaced, and then the other arguments being (pointers to) the content to insert in the template. If you look at the library files, you'll see a "..." in the definition of the function. One key is that you have also to calculate the content-length of your packet in advance, or it won't work.

Good luck.