TEMPer USB Thermometer Scheduled Task/Service
I have been looking around for some type of thermometer that I can attach to my computer for a little while. My main purpose is that I’d like to control my window air conditioner unit since it doesn’t have a thermostat on it, and I’d like to try and conserve some energy by cycling it on and off according to the ambient temperature (that’s for the next article though).
I found a cheap USB thermometer here and it even mentioned using .NET, which was a plus since that would allow me to extend the functionality into something more useful to my needs. Like you can see from the reviews, the included software isn’t very useful nor user friendly. It looks like they just attempted to integrate as many free components as possible into their application (e-mail, graphs, MSN messenger, etc.) in the attempt to make it seem useful. My limited experience with the included software is that it freezes quite often, which makes the device useless to me since I don’t want to constantly be restarting the application.
I came up with a utility that can be run as a scheduled task and reads the current temperature using TEMPer thermometer. The utility can be extended in such a way that the current temperature can be used for multiple different tasks (I’ll show how I use it for an X10 thermostat in the next article). Currently, it supports writing the current date/time and temperature to a SQLite database file.
The task can be extended by implementing the VexedLogic.TemperatureMonitor.ITempMonitorPlugin interface, which defines 1 property and 3 methods:
- PluginName (property) – A read-only property that returns the name of the plugin
- TemperatureRead(currentTemperature) – The method that is called when the temperature is successfully read
- TemperatureError() – The method that is called when an error occurred while reading the temperature
- Initialize() – The method that is called when the utility starts. Returning false will prevent the plugin from loading.
The implementation of the “Logging” plugin is as follows:
using System; namespace VexedLogic.TemperatureMonitor.Plugins.Logging { public class Logger : ITempMonitorPlugin { #region ITemperatureMonitorPlugin Members public string PluginName { get { return "Logging"; } } public void TemperatureRead(double currentTemperature) { using (TemperatureMonitorContainer ctx = new TemperatureMonitorContainer()) { TemperatureReading temperatureReading = new TemperatureReading { DateTime = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture), Temperature = currentTemperature }; ctx.AddToTemperatureReadings(temperatureReading); ctx.SaveChanges(); } } public void TemperatureError() { } public bool Initialize() { return true; } #endregion } }
An assembly can be created from this class and be placed in the “Plugins” folder where the VexedLogic.TemperatureMonitor.exe resides and the plugin will be automatically loaded every time the utility is run. You can also follow a similar procedure outlined on Scheduling X10 Devices using the CM17A to schedule the VexedLogic.TemperatureMonitor.exe program to execute every X minutes. This will automatically read the temperature and execute the TemperatureRead(…) method of each plugin at the schedule you determine.
Download: VexedLogic Temperature Monitor
Logging Plugin
If you’re interested in reading the data that is written by the included Logging plugin, you’ll need a way to read the SQLite DB file. The UI for administering SQLite that I’ve used is called SQLite Administrator.
Go to “Database -> Open” and find the temperatures.db file that is in the same directory that VexedLogic.TemperatureMonitor.exe resides in.
Since the Logging plugin stores the current time as UTC and current temperature as Celcius, some simple calculations can be done to view the data as your local time and Fahrenheit.
The query that returns the raw (UTC and Celsius temperature) data is:
SELECT DateTime, Temperature FROM TemperatureReading
The query that returns the local time and Fahrenheit temperature data is:
SELECT DateTime(DateTime,'localtime'), Temperature * (9.0/5.0) + 32 FROM TemperatureReading
So far, I’ve had this plugin running every 5 minutes for 2 weeks non-stop and haven’t had any problems with the thermometer. So, that convinces me that the included software has some issues with extended periods of run time.
This entry was posted on Sunday, June 19th, 2011 at 5:21 pm and is filed under Life. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.