Page 1 of 1

CSV File consistent output

Posted: Mon Jul 05, 2010 2:30 pm
by gibsonmb
I need to call a url that provides a single row of values each time it is called. The following provides a single row of data sometimes, two rows at other times and then somtimes no rows of data. I am sure this is to do with "timeframe" and "res" values. Can somebody tell me what to set these to, to make sure I get one row of values every time. My Meteohub is uploading to the Meteoplug server every 10 minutes. I'm not sure this latter piece of info is relevent. You can see what this produces at the follwoing url:

https://www.meteoplug.com/cgi-bin/meteo ... f5eafafef1

timeframe=700s
res=30s

gtitle=WD-Export # name of graph
gtype=export # type of graph
glunit=_ # delimiter
grunit=%-d_%-m_%Y_%-H_%-M # date/time stamp
gtrim=1 # cut empty records at start and end

sid0=th0 sname0=-999 ssel0=temp sprec0=1 # temp
sid1=th0 sname1=-999 ssel1=hum sprec1=0 # hum
sid2=thb0 sname2=-999 ssel2=seapress sprec2=1 # sea pressure
sid3=wind0 sname3=-999 ssel3=wind sfactor3=1.944 sprec3=1 # wind
sid4=wind0 sname4=-999 ssel4=maindir sfactor4=22.5 sprec4=0 # wind direction
sid5=sol0 sname5=solar ssel5=rad # sensor 0, radiation

I want to use this to feed Pachube

Re: CSV File consistent output

Posted: Mon Jul 05, 2010 9:47 pm
by admin
a) res=30s is not defined, Meteoplug has "min5" as a minimum.

b) graph type "export" is designed to print out all data in the given time frame. That can be one, more or Null lines depending on whether Meteoplug has already received data from the client for the requested period of time.

I would propose to make use of template replacement, which gives you access to last received, most actual data. Just place a template file somewhere in the web and do reference it from a Meteoplug template definition. Have a look here for details: http://wiki.meteoplug.com/Gallery#Templates

Variable definitions in templates allow for a default value (if no value found), allow for a precision setting and for factors and offsets like in graphs. Details are explained here: http://wiki.meteoplug.com/Define_Chart# ... e_Settings

You don't have to make it a true html file, just design it the way it fits your Pachube upload demands. Please don't poll this more often than your client uploads data to Meteoplug, you will just put load on the server without seeing more actual data.

Re: CSV File consistent output

Posted: Tue Jul 06, 2010 9:09 am
by gibsonmb
When Pachube calls the url, it needs a single line CSV response, no HTML. You cannot create clever web page requests with data substituition in Pachube and you just need to return a single row of data. Thanks for pointing out the 30s mistake. I still need a simple single row of data returned. Pachube polls every 5 minutes, that as far as I can see is not adjustable. Still need help.

regards

Mike

Re: CSV File consistent output

Posted: Tue Jul 06, 2010 1:18 pm
by skyewright
gibsonmb wrote:...you just need to return a single row of data.
And you can do exactly that with templates.

With templates you are just setting up something that will be delivered as text. That text might be HTML markup, but it can just as easily be csv data (which is just text set out in a particular way).

e.g. a template file containing

Code: Select all

[actual_min5_th0_temp_1:--],[actual_min5_th0_hum_0:--]
Would give you a 1 line, 2 column csv, with a temp in the first column and a humidity in the second.

You save the above as a file somewhere accessible to the Meteoplug server (e.g. on your own website), then set up a "chart definition" in Meteoplug that refers to that file.=, e.g.

Code: Select all

template=http://www.gibsonmb-domain.com/pachube.csv
content=text/plain
Later Edit: Make sure that your template file uses a name that ends in html, even if what you want to end up with will be somthing else (e.g. a csv, as in this case). So my example should read:
template=http://www.gibsonmb-domain.com/pachube.html


The second line in the definition might not be necessary (Pachube may just assume that the file is text/plain even if it has the default text/html MIME type), but I've added it "just in case".

The URL that you give Pachube is the URL that is offered when you use "Show Chart" in Meteoplug for your new definition.

Does that make more sense now?

Re: CSV File consistent output

Posted: Tue Jul 06, 2010 6:49 pm
by gibsonmb
Thanks David, that does make sense, I'll go have a play and see if I can get this working (if I can leave my Arduino alone that arrived today)!!!!

Re: CSV File consistent output

Posted: Tue Jul 06, 2010 8:34 pm
by admin
thanks david, perfectly explained.

Re: CSV File consistent output

Posted: Wed Jul 07, 2010 9:13 pm
by gibsonmb
I played with your gallery examples some more after writing this post and fixed it, the file type has to be .html. It cannot be .txt or .csv. This is really powerful, time to have some fun.

I tried the above and this is what I got when clicking on 'display' on the Meteoplug server define graphs;

Error: Cannot receive data from url: http://home.btconnect.com/gibsonsathome/pachube.csv

Here is the content of the text file which I've kept as per the example abvoe to keep it simple for now.

[actual_min5_th0_temp_1:--],[actual_min5_th0_hum_0:--]

It is a valid site that you can get to as you can see below if you just drop the filename

http://home.btconnect.com/gibsonsathome

Any ideas?

Mike

Re: CSV File consistent output

Posted: Thu Jul 08, 2010 5:10 pm
by skyewright
gibsonmb wrote:I played with your gallery examples some more after writing this post and fixed it, the file type has to be .html. It cannot be .txt or .csv..
Opps. That what comes from writing code direct into a reply without testing, just based on what you recall doing. :oops:
Oh well, you got there in the end. :) I'll add a note to earlier example to cover this in case anyone comes across this thread at a late date.