#!/bin/bash #-----------------------------------------------------------------------# # # # Script originally written by David McDowell and John Mitchell. # # Thanks also to fellow TriLUG (http://www.trilug.org) members. # # Maintained and updated by David McDowell. # # # # You may use this script freely providing you give due credit; please # # keep this information block for use and distribution. This script is # # provided WITHOUT ANY WARRENTY. Check # # http://www.turnpike420.net/linux/iTHX-M/ for the latest version. # # # # Version 1.3 - 2005-06-14 # # # #-----------------------------------------------------------------------# # This script gets temperature/humidity data from a Newport Electronics, Inc. # iServer MicroServer model iTHX-M: http://www.newportus.com # # Set this script up as a cron job to run every n minutes you will get # a daily text log; mask: yyyy-mm-dd_iTHX-M.txt # # The corresponding PHP script will put the data into a MSSQL database, you # may of course choose your own database logging method. # # You will need "netcat" found here: http://netcat.sourceforge.net # Currently tested with netcat-0.7.1-1.i386.rpm on Fedora Core 3 # Outputs as comma delimited text and is appended to file. # Start by capturing date (DATENOW) and time (TIMENOW) from your computer # if you don't want date and time from the iTHX-M. The iTHX-M does not # appear to have a way to keep time in sync using NTP or similar methods. # use %F for yyyy-mm-dd # use %R for hr:mn OR use %T for hr:mn:se DATENOW=`date +%F` TIMENOW=`date +%T` # This gets one temperature (TEMPERATURE) reading. # We cut the date/time from the return string of the iTHX-M. # The iTHX-M returns with this mask: 000.00 mm/dd/yyyy hr:mn:se # We only want the temperature: 000.00 TEMPERATURE=`echo -e '*SRT\r' | netcat 192.168.1.253 1000 | cut -c1-6` # Wait one second for the iTHX-M to recover sleep 1 # This gets one humidity (HUMIDITY) reading. # We cut the date/time from the return string of the iTHX-M. # The iTHX-M returns with this mask: 000.00 mm/dd/yyyy hr:mn:se # We only want the humidity: 000.00 HUMIDITY=`echo -e '*SRH\r' | netcat 192.168.1.253 1000 | cut -c1-6` # Output as comma delimited text to file. # Added "T_" in front of the temperature. # Added "H_" in front of the humidity. echo "$DATENOW,$TIMENOW,T_$TEMPERATURE,H_$HUMIDITY" >> ${DATENOW}_iTHX-M.txt # Output to iTHX-M.txt looks like this: # 2004-09-25,15:50:01,T_067.80,H_056.50 # Output data to a database using PHP /usr/bin/php -q /path/to/iTHX-M-1.3.php $TEMPERATURE $HUMIDITY