Tuesday, January 2, 2018

Temperature Data Loggers

Why a Temperature Logger?

Ever since my first winter camp when someone told me how much warmer it was inside a quinzhee, I wanted to have a way to measure that to quantify exactly what the difference would be.  I'd searched half-heartedly since then for a cost-effective solution, but it was not until just before our Scouts 2nd fall camp in November past that I really start searching in earnest.  And luckily I found the perfect item - the Elitech RC-5 USB Temperature Data Recorder.  These devices are used in the medical supply and pharmaceutical industry when drugs and other biological supplies are shipped and have to be maintained at a constant temperature otherwise they cannot be used.  One of the data loggers get packed into the box with the item being shipped, and then the data is read from the device at the other end to ensure the supplies were always kept within the required temperature range.

Aside from knowing the temperature differential inside a quinzhee or igloo, I also just find it generally useful to have a log of temperatures over the course of a camping trip or other outdoors outing.  I like to keep notes on my camping trips on what conditions were like, what gear I used, and how the gear performed.  A key part of knowing how well your gear performed is having accurate temperature data.  For example, it is useful to record in my notes "my brand X sleeping bag was a bit chilly overnight", but it is far more useful to know exactly what the temperature was.



I ended up picking up two of the devices from this Amazon.com link.  Note the price is US dollars but they do ship to Canada, and I seem to recall there was no customs nor duty on top of that but don't quote me on that since I have a terrible memory for such things.  Basically they came in at about 35 Canuck bucks each shipped, which was the price range I was looking for.  I could have lowered the price-per-unit shipping cost by buying more of them, but at the time I had no idea how they'd perform so I was taking a bit of a chance, and two was all I really needed for my immediate needs.  With what I know now I could definitely see myself owning a few more of them - for example in the sleeping bag test I did the other night I could have used one logger inside my shelter near my feet, and another near my head just to see what the difference might be.  That in addition to the one I had outside would be 3 total.

These loggers are pretty basic - they log a temperature at an interval you choose with software on your computer - and that's about it.  You plug it into a USB port to set a few basic things like the interval (how often it should log a datapoint), and whether you want C or F, and then you unplug it to use.  Other features I have not used are that you can give devices unique names, and also set temperature alarms.  The units store 32,000 data points so if you set it to log once per minute as I have, that is a bit more than 22 days of data.

As a Linux user one of my primary concerns is always whether or not something works on that platform - and initially I was disappointed to find that the Elitech software download site only included software for Windows and Mac.   Luckily these devices captured the interest of someone in the Open Source community and Google was able to locate this software which provides functional Linux command-line access to the various features of the units.  Though I was not able to get the supplied elitech-datareader binary to do the initial configuration of the unit, I was able to use the provided python libraries to write my own simple 10 line python program to do it.  But the elitech-datareader program was able to easily read the data off.  Here is what the provided binary says about itself in terms of usage :
[hippy@centos-gig elitech]$ elitech-datareader 
usage: description Elitech RC-4 / RC-5 data reader [-h]
[-c {init,get,latest,simple-set,set,devinfo,clock,raw}]
[-i INTERVAL]
[--upper_limit UPPER_LIMIT]
[--lower_limit LOWER_LIMIT]
[--station_no STATION_NO]
[--stop_button {y,n}]
[--delay {0.0,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0,5.5,6.0}]
[--tone_set {y,n}]
[--alarm {x,3,10}]
[--temp_unit {C,F}]
[--temp_calibration TEMP_CALIBRATION]
[--time TIME]
[--dev_num DEV_NUM]
[--user_info USER_INFO]
[--encode ENCODE]
[--page_size PAGE_SIZE]
[--req REQ]
[--res_len RES_LEN]
[--value_only]
[--ser_baudrate SER_BAUDRATE]
[--ser_timeout SER_TIMEOUT]
serial_port
When you first insert the device into your computer, you are going to want to know what USB device it configured itself as.  This is easy to determine on Linux by looking at the last few lines of output of the dmesg command.
[779619.444113] usb 4-3: new full-speed USB device number 18 using ohci-pci
[779619.592746] usb 4-3: New USB device found, idVendor=1a86, idProduct=7523
[779619.592753] usb 4-3: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[779619.592755] usb 4-3: Product: USB2.0-Serial
[779619.597438] ch341 4-3:1.0: ch341-uart converter detected
[779619.620384] usb 4-3: ch341-uart converter now attached to ttyUSB0
[hippy@centos-gig elitech]$ ls -alh /dev/ttyUSB0 
crw-rw----. 1 root dialout 188, 0 Jan  1 18:53 /dev/ttyUSB0
[hippy@centos-gig elitech]$

Here you can see it is /dev/ttyUSB0, and I double-verified that by doing an ls -alh /dev/ttyUSB0 which showed a timestamp of right now - exactly when the device was inserted.  To read data from the device once configured, I was able to get the command elitech-datareader -c get /dev/ttyUSB0, but I was not able to use the command to do the initial configuration including setting the time on the device, as well as the recording interval (the default seems to be a fairly aggressive 10 seconds).  So I whipped up this simple python program with their provided examples, which sets the interval (and does a superfluous data dump).  Note you either have to change permissions on the USB device, or run your program as root.   From the output above we see that a regular user does not have access to the device.

[hippy@centos-gig elitech]$ cat update.py 
#!/usr/bin/python

import elitech
import time
import datetime

device = elitech.Device("/dev/ttyUSB0")
body = device.get_data()
for elm in body:
    print elm

device = elitech.Device("/dev/ttyUSB0")
devinfo = device.get_devinfo()  # get current parameters.

param_put = devinfo.to_param_put()  #convart devinfo to parameter
param_put.rec_interval = datetime.time(0, 1, 00)    # update parameter
param_put.stop_button = elitech.StopButton.ENABLE   # update parameter

param_put_res = device.update(param_put)    # update device

Once configured, you start the device by pushing and holding the triangular play button for 3 seconds.  When you see the little triangle appear on the LCD display, it is recording.  I have not yet been able to figure out how to stop recording completely - only how to pause it with the pause button.  Well, aside from plugging it back into the computer again and running the update.py program which resets it back to its initial position and wipes the data.
When you read the data off it looks like this :
[hippy@centos-gig video]$ sudo elitech-datareader -c get /dev/ttyUSB0
1 2018-01-01 19:03:40 26.1
2 2018-01-01 19:04:40 26.1
3 2018-01-01 19:05:40 26.2
4 2018-01-01 19:06:40 26.4

To load the data into a spreadsheet like Open Office or Google Sheets and produce graphs like the one show below, you have to massage it a bit.  On Linux that means a bit of awk and sed basically.  You want to get rid of the first column which shows you which datapoint we are dealing with, and also get rid of the seconds (:40 above).  When graphing data from numerous loggers you then want to manually edit the files to ensure they start and end on the same minute, and have the same number of lines in them.  Once that is done it is really easy to read one file into each sheet, and then copy and paste the temperature data from each sheet into the first sheet.  If I were doing a lot of this I'd probably write another simple little script to do it all for me and stuff it into a CSV, but doing this manually only took 2 or 3 minutes.  I produced this simple graph by first loading the data into a sheet locally within Open Office, and then uploading it to google sheets which is what produced the graph for me.  It simply shows the data from one logger inside my sleeping structure the other night as temperatures plummeted to -25C, and another logger hung in a shrub just outside the shelter.

For the sake of completion I loaded the software on my wife's Windows laptop and just looked at it quickly mainly to be able to provide a screen shot to give you an idea what it looks like.  This is the main screen, and you can get an idea from there what else is available to you.  It won't win any aesthetics awards but it does seem to get the job done well enough.

No comments:

Post a Comment

Welcome to My New Blog!