Project 5: Temp Logger

Now that we have access to the PC temperature sensor data, we can create our own data logger instead of simply viewing the files generated by MBM 5. This will be instructive for working with Thin Basic and it will also allow us to customize what data we record and how it will be displayed.

Plan for Making the Temperature Logger
We will use the random data logger in Project 3 as the starting point for this new logger. In this project we will display and record just the CPU and Case temperatures reported by MBM 5. All we have to do is open the mbm.txt file, read the first few lines and parse out the latest temperature readings contained therein.

Once we have grabbed the data from mbm.txt we can embed it in a web page and record to a data file formatted under the control of our program.

Some Test Code
Instead of diving right into the modification of the random1.tbasic code, we will first write a test program that reads the mbm.txt file and parses out the two readings.  That way we can quickly troubleshoot any problems and when successful, just copy and paste what we need into random1.tbasic.

The source code for the test program is here. If you want to see how it works, copy the code from the .pdf file and paste into a blank Thin Air project page. Be sure you have a file C:\freelogger\mbm.txt in place for the program to open and read.

To run the program click on the Debug drop-down and select Go. A DOS box will open and two sets of temperature readings will appear, as shown in the example below:

Project 5 - Test code screen

There are two sets of readings because the program first reads the temperatures as strings from mbm.txt.  Then the program converts the strings into actual floating point values.  We might need to use both kinds of representations in a data logging system.  For example, we could show the temperature on a web page in both degrees F and degrees C, but we could only do a conversion operation on numeric values, not string representations of the mbm.txt data.

You can parse out other readings to the extent they are available in mbm.txt.  The MBM 5 program will detect motherboard voltages, fan speed and other parameters.  These will appear in the same line of text retrieved by the Thin Basic program.  Simply count out where the starting column of the value is in the line, the length of the data you want, and parse using the MID$ function (see above source code).

Creating the Temp Logger Code
Now that we have code that retrieves temperature readings, we can insert this into the random1.tbasic code. We don’t need all of the code – the part that writes the readings to the DOS box screen won’t be part of the new logger. And we will have to remove some of the code in random1.tbasic – the part that generates the random readings, for example. So if you are a good code surgeon you can see what needs to be done.

The complete code listing for the new Temp Logger is shown here.

You can copy this and paste it into a new Thin Air project page and run it. Be sure you have MBM 5 and the Tiny Web Server running. Open your web browser and type the following in the address box:


You should see the new Project 5 web page, as shown below:

Project 5 Web page screen

Notice that the date is now included in the display, and the two temperatures appear on separate lines.  After a few minutes you can load tdata.txt into your browser and see something like the following.

Project 5 - temp data file

Going Further
As with Project 3, the data acquired in tdata.txt can be imported into Excel.  Make sure that the delimiter is set to Space and that you re-format the time column.   You should be able to generate a graph similar to that shown below:

Project 5 - Excel graph

You could also replace the time column in the spreadsheet with elapsed time in minutes by using a formula.  This will usually produce a better looking graph. 

 Here is an Excel graph of some 13 hours of recorded PC temperature data.  The blue trace is the case temperature and the red trace CPU temperature.  Notice that the temperatures were fairly stable because the PC was unused.  At noon the anti-virus program is scheduled to run and the process of checking all the files on the hard drive caused the PC temperatres to rise noticably.

Project 5 - PC Temperatures recorded over 13 hours

%d bloggers like this: