Application Note 5

Displaying DACS Data with a Web Server


Application Note 1 describes how to log DACS voltage data with a Bash shell script. Application Note 4 describes how to plot this data using Gnuplot.

This note shows how to display the Gnuplot output image using a simple Web server. This note also shows how to use the Linux "cron" facility to periodically update the plot image so that the latest plot data is always displayed.

Web Server

To avoid the complexity of installing a server package such as Apache, we use the simple Web server that comes with every Python2 installation, version 2.4 or greater. To use Python3, see examples on the Internet.

We use Python because it is routinely installed on many Linux systems such as the Raspberry Pi. And, if Python is not installed, it is easily installed on most systems.

The files needed for this note can be downloaded as a tar archive, dacs_webfiles.tgz.

To bring up the Web server, first create a new directory to hold the server files (e.g., mkdir dacsite). Next copy the tar archive to the server directory and, at a shell prompt, extract them there: tar -xvf ./dacs_webfiles.tgz.

After extracting the Web server files, stay in the Web server directory and execute the following: python -m SimpleHTTPServer 8000".

The "-m" in the command line loads the module, SimpleHTTPServer. The "8000" specifies the port number. The startup message should be something like this: Serving HTTP on port 8000.

To use the server, start up a browser and enter: or localhost:8000 as the URL. This specifies that the current computer, the localhost, should be used as the HTTP server. You can also enter the IP address of your computer (e.g., something like In any case, the browser should display a DACS data plot.

Page 2

Automated Updates

At this point, the plot displayed by the browser is static -- the same plot is shown every time the browser is started up. To include the latest DACS data in the plot, a new Gnuplot output file, dacs_v1.jpg, must be generated and its output copied to the Web directory (e.g., ~/dacsite).

Assume the following:

  1. Data File -- The DACS data file, dacs_v1.txt, is periodically updated by a "cron" task and put in a logs directory (e.g., ~/logs). This is described in Application Note 1
  2. Plot Script -- A plot script, dacs_v1.plt is set up for execution by Gnuplot in a "plots" directory (e.g., ~/plots/dacs. This is described in Application Note 4

Figure 1 shows a shell script,, that generates a new plot file, dacs_v1.jpg, from the current data file (e.g., ~/logs/dacs_v1.txt. Line 4 copies the current data file from the logs directory to the plot directory. Line 5 runs Gnuplot to generate a new plot file, ~/plots/dacs/dacs_v1.jpg.

   1    #!/bin/bash
   2    # -- plot dacs data -- 140531rjn
   3    #
   4    cp ~/logs/dacs_v1.txt ~/plots/dacs
   5    gnuplot ./plots/dacs/dacs_v1.plt

Figure 1. Chron Script to Generate a New Plot File

Page 3

Figure 2 shows a shell script,, that executes periodically as a "cron" task to update the Web site plot. Line 4 invokes the shell script given in Figure 1 to generate a new plot file. Line 5 copies the plot file to the Web site.

To use the Linux cron facility to automatically execute the script, use the command: crontab -e and add a new entry such as: 05 * * * * /home/bob/bin/ > /dev/null 2>> /home/bob/logs/cron.log.

Note that the procedure for "cron" execution of the update script is similar to that described in Application Note 1 but the script is executed at 5 minutes past the hour. This ensures that the hourly voltage updates, executed at the top of each hour, are always included in the latest plot.

   1   #!/bin/bash
   2   # -- update dacs jpg on Web site -- 140630rjn
   3	#
   4	/home/bob/bin/
   5	cp ~/plots/dacs/dacs_v1.jpg /home/bob/dacsite/dacs_v1.jpg

Figure 2. Cron Script to Update Web Site

Page 4

Revision Summary

Minor corrections, broken link.
Initial Release

email for BOBZ product support

Copyright © June 30, 2014, Bob Nash.