5 LOCK=/var/tmp/readtemp.lock
7 SYSDEV=/sys/bus/usb/devices
10 if [ -f "$i/interface" ]
12 if grep -q "CP2102 USB to UART" "$i/interface"
14 DEV=/dev/$(basename `ls -d $i/ttyUSB* `)
15 # dont break here, keep going so we get the last one
21 if ! lockfile -r 3 -l 5 $LOCK
23 echo "Failed to obtain lock"
27 if ! stty --file=$DEV | grep -q 'speed 19200'
29 stty --file=$DEV 19200
33 if ! stty --file=$DEV | grep -q '-echo'
35 stty --file=$DEV -echo
42 if [ $# -ge 1 ] && [ "$1" == "-c" ]; then
46 while read -t $TIMEOUT -u 3 CODE ID TEM OTH; do
48 if [ "$CODE" == "END" ]; then
53 if [ "$CODE" != "TEMP" ]; then
54 echo "ERROR CODE=$CODE ID=$ID TEM=$TEM"
58 # truncate for paranoia
61 # calculate degrees from the hex code
62 DEGC=`echo "16 i $TEM A i 4 k 0.0625 * p" | dc`
64 if [ $MODE == "cacti" ]; then
65 printf "id:%s temp:%s\n", "$ID" "$DEGC"
67 printf "%s %s degC\n" "$ID" "$DEGC";