shell doesn't support floats so use int values for test
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 26 Aug 2020 10:31:00 +0000 (12:31 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 26 Aug 2020 10:31:00 +0000 (12:31 +0200)
w1-ds18b20-influx.sh
w1-ds18b20.sh

index 37c134e..9908150 100755 (executable)
@@ -6,8 +6,9 @@ influx=/dev/shm/temp.influx
 :> $influx
 
 ls /sys/bus/w1/devices/w1_bus_master*/*-*/w1_slave | while read path ; do
-       temp=$( cat $path | grep t= | cut -d= -f2  | awk '{ printf "%.3f\n", $1 / 1000 }' )
-       if [ $temp != 85 ] ; then # 85 is error
+       temp=$( cat $path | grep t= | cut -d= -f2 )
+       if [ $temp -ne 85000 ] ; then # 85 is error
+               temp=$( echo $temp | awk '{ printf "%.3f\n", $1 / 1000 }' )
                id=$( echo $path | cut -d/ -f 7 )
                echo "ac_temp,dc=a125,sensor=$id temperature=$temp" >> $influx
                echo $temp > /dev/shm/ds18b20.$id
index 9ef9e62..83a42e9 100755 (executable)
@@ -1,8 +1,9 @@
 #!/bin/sh -e
 
 ls /sys/bus/w1/devices/w1_bus_master*/*-*/w1_slave | while read path ; do
-       temp=$( cat $path | grep t= | cut -d= -f2  | awk '{ printf "%.3f\n", $1 / 1000 }' )
-       if [ $temp != 85 ] ; then # 85 is error
+       temp=$( cat $path | grep t= | cut -d= -f2 )
+       if [ $temp != 85000 ] ; then # 85 is error
+               temp=$( echo $temp | awk '{ printf "%.3f\n", $1 / 1000 }' )
                id=$( echo $path | cut -d/ -f 7 )
                echo -n "$id "
                echo $temp | tee /dev/shm/ds18b20.$id