14.2.10

WD MyBook Hacks - Temperature Readings

This is a topic that puzzled me for some time. Built-in temperature sensors are useful for monitoring the health status of the device and making proper action if for instance overheating occurs. For personal computing, lm-sensors is a frequently-used tool for this purpose which is able to read the sensors via SMBus on most of the motherboards. However, the MyBook has a different facility for this, so we will see how to take advantage of it. In fact, not only the on-board temperature sensor can be read, but the one on the hard drive can be used as well.

Reading sensor on the hard drive

This sensor can simply be reached through reading the S.M.A.R.T. data of the drive as I posted earlier. What we need to do is to grep the useful data and get rid of the garbage by selecting the line and the field we are interested in:

#~: smartctl -a -d ata /dev/sda | awk '/Temperature/ {print $10}'
44

will do the job, and we get the temperature of the hard drive in Celsius.

Reading the on-board temperature sensor

This one can be interrogated through:

#~: cat /sys/module/thermAndFan/parameters/current_temp
27

which is a reasonable value. If however we look further into the details:

#~: cat /sys/module/thermAndFan/parameters/hot_limit
16
#~: cat /sys/module/thermAndFan/parameters/cold_limit
104

this should give the clue that this is not a direct temperature reading. Indeed this sensor does not read in Celsius but rather in "Counts" which is proportional to the sensor resistance value. Luckily enough google finds the lookup table for this platform here (see TvsCnt[] array). As the sensor is a semiconductor thermistor, there is no simple linear equation to determine the temperature, rather the following exponential dependence should be used: Cnt=a×exp(b/T), with Cnt being the reading above and T being the absolute temperature in Kelvin. For this specific sensor the parameters are a=1/9331 and b=3865 as a result by a simple fitting procedure. So after some algebra we find that the temperature will be: t=3865/(ln(Cnt)+9.1411)-273.16 in Celsius (feel free to do it in Fahrenheit :) ).

In order to implement this equation, we will use the command-line calc tool:
#~: ipkg install calc

Finally using this tool a simple script can be used to determine the temperature:

#!/bin/sh
Y1=`cat /sys/module/thermAndFan/parameters/current_temp `
C1='display(0);config("tilde","off");3865/(ln('
C2=')+9.1411)-273.16'
/opt/bin/calc $C1$Y1$C2 | awk 'NR==3 {print $1}'  

which results in a single return value, e. g. 37.

Finally the question remains: Why would we do this? The reason is that these readings can be plotted using for instance MRTG, so that the health status of the storage can be checked easily.

No comments:

Post a Comment