Advertisement
Guest User

/usr/local/bin/temp-daemon.sh

a guest
Nov 3rd, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # SoC/HDD temperature daemon. Writes the current temperatures to
  4. # /run/soc-temp and /run/hdd-temp (since we're experiencing always
  5. # timeouts under heavy load when trying to get the temperatures
  6. # directly from within RPi-Monitor.
  7. #
  8. # A directly connected DHT22 temperature/humidity sensor will
  9. # also be queryied with this version and writes to /run/ambient-temp
  10.  
  11. Main() {
  12. # SoCTempAdjustment is needed because the A20 SoC delivers uncalibrated temp values
  13. SoCTempAdjustment=1447
  14.  
  15. # write a reasonable base value to /run/ambient-raw-temp
  16. echo 25 >/run/ambient-raw-temp
  17. echo 25 >/run/ambient-raw2-temp
  18.  
  19. # ensure module sunxi-dbgreg.ko is loaded
  20. grep -q sunxi_dbgreg </proc/modules || ( modprobe sunxi-dbgreg ; sleep 0.1 )
  21.  
  22. # prepare registers
  23. # echo 'f1c25000:27003f' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
  24. # echo 'f1c25010:40000' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
  25. # echo 'f1c25018:10fff' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
  26. # echo 'f1c25004:10' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
  27.  
  28. while true ; do
  29. # read ambient temperature from /run/ambient-raw-temp
  30. read AmbientTemp </run/ambient-raw-temp
  31. read AmbientTemp2 </run/ambient-raw2-temp
  32. if [ "X${AmbientTemp}" != "X" ]; then
  33. RoundedAmbientTemp=$( echo ${AmbientTemp} | cut -f1 -d. )
  34. if [ ${RoundedAmbientTemp} -lt 1 -o ${RoundedAmbientTemp} -gt 50 ]; then
  35. # skip recording of wrong values
  36. :
  37. else
  38. echo ${AmbientTemp} >/run/ambient-temp
  39. fi
  40. fi
  41. if [ "X${AmbientTemp2}" != "X" ]; then
  42. RoundedAmbientTemp2=$( echo ${AmbientTemp2} | cut -f1 -d. )
  43. if [ ${RoundedAmbientTemp2} -lt 1 -o ${RoundedAmbientTemp2} -gt 50 ]; then
  44. # skip recording of wrong values
  45. :
  46. else
  47. echo ${AmbientTemp2} >/run/ambient2-temp
  48. fi
  49. fi
  50. timeout 3 /usr/local/bin/loldht 2 | awk -F" " '/Temperature/ {print $7}' >/run/ambient-raw2-temp
  51. timeout 3 /usr/local/bin/loldht 1 | awk -F" " '/Temperature/ {print $7}' >/run/ambient-raw-temp &
  52.  
  53. # let the value be written to syslog
  54. echo 'f1c25020' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/read;
  55.  
  56. # wait 0.5 seconds
  57. sleep 0.5
  58.  
  59. # read return value from syslog and transform it into degrees Celsius
  60. HexVal=$(tail /var/log/syslog | awk -F" 0x" '/ 0x/ {print $2}' | tail -n1 )
  61. SoCTemp=$(echo $(( 0x${HexVal} - ${SoCTempAdjustment} )) | awk '{printf ("%0.1f",$1/10); }')
  62. if [ "X${SoCTemp}" != "X" ]; then
  63. echo -n ${SoCTemp} >/run/soc-temp
  64. fi
  65.  
  66. # HDD/SSD temp
  67. DiskTemp=$(hddtemp -n /dev/sda)
  68. if [ "X${DiskTemp}" != "X" ]; then
  69. echo -n ${DiskTemp} >/run/hdd-temp
  70. fi
  71.  
  72. # sleep 5 secs
  73. sleep 5
  74. done
  75. } # Main
  76.  
  77. Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement