Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # SoC/HDD temperature daemon. Writes the current temperatures to
- # /run/soc-temp and /run/hdd-temp (since we're experiencing always
- # timeouts under heavy load when trying to get the temperatures
- # directly from within RPi-Monitor.
- #
- # A directly connected DHT22 temperature/humidity sensor will
- # also be queryied with this version and writes to /run/ambient-temp
- Main() {
- # SoCTempAdjustment is needed because the A20 SoC delivers uncalibrated temp values
- SoCTempAdjustment=1447
- # write a reasonable base value to /run/ambient-raw-temp
- echo 25 >/run/ambient-raw-temp
- echo 25 >/run/ambient-raw2-temp
- # ensure module sunxi-dbgreg.ko is loaded
- grep -q sunxi_dbgreg </proc/modules || ( modprobe sunxi-dbgreg ; sleep 0.1 )
- # prepare registers
- # echo 'f1c25000:27003f' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
- # echo 'f1c25010:40000' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
- # echo 'f1c25018:10fff' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
- # echo 'f1c25004:10' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
- while true ; do
- # read ambient temperature from /run/ambient-raw-temp
- read AmbientTemp </run/ambient-raw-temp
- read AmbientTemp2 </run/ambient-raw2-temp
- if [ "X${AmbientTemp}" != "X" ]; then
- RoundedAmbientTemp=$( echo ${AmbientTemp} | cut -f1 -d. )
- if [ ${RoundedAmbientTemp} -lt 1 -o ${RoundedAmbientTemp} -gt 50 ]; then
- # skip recording of wrong values
- :
- else
- echo ${AmbientTemp} >/run/ambient-temp
- fi
- fi
- if [ "X${AmbientTemp2}" != "X" ]; then
- RoundedAmbientTemp2=$( echo ${AmbientTemp2} | cut -f1 -d. )
- if [ ${RoundedAmbientTemp2} -lt 1 -o ${RoundedAmbientTemp2} -gt 50 ]; then
- # skip recording of wrong values
- :
- else
- echo ${AmbientTemp2} >/run/ambient2-temp
- fi
- fi
- timeout 3 /usr/local/bin/loldht 2 | awk -F" " '/Temperature/ {print $7}' >/run/ambient-raw2-temp
- timeout 3 /usr/local/bin/loldht 1 | awk -F" " '/Temperature/ {print $7}' >/run/ambient-raw-temp &
- # let the value be written to syslog
- echo 'f1c25020' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/read;
- # wait 0.5 seconds
- sleep 0.5
- # read return value from syslog and transform it into degrees Celsius
- HexVal=$(tail /var/log/syslog | awk -F" 0x" '/ 0x/ {print $2}' | tail -n1 )
- SoCTemp=$(echo $(( 0x${HexVal} - ${SoCTempAdjustment} )) | awk '{printf ("%0.1f",$1/10); }')
- if [ "X${SoCTemp}" != "X" ]; then
- echo -n ${SoCTemp} >/run/soc-temp
- fi
- # HDD/SSD temp
- DiskTemp=$(hddtemp -n /dev/sda)
- if [ "X${DiskTemp}" != "X" ]; then
- echo -n ${DiskTemp} >/run/hdd-temp
- fi
- # sleep 5 secs
- sleep 5
- done
- } # Main
- Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement