Project 3: Simple Logger

Now that we have a web server and a programming environment installed, we can build an actual data logger.  This logger will be as simple as possible for learning purposes – it will display and record a single random number every 60 seconds.

Naturally, a list of random numbers generated by this logger will not provide any useful information.  But this first example project will show how to construct more complex data logging programs later and, once it works, will be easy to modify to display and record actual physical data.

Creating the Simple Data Logger
To create a simple data logger we will need two things:

1. Tiny Web Server running, ready to serve up web pages and

2. A program to generate the random data, write a new web page every 60 seconds and store the readings to a file.

So the first part is easy – we simply launch Tiny Web Server and it will sit running in the background ready to serve up pages.

A Thin Basic program can be used to do all the other stuff. Since this is the most complicated part, let’s break it down.

Creating a Web Page from a Program
A Thin Basic program called random1.tbasic will be used to create a web page every 60 seconds. The web page is simply a text file consisting of html tags, some text, the current time and a random data reading. The web page will be called random1.html and will be written to the C:\freelogger folder where it will be available to Tiny Web Server.

Recording the Random Data
In addition, random1.tbasic will save the current time and the random data reading to a file named rdata.txt, also in the C:\freelogger folder. This page is also available to the Tiny Web Server and can be viewed from a web browser.

Creating random1.tbasic
A pdf file containing the source code for random1.tbasic is here. Highlight the code and copy it, then open Thin Air with a new project page. Paste the code into the blank page. At this point you might want to Save the file to the C:\freelogger folder with the name random1.tbasic.

Running the Program
Go to the Debug drop-down and select Go. If everything is working correctly you will see a DOS box appear that looks like this:

Project 3 screen 1

This box may be minimized – it does not display anything other than “Project 3: Random Reading Data Logger”

Next, launch your web browser and type the following  into the address box:


If successful, you should see the following:

Project 3 - Screen 2 - Browser page

Notice that the web page can be updated after a minute and the random reading and current time will change.  Notice that the time is given as Hours:Minutes:Seconds:Milliseconds.  The random reading will vary between 1.000 and 1.999.

The data is also being saved to a file that is accessible by browser.  After a few minutes, type the following address into your browser:


Notice that no html page is defined.  The Tiny Web Server will reply with a list of all pages in the C:\freelogger folder.   Select rdata.txt and you should see the following:

Project 3 - Screen 3 - Data text page

If you got an error message when trying to read rdata.txt be sure the Tiny Web Server is configured to serve text files.  You can verify this by right-clicking on the Tiny Web Server icon in the desktop tray and be sure the File Browsing box is checked.

Shutting Down
To close down the Thin Basic program simply close the DOS box window using the X button on the upper right corner.  The program will stop creating new web pages or appending new data to rdata.txt.  The last web page will still exist and can be viewed, but refreshing with the browser will not, of course, produce new data readings or the current time.

You can delete rdata.txt and if you run the program again it will start a new data file, or you can leave it as it is and new data readings will be appended to it.  This may not mean much when the readings consist of random numbers, but for real-world data this choice will be important.

Going Further
You can import the random readings from rdata.txt into Excel.  Launch Excel and then Open the rdata.txt file.  To do this you will need to navigate to the C:\freelogger folder and make sure that the file types you are viewing in the Excel File Open window include .txt files.

When you locate rdata.txt and Open it, an Import Wizard will open and ask how the file should be treated.

In Step 1, the default “Delimited” selection is correct.

In Step 2, choose “space”  as the delimiter, then click on Finish.

The time and random readings should appear in two separate columns in the spreadsheet.

Highlight the entire first column (the time readings) and then us the Excel Format drop-down (along the top of the spreadsheet) and select Cells, then Time.  In the Type window select the format as shown below:

Project 3 - Time format screen in Excel

If everyting has worked correctly, you can now graph the readings over time, as shown below:

Project 3 - Excel Spreadsheet

%d bloggers like this: