Michal Čihař - Temperature monitoring on OpenWrt

Temperature monitoring on OpenWrt

My OpenWrt box has for some time connected TM - RS232 sensor. However for some reason I did never find time to setup it. However as the node is already running lite version of munin, it was really easy to do so. All what was needed is to add another plugin into the /usr/sbin/munin-node script and add temp to list of plugins at top:

config_temp() {             
  echo "graph_title Temperature"
  echo "graph_args --base 1000 -l 0 -u 40"    
  echo "graph_vlabel room temperature"                                                                                        
  echo "graph_category other"                                                                                                                   
  echo "graph_info This graph shows the room temperature."
  echo "temp.label temperature"
  echo "temp.draw LINE2"                             
  echo "temp.info The current room temperature."
}                                                                    
fetch_temp() {                                        
  read RES < /dev/ttyUSB0                        
  echo "temp.value" $(echo $RES | tr -d C+)
}

PS: It looks like reading sometimes produces just bogus results, so here is improved version, which does some level of filtering:

read RES1 < /dev/ttyUSB0                       
read RES2 < /dev/ttyUSB0                 
read RES3 < /dev/ttyUSB0                 
if [ "x$RES1" = "x$RES2" ] ; then                  
    echo "temp.value" $(echo $RES1 | tr -d C+)                          
elif [ "x$RES1" = "x$RES3" ] ; then                                 
    echo "temp.value" $(echo $RES1 | tr -d C+)                 
elif [ "x$RES2" = "x$RES3" ] ; then                        
    echo "temp.value" $(echo $RES2 | tr -d C+)                                    
else                                                                       
    echo "temp.value" $(echo $RES2 | tr -d C+)                                                                                            
fi