SHARE
TWEET

Bash Script for Reading Sensors and Plotting RRD Graphs

a guest Jan 25th, 2016 133 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #bin/sh
  2.  
  3. fetch_data() {
  4.   lines=($(/bin/cat temp.txt))
  5.   temp=${lines[0]}
  6.   hum=${lines[1]}
  7.   pres=${lines[2]}
  8.   rm "temp.txt"
  9. }
  10.  
  11. sudo /usr/local/bin/upnp2mrtg > temp.txt
  12. fetch_data
  13. /usr/bin/rrdtool update /var/www/rrd/fritzbox.rrd N:$temp:$hum
  14.  
  15. sudo /usr/local/bin/dht22.py > temp.txt
  16. fetch_data
  17. temp=($(/usr/bin/python -c "print $temp/10.0"))
  18. hum=($(/usr/bin/python -c "print $hum/10.0"))
  19. /usr/bin/rrdtool update /var/www/rrd/dht22-pi.rrd N:$temp:$hum
  20.  
  21. /usr/bin/wget -q -O temp.txt http://nodemcu1/
  22. fetch_data
  23. temp=($(/usr/bin/python -c "print $temp/10.0"))
  24. hum=($(/usr/bin/python -c "print $hum/10.0"))
  25. /usr/bin/rrdtool update /var/www/rrd/dht22-nodemcu1.rrd N:$temp:$hum
  26.  
  27. /usr/bin/wget -q -O temp.txt http://nodemcu2/
  28. fetch_data
  29. temp=($(/usr/bin/python -c "print $temp/10.0"))
  30. hum=($(/usr/bin/python -c "print $hum/10.0"))
  31. /usr/bin/rrdtool update /var/www/rrd/dht22-nodemcu2.rrd N:$temp:$hum
  32. /usr/bin/wget -q -O temp.txt http://nodemcu3/
  33. fetch_data
  34. temp=($(/usr/bin/python -c "print $temp/10.0"))
  35. hum=($(/usr/bin/python -c "print $hum/10.0"))
  36. /usr/bin/rrdtool update /var/www/rrd/dht22-nodemcu3.rrd N:$temp:$hum
  37.  
  38.  
  39. # create graphs
  40. /usr/bin/rrdtool graph /var/www/rrd/fritzbox-day.png \
  41. --width=400 --height=140 -s 'now - 1 day' -e 'now' \
  42. --watermark "Fritzbox traffic: `date`" \
  43. DEF:inoctets=/var/www/rrd/fritzbox.rrd:in:AVERAGE \
  44. DEF:outoctets=/var/www/rrd/fritzbox.rrd:out:AVERAGE \
  45. LINE2:inoctets#00FF00:"In traffic" \
  46. LINE2:outoctets#0000FF:"Out traffic"
  47.  
  48. /usr/bin/rrdtool graph /var/www/rrd/dht22-pi-day.png \
  49. --width=400 --height=140 -s 'now - 1 day' -e 'now' \
  50. --watermark "Kitchen Window: `date`" \
  51. DEF:Temp=/var/www/rrd/dht22-pi.rrd:temp:AVERAGE \
  52. LINE2:Temp#FF0000:"Temp deg. C" \
  53. DEF:Hum=/var/www/rrd/dht22-pi.rrd:hum:AVERAGE \
  54. LINE2:Hum#00FF00:"RH %" \
  55. CDEF:avg_temp=Temp,300,TREND \
  56. CDEF:avg_hum=Hum,300,TREND \
  57. GPRINT:avg_temp:AVERAGE:"Avg Temp\: %2.1lf%s" \
  58. GPRINT:avg_hum:AVERAGE:"Avg Hum.\: %2.1lf%s\n"
  59.  
  60. /usr/bin/rrdtool graph /var/www/rrd/dht22-nodemcu1-day.png \
  61. --width=400 --height=140 -s 'now - 1 day' -e 'now' \
  62. --watermark "Living Room: `date`" \
  63. DEF:Temp=/var/www/rrd/dht22-nodemcu1.rrd:temp:AVERAGE \
  64. LINE2:Temp#FF0000:"Temp deg. C" \
  65. DEF:Hum=/var/www/rrd/dht22-nodemcu1.rrd:hum:AVERAGE \
  66. LINE2:Hum#00FF00:"RH %" \
  67. CDEF:avg_temp=Temp,300,TREND \
  68. CDEF:avg_hum=Hum,300,TREND \
  69. GPRINT:avg_temp:AVERAGE:"Avg Temp\: %2.1lf%s" \
  70. GPRINT:avg_hum:AVERAGE:"Avg Hum.\: %2.1lf%s\n"
  71.  
  72. /usr/bin/rrdtool graph /var/www/rrd/dht22-nodemcu2-day.png \
  73. --width=400 --height=140 -s 'now - 1 day' -e 'now' \
  74. --watermark "Clothing room: `date`" \
  75. DEF:Temp=/var/www/rrd/dht22-nodemcu2.rrd:temp:AVERAGE \
  76. LINE2:Temp#FF0000:"Temp deg. C" \
  77. DEF:Hum=/var/www/rrd/dht22-nodemcu2.rrd:hum:AVERAGE \
  78. LINE2:Hum#00FF00:"RH %" \
  79. CDEF:avg_temp=Temp,300,TREND \
  80. CDEF:avg_hum=Hum,300,TREND \
  81. GPRINT:avg_temp:AVERAGE:"Avg Temp\: %2.1lf%s" \
  82. GPRINT:avg_hum:AVERAGE:"Avg Hum.\: %2.1lf%s\n"
  83.  
  84. /usr/bin/rrdtool graph /var/www/rrd/dht22-nodemcu3-day.png \
  85. --width=400 --height=140 -s 'now - 1 day' -e 'now' \
  86. --watermark "Bedroom: `date`" \
  87. DEF:Temp=/var/www/rrd/dht22-nodemcu3.rrd:temp:AVERAGE \
  88. LINE2:Temp#FF0000:"Temp deg. C" \
  89. DEF:Hum=/var/www/rrd/dht22-nodemcu3.rrd:hum:AVERAGE \
  90. LINE2:Hum#00FF00:"RH %" \
  91. CDEF:avg_temp=Temp,300,TREND \
  92. CDEF:avg_hum=Hum,300,TREND \
  93. GPRINT:avg_temp:AVERAGE:"Avg Temp\: %2.1lf%s" \
  94. GPRINT:avg_hum:AVERAGE:"Avg Hum.\: %2.1lf%s\n"
RAW Paste Data
Top