TEMPerHUM

From Hurlster Wiki
Jump to navigation Jump to search

USB temperature and humidity stick.

How to compile on Ubuntu Precise

  • Pre build requirements
add-apt-repository ppa:mlba-team/stable
apt-get update && apt-get install libhidapi-dev -y
  • Get TEMPered
#cd /usr/local/src/ && git clone https://github.com/edorfaus/TEMPered.git
#cd TEMPered/
  • Custom cmake it

This is necessary because of some shared library issue. Thanks http://edorfaus.wordpress.com/2012/04/28/devices-arrived/

root@server:/usr/local/src/TEMPered# cmake
Would you like to see advanced options? [No]:
Please wait while cmake processes CMakeLists.txt files....

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
HIDAPI_LIB
   linked by target "hid-query" in directory /usr/local/src/TEMPered/utils
   linked by target "tempered-exe" in directory /usr/local/src/TEMPered/utils
   linked by target "enumerate" in directory /usr/local/src/TEMPered/examples
   linked by target "read-all" in directory /usr/local/src/TEMPered/examples
   linked by target "read-repeat" in directory /usr/local/src/TEMPered/examples

Variable Name: BUILD_HIDAPI_SHARED
Description: Build with shared version of HIDAPI
Current Value: ON
New Value (Enter to keep current value): OFF

Variable Name: BUILD_SHARED_LIB
Description: Build shared version of tempered library
Current Value: ON
New Value (Enter to keep current value): 

Variable Name: BUILD_STATIC_LIB
Description: Build static version of tempered library
Current Value: OFF
New Value (Enter to keep current value): 

Variable Name: BUILD_UTILITIES
Description: Build the utilities
Current Value: ON
New Value (Enter to keep current value): 

Variable Name: CMAKE_BUILD_TYPE
Description: Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.
Current Value: 
New Value (Enter to keep current value): 

Variable Name: CMAKE_INSTALL_PREFIX
Description: Install path prefix, prepended onto install directories.
Current Value: /usr/local
New Value (Enter to keep current value): 

Variable Name: HIDAPI_HEADER_DIR
Description: The location of HIDAPI's header file
Current Value: /usr/include/hidapi
New Value (Enter to keep current value): 

Variable Name: HIDAPI_LIB
Description: The location of the HIDAPI shared library file
Current Value: HIDAPI_LIB-NOTFOUND
New Value (Enter to keep current value): 

Variable Name: UTILS_USE_SHARED_LIB
Description: Utilities use the shared tempered library
Current Value: ON
New Value (Enter to keep current value):  

Please wait while cmake processes CMakeLists.txt files....

Variable Name: HIDAPI_OBJECT
Description: The location of the HIDAPI static object file
Current Value: /usr/local/src/hidapi/linux/hid-libusb.o
New Value (Enter to keep current value): 

Please wait while cmake processes CMakeLists.txt files....

  • Make it!
root@server:/usr/local/src/TEMPered# make
Scanning dependencies of target tempered-shared
[  7%] Building C object libtempered/CMakeFiles/tempered-shared.dir/core.c.o
[ 14%] Building C object libtempered/CMakeFiles/tempered-shared.dir/temper_type.c.o
[ 21%] Building C object libtempered/CMakeFiles/tempered-shared.dir/type_hid/fm75.c.o
[ 28%] Building C object libtempered/CMakeFiles/tempered-shared.dir/type_hid/common.c.o
[ 35%] Building C object libtempered/CMakeFiles/tempered-shared.dir/type_hid/ntc.c.o
/usr/local/src/TEMPered/libtempered/type_hid/ntc.c: In function ‘tempered_type_hid_read_sensor_group_ntc’:
/usr/local/src/TEMPered/libtempered/type_hid/ntc.c:8:66: warning: unused parameter ‘group’ [-Wunused-parameter]
/usr/local/src/TEMPered/libtempered/type_hid/ntc.c:9:41: warning: unused parameter ‘group_data’ [-Wunused-parameter]
/usr/local/src/TEMPered/libtempered/type_hid/ntc.c: In function ‘tempered_type_hid_get_temperature_ntc’:
/usr/local/src/TEMPered/libtempered/type_hid/ntc.c:20:60: warning: unused parameter ‘tempC’ [-Wunused-parameter]
[ 42%] Building C object libtempered/CMakeFiles/tempered-shared.dir/type_hid/sht1x.c.o
Linking C shared library libtempered.so
[ 42%] Built target tempered-shared
Scanning dependencies of target tempered-util-shared
[ 50%] Building C object libtempered-util/CMakeFiles/tempered-util-shared.dir/temp-scale.c.o
[ 57%] Building C object libtempered-util/CMakeFiles/tempered-util-shared.dir/dew-point.c.o
[ 64%] Building C object libtempered-util/CMakeFiles/tempered-util-shared.dir/calibration.c.o
Linking C shared library libtempered-util.so
[ 64%] Built target tempered-util-shared
Scanning dependencies of target hid-query
[ 71%] Building C object utils/CMakeFiles/hid-query.dir/hid-query.c.o
Linking C executable hid-query
[ 71%] Built target hid-query
Scanning dependencies of target tempered-exe
[ 78%] Building C object utils/CMakeFiles/tempered-exe.dir/tempered.c.o
Linking C executable tempered
[ 78%] Built target tempered-exe
Scanning dependencies of target enumerate
[ 85%] Building C object examples/CMakeFiles/enumerate.dir/enumerate.c.o
Linking C executable enumerate
[ 85%] Built target enumerate
Scanning dependencies of target read-all
[ 92%] Building C object examples/CMakeFiles/read-all.dir/read-all.c.o
Linking C executable read-all
[ 92%] Built target read-all
Scanning dependencies of target read-repeat
[100%] Building C object examples/CMakeFiles/read-repeat.dir/read-repeat.c.o
Linking C executable read-repeat
[100%] Built target read-repeat
  • Install it!
root@server:/usr/local/src/TEMPered# make install
[ 42%] Built target tempered-shared
[ 64%] Built target tempered-util-shared
[ 71%] Built target hid-query
[ 78%] Built target tempered-exe
[ 85%] Built target enumerate
[ 92%] Built target read-all
[100%] Built target read-repeat
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/include/tempered.h
-- Installing: /usr/local/lib/libtempered.so.0
-- Installing: /usr/local/lib/libtempered.so
-- Installing: /usr/local/include/tempered-util.h
-- Installing: /usr/local/lib/libtempered-util.so.0
-- Installing: /usr/local/lib/libtempered-util.so
-- Installing: /usr/local/bin/hid-query
-- Installing: /usr/local/bin/tempered
-- Removed runtime path from "/usr/local/bin/tempered"
  • Use it!
root@server# tempered -s Fahrenheit
0004:0003:01 0: temperature 77.90 °F, relative humidity 47.2%, dew point 56.1 °F

MRTG Setup

  • SNMPD.conf
exec temp /usr/local/sbin/gettemp.sh
exec wundertemp /usr/local/sbin/getwundertemp.php
  • gettemp.sh
#!/bin/sh
temp=`/usr/local/bin/tempered -s F | cut -c29-33`
temp=`/usr/local/bin/tempered -s F | awk 'NR==1{ print $4; }'
echo $temp
  • getwundertemp.php
#!/usr/bin/php
<?php

//$zipcode = $argv[1];
$zipcode = 12345;
$page = file_get_contents("http://www.wunderground.com/cgi-bin/findweather/getForecast?query=$zipcode&wuSelect=WEATHER");

$current_temp = 0;
if (preg_match('#pwsvariable="tempf" english="°F" metric="°C" value="([0-9\.]+)">#', $page, $matches)) {
    $current_temp = $matches[1];
}

if (preg_match('#Heat Index:.*?

([0-9\.]+)#s', $page, $matches)) { $heat_index = $matches[1]; } //echo "$current_temp\n$heat_index\non\non\n"; echo "$current_temp\n";  ?>
  • Remote Config
Target[temper]: extOutput.11&extOutput.13:STRING@SERVER.com AbsMax[temper]: 120 MaxBytes[temper]: 100 Options[temper]: nopercent,growright,nobanner,nolegend,noinfo,expscale,gauge Title[temper]: Server Room and Outside Temp PageTop[temper]: Server Room and Outside Temp YLegend[temper]: Temperature F ShortLegend[temper]:  °F LegendI[temper]: Inside   LegendO[temper]: Outside   Unscaled[temper]: dwmy