Go Down

Topic: How to get a CGI script working on Yun Rev2 (Read 420 times) previous topic - next topic

ottsm

I'm trying to understand how to get cgi scripts running on my Yun Rev 2.

I can see that the cgi-bin directory is under;
root@Arduino:/www/cgi-bin

I want the cgi scripts to be able to see file paths located on my SD card such as;
root@Arduino:/mnt/sda1/arduino/www
I made the www directory under the arduino and on the web browser if I type 192.168.0.xx/sd/ it will run the index.html file that I made.
the /sd is linked with the root via
root@Arduino:/www/sd

Every time I place a cgi file in the cgi-bin and try and run it I get the following error;
Unable to launch the requested CGI program:
  /www/cgi-bin/rrd.cgi: No such file or directory

I've been trying to follow something similar to what was done here;
https://github.com/cydergoth/yun_monitor
Except I'm not using collectd, instead I'm collecting temperature data in the rrd database out of the arduino.


the cgi script looks like the following, and rrdcgi has been installed;

#!/usr/bin/rrdcgi
<html>

<head>
   <title>Temperature Data</title>
</head>

<body>

   <h1>Welcome to Temperature Data</h1>

   <p>
   <RRD::GRAPH
   --imginfo '<IMG SRC=/sd/%s WIDTH=%lu HEIGHT=%lu >'
   /www/sd/HouseData.png --lazy --title="Temperatures"
   DEF:Temp2_01=/mnt/sda1/arduino/HouseData/TrendData.rrd:Temp2_01:AVERAGE
   DEF:Temp2_02=/mnt/sda1/arduino/HouseData/TrendData.rrd:Temp2_02:AVERAGE
   LINE1:Temp2_04#ff3030:"Humdity1"
   LINE1:Temp2_08#ff9900:"Humdity2"
   >
   </p>
</body>
</html>

 

ShapeShifter

I've not tried using the cgi folder, so I can't answer your direct question. But I have done something similar, and offer a link to an alternate way of getting it done: HowTo: Using RRD - Round Robin Database

In that project, I use RRD to collect data, and than use the Bottle framework to create a web site to control the project and view graphs of the collected data. It has worked very well for me.

ottsm

Thanks for the information, I've started reading the older post you mention and hopefully I can figure something better out then what I'm currently doing. 

Currently I also have an RRD database based off version 1.2.30-3.  I have older Dragino Yun Shields that had this version built in the software packages.  This version had more options when producing the png image then rrdtool1.  The new Yun Rev 2 with openwrt only has rrdtool1 unless you manually install the later version.  I may do this but it got me thinking about my current setup.  I'm just using a standard shell program that runs in cron every minute to update the png file.  The problem with this method is that when the html is refreshed if the shell is in the middle of updating the png file, you will get only part of the image.  It's also not dynamic, it would be nice to select the range of data and which points are plotted via the html page.  I worked on this several years ago and just didn't have the time to figure out anything else.  Now that I want to using the Rev 2 Yun I'd like to resolve some of these problems. 

Thanks again,

ottsm

Of course the pyrrd package does not exist as standard in openwrt yun rev 2.  Might try my older system that has it, get it all working, and then figure out how to compile both pyrrd and rrdtool version 1.2.30-3 for the Yun rev 2.  One step forward two steps back again.

ShapeShifter

Yes, if you haven't guessed by now, my project is on the original Yun. I have no experience with Rev 2, and am not familiar with what packages are or are not available to on it.

I had considered having a periodic task to generate image files, but in my case they would be accessed so infrequently that I figured it was mostly wasted effort and potential wasted wear on the flash memory. So I just create the images on demand. On my one statistics screen that has six graphs, it takes a couple seconds for all of the images to be generated and displayed, but it's not intolerable.

ottsm

Hadn't thought of that but generating on demand is not a bad idea at all, why produce a graph if nobody is looking at it.  On the other hand the RRD database also resides on the SD card and it has to be updated although its size never changes and only certain sectors would be modified at a given time and only once when created and once when updated, except perhaps the file date time stamp that would be updated all the time.

You got me thinking about another problem I have, I was writing to some temporary files on the SD card to manipulate the data and get it into the RRD database.  If the power is lost while the file is still open I had setup special code to reboot the Yun to close out the files.  Perhaps I should be using the RAM disk /tmp instead.  This would avoid constantly writing to the SD card as well and if power is lost in the middle of a write, the files are purged anyway.  

I think the path I'm going to take is to use;
http://javascriptrrd.sourceforge.net/
I tried it once before and it can be slow to load but the newer SD card I got for the Yun2 seems to be a little faster, it seems to want to load the entire RRD file, not just a range you would want to look at, the range is selected after the file is loaded by clicking on the scaler graph.

Go Up