Help with a little code please

Could anyone please tell me what the following code does pls; ether.browseUrl(PSTR("/foo/"), "bar", website, my_callback);

I can work out that 'website' = the website address, and 'my_callback' is a routine to analyse the results, and suspect that 'ether.browseUrl' directs a visit to the 'website' URL. But I don't know what 'PSTR' is, and what does "/foo/" and "bar" relate to. ( I realize that they are example terms!)

Thanks Paul

PSTR(“a string”) means that “a string” is stored in program (flash) memory instead or RAM. As you haven’t said what library the browseUrl() function is from, and it isn’t from the standard Arduino Ethernet Shield library, I can’t offer any more help than this.

Sorry, the code is from which is the jeelabs ethercard library. I am trying to develop a 'watchdog' which checks a website, and unless the reply is '?HTTP/1.1 200 OK' , then a reset is made. Similar to what is described here -

Unfortunately, the author of that library does not appear to have provided any documentation. I couldn't even find a single source code comment line explaining what the function is supposed to do or what the parameters represent. So I suggest you ask the author, or look for a different library with better documentation.

I slightly suspect that it looks in a directory 'foo' for a file named 'bar', but that's pretty much a guess!

Many thanks for trying though.


The parameter names "urlbuf" and "urlbuf_varpart" do suggest that the "/foo/" and the "bar" get concatenated to construct a url. I expect the idea is that you can put the unchanging part of the URL in PROGEM to save on RAM usage.

The few examples I can find on the web suggest that the /foo/ part is the directory path of the URL and the bar is any optional arguments or whatever else that are passed. e.g. this example:

ether.browseUrl(PSTR("/channels/1417/field/1/last.txt"), "", thingSpeakAddress, my_callback);

has an example of a path to a filename with no extra arguments on the URL. If you don't need the extra arguments anyway then this could be used as a template for what you are trying to do. NOTE that the third argument, the address, must also be a PROGMEM string (as shown in the complete web client demo).


Well researched! I never thought of looking at Thingspeak! That does seem to make sense, so I need to identify a 'permanent' website file address at Pachube which can be accessed to confirm a connection. ...and the "", presumably means if the file last.txt file is found then no further arguments are required.


I think, as dc42 says, the /foo/ and bar are concatenated so that once the website has been contacted what is sent is /foo/bar. In one of the websites I found, someone was trying to upload some sensor readings to a webpage and in that case the readings were something like "1.2 3.0 7.9" and were passed as the "bar" string. In the example I posted, there was no need for that extra argument because there was a direct request for a text file (last.txt) which didn't require any arguments. In that case you have to pass a null string "" as the argument. I think the reason for the way the browseUrl arguments are laid out is that, first of all, the URL itself (third argument) is likely to be constant and is therefore made a PSTR which cannot be changed (it is in read-only program memory). Similarly, although you might want to use a few different pathname strings you wouldn't normally have a lot of them, so that is also a PSTR. Requiring that these more-or-less constant strings be PSTR helps you conserve the small amount of SRAM available to a program (on Duemilanove it is 2kB). But the optional argument string could change on every call - as in the example above which uploads sensor data. In that case because the string is dynamic it is just a regular string which is stored in sram.