<<

How to Monitor and Report Temperature with a USB Sensor by John Chamberlain ThermoHID is a small Windows program written by Steve Timms (http://www.thermohid.co.uk) to interface with the simple and inexpensive TEMPer devices. ThermoHID allows one to use the temperature reading capabilities of the TEMPer devices for real- time monitoring, recording, and even alarm-generating, and upload the results to a web server for monitoring from anywhere. Although setting up everything can be rather intimidating, once you get it running, it works reliably and transparently while you use your computer for your normal work. Below I describe the steps to run invisibly in the background, and upload the resulting report to a web server. See Change the Chart below for the routine seasonal change to the chart scale. Required Steps • Step 1. Connect the TEMPer device (via USB cable) to a continuously running, internet connected Windows computer. • Step 2. Run ThermoHID manually to set up the program parameters and resulting graph appearance. (Optional: Install and use TeeChart Office to configure the graph, saved in a configuration file, e.g., default.tee.) • Step 3. To enable ThermoHID to run in the background in Windows: a) Create a secondary Windows user, and b) Create a scheduled task to run the ThermoHID program, assigned to our secondary user. Advantage: This will run the program in the background anytime the computer is ON (not require someone to be logged on). • Step 4. Finally, to share the data, upload the output of the reporting program to a convenient server at regular intervals. ThermoHID includes a ftp service, but I prefer a more secure file transfer program also run as a scheduled task. The first two steps above are covered well in the TEMPer and ThermoHID documentation. So, here’s a little more detail for the latter two steps. Step 3. Run ThermoHID in the Background We want the ThermoHID to run invisibly day and night. To accomplish that we 1) install everything to run on an Internet-connected computer that can be left on 24/7, and 2) run it (start/restart) as a scheduled task with a secondary user (which avoids any interference with primary users using the computer, e.g., during office hours). 1. Running 24/7. In Windows Control Panel, Power Options, Change Plan Settings (for the currently selected power plan), Put the computer to sleep: Choose “Never.” There are several

— 1 — ways to get to this setting, but the goal is for the CPU of the computer to NEVER go to sleep on its own. Obviously, YOU can still shut down/power down the computer manually. Power Failures. If you want the computer to recover itself after a power failure, you probably must modify the BIOS settings. In the BIOS in Advanced Power Management (APM) look for an option like “After AC power loss: [always OFF| always ON| last state].” Choose “Always ON”, “Save and Exit” the BIOS settings, which will restart the system. 2. Run ThermoHID on Startup. I originally had ThermoHID running as a Windows Service, but that was rather tedious and arcane to set up. A somewhat easier way is to create a secondary local Windows user (e.g., “ThermoHID” with a simple password, no need for network privileges, etc.). Then start Task Scheduler and create a new Task entry, with these settings: a. General tab: Name: Enter a name like “Start ThermoHID at startup” or similar. Select “Run whether user is logged on or not.” And “Change User”: type your secondary user name, and Check Names, select the found user entry, and OK. Supply password. b. Triggers: Click New, select to begin the task “At startup,” and OK. c. Actions: Click New, select to “Start a program,” browse to find the fully qualified location of “ThermoHID.exe”, copy/paste the drive and folder information into the “Start in” box, and OK. d. Settings: Verify that “Do not start a new instance” is selected e. Save by clicking OK, and supply the password for the new user you created above. f. Run now: right-click the new task, and select Run. The program should begin running in the background, which can be verified by either watching the files change periodically in the ThermoHID folder, or running Windows Task Manager (Ctrl-Alt-Del), and seeing the ThermoHID in the list. You should also verify that it runs when you restart the computer, too. (You can also “End” ThermoHID from the right-click menu, too.) Step 4. Automatically upload to a web server ThermoHID includes its own ftp capability, but I prefer a more secure and versatile file transfer program: WinSCP, which can run a script to upload the web page and graph to a web server. Upload of files via a Script. Below is a WinSCP script (plain text) file (upload_ThermoHID_files.txt), located in the WinSCP folder, that will be run by WinSCP to: 1) connect to MyServer, 2) “put” our two updated ThermoHID files into the existing /office folder, and 3) Exit. (Replace MyServer and /office with your own server and folder names. MyServer must exist with the required login information in WinSCP.) # Automatically answer all prompts negatively # so not to stall the script on errors option batch on # Disable overwrite warnings/confirmations option confirm off # Connect to MyServer using saved session settings open MyServer # Change remote cd /office # Upload files (and rename html) to the current working directory put "c:\program files\ThermoHID\ThermoHID.htm" index.html put "c:\program files\ThermoHID\TempHIDGraph.jpg" # Disconnect close # Exit WinSCP exit — 2 — Note: This script copies (renames) the ThermoHID.htm file to “index.html,” so simply browsing to a URL like http://myserver.com/office will display the current ThermoHID web page and graph. HINT: Try out this script from the WinSCP folder, and watch for successful responses. At the command line, type: winscp /script=upload_ThermoHID_files.txt Automatically Upload. To keep the web page up-to-date, periodically perform this upload. Create another Windows Scheduled Task (in Control Panel) that runs the script in the background. 1. Right-click My Computer, Manage, under System Tools, see Task Scheduler, and the Task Scheduler Library. (If you made a folder for the Step 3 ThermoHID tasks, open and save this new task there, too.) 2. Right-click and Create Task. a. General tab: Name: Enter a name like “Upload files every few minutes” or similar. Select “Run whether user is logged on or not.” And “Change User”: type your secondary user name, Check Names, select the found user entry, and OK. Supply password. b. Triggers: Click New, select to begin the task “At startup,” check “Repeat Task every”, specify “5 minutes”, Enabled, and OK. And in case something stops this task, add a second: click New, begin “On a schedule”, change the time to midnight (12AM), Daily, and again, “Repeat task every 5 minutes,” Enabled, and OK. c. Actions: Click New, select to “Start a program,” browse to find the fully qualified location of “WinSCP.com”, copy/paste the drive and folder information into the “Start in” box. Now, very important: in the “Add arguments” box, paste: “/script=upload_ThermoHID_files.txt” (or whatever you named the WinSCP script) and click OK. d. Settings: Verify that “Do not start a new instance” is selected e. Save: click OK, and again supply the user password. f. Run now: Right-click the new task, and select Run. The program should briefly execute in the background and every 5 minutes thereafter. This can be verified by closely watching the Windows Task Manager (Ctrl-Alt-Del), and seeing the Win SCP process briefly appear in the list, and/or you can verify that updated files are indeed uploaded to your web server. Verify that it runs when you restart the computer, too. Customize ThermoHID Above we configured ThermoHID to automatically run in the background. Occasionally you may wish to make changes to the program and output. For example, to change: • The web page template, as defined by ThermoHID.txt. (ThermoHID.htm is generated using ThermoHID.txt.) • The chart layout, defined by a tee file (usually default.tee) in the ThermoHID folder. Chart formatting changes can be made in the ThermoHID program or with TeeChart Office. • The ThermoHID program operation itself, by altering the INI file or while running the EXE. In all these cases, changes will take effect the next time ThermoHID is started. But since you probably have it always running, you must: 1) stop the program, 2) make your changes, and 3) restart the program.

— 3 — Stop/ReStart ThermoHID 1. You can log in as the secondary user, and Exit the running ThermoHID program (right click the task-bar icon, and Exit). Or, to avoid switching users, you can use the Windows Task Manager (Ctrl-Alt-Del), scroll down to find the ThermoHID process, right-click and End Process. (Cross your fingers and hope that no file corruption occurs!) 2. Now, to make changes to ThermoHID set up, start ThermoHID.exe, right-click the task- bar icon and Restore, make desired changes in configuration, and End the program (right- click the task-bar icon, and Exit) to save the changes. 3. Then restart the task: Open up the Task Scheduler list, right-click the ThermoHID task in the list, and select Run. ThermoHID should be listed in the Windows Task Manager. Below are some typical changes you might wish to make to ThermoHID in Step 2 above.

Change the Chart The most common need for change will be to adjust the chart, e.g., the range of outdoor temperatures (y-axis) in summer versus winter. The format of the graph created by ThermoHID is controlled by default.tee, the format of which can be edited using TeeChart Office (which may no longer be available). See http://www.steema.com/ for more details or to download the TeeChart program. The simple solution is to create the desired format and save them with a descriptive name, like summer.tee and winter.tee. In Explorer find and run the TeeChart program (e.g., TeeChartOffice.exe). If not available, ThermoHID itself incorporates a similar interface to edit the current tee file. 2. Use File, Open to select an existing tee file, e.g., default.tee. 3. Make the desired changes to the chart configuration. 4. Right-click the chart, and choose Edit... 5. Choose the desired chart component to configure by clicking the appropriate tab and sub- tab, and specific attribute in the list. For example, as shown here, the Axis, Minimum tabs are chosen, and the Left Axis minimum value is being changed. 6. Close the Edit window. 7. Save the changes to the desired tee file. Note: Changes made with the ThermoHID interface will be saved in the current tee file (usually default.tee). Changes made with TeeChartOffice will affect whichever tee file you selected to open/save. ThermoHID must be restarted for tee-file changes to take effect.

— 4 — A simple strategy for the bi-annual between summer and winter graph scales is to simply overwrite default.tee with summer.tee or winter.tee at each seasonal change, which will take effect the next time ThermoHID restarts (e.g., system startup). That can be done manually. To automate this: Create a task in Windows’ Task Scheduler triggered “At system startup” to run a VBS script that compares the system date with summer/winter dates and copies (overwrites) the appropriate tee file to default.tee. Dim DateSummer, DateWinter, Today, fso ' create object having file functions (i.e., copyFile) Set fso = CreateObject("Scripting.FileSystemObject")

' create breakpoints for current year DateSummer = "4/1/" & Year(Date) DateWinter = "10/1/" & Year(Date) ' calculate differences (days) between breakpoints and today ds = DateDiff("d", DateSummer, Date) dw = DateDiff("d", DateWinter, Date) if ds > 0 and dw < 0 then ' use summer chart settings fso.CopyFile "default-summer.tee", "default.tee", TRUE else ' use winter chart settings fso.CopyFile "default-winter.tee", "default.tee", TRUE end if

Change ThermoHID program settings 1. Locate and run ThermoHID.exe. Note: If the program is running as a background user, it must first be Stopped (as described above, using the Task Manager). 2. The program runs minimized, as indicated by the thermometer icon in the notification area. Restore the running ThermoHID program by right-clicking the icon in the notification area and selecting Restore, or just double- click the icon in the notification area. 3. Make the desired changes, such as adjusting the frequency of readings (see example here), and changes will be saved to the program INI file (if File, Use INI File for Settings is “checked”—allows manual changes to the settings). Note: The Options, Settings menu has several important settings, such as the date/time formats. 4. Save your changes by clicking the menu: File, Save Chart Settings to update. 5. Close or Exit the dialog window. 6. Fully terminate the program: right-click the icon in the system tray and select Exit. See above for resuming running as the secondary user. It may take a few minutes for the task to cycle through it’s periodic updates and uploads.

— 5 —