Skip to content

Commit a5049c6

Browse files
committed
Fix issue 426. Adds ability to read raspberry pi temperature readings
1 parent 12d3817 commit a5049c6

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

app/server/linux_json_api.sh

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,29 @@ cpu_intensive_processes() {
8484
}
8585

8686
cpu_temp() {
87-
88-
if type -P sensors 2>/dev/null; then
89-
returnString=`sensors`
90-
#amd
91-
if [[ "${returnString/"k10"}" != "${returnString}" ]] ; then
92-
$ECHO ${returnString##*k10} | $CUT -d ' ' -f 6 | $CUT -c 2- | $CUT -c 1-4
93-
#intel
94-
elif [[ "${returnString/"core"}" != "${returnString}" ]] ; then
95-
fromcore=${returnString##*"coretemp"}
96-
$ECHO ${fromcore##*Physical} | $CUT -d ' ' -f 3 | $CUT -c 2-5 | _parseAndPrint
97-
fi
98-
else
99-
$ECHO "[]" | _parseAndPrint
100-
fi
87+
local ID=*
88+
[ -f /etc/os-release ] && source /etc/os-release
89+
case "$ID" in
90+
"raspbian")
91+
cpu=$(</sys/class/thermal/thermal_zone0/temp)
92+
echo "$((cpu/1000))" | _parseAndPrint
93+
;;
94+
*)
95+
if type -P sensors 2>/dev/null; then
96+
returnString=`sensors`
97+
#amd
98+
if [[ "${returnString/"k10"}" != "${returnString}" ]] ; then
99+
$ECHO ${returnString##*k10} | $CUT -d ' ' -f 6 | $CUT -c 2- | $CUT -c 1-4
100+
#intel
101+
elif [[ "${returnString/"core"}" != "${returnString}" ]] ; then
102+
fromcore=${returnString##*"coretemp"}
103+
$ECHO ${fromcore##*Physical} | $CUT -d ' ' -f 3 | $CUT -c 2-5 | _parseAndPrint
104+
fi
105+
else
106+
$ECHO "[]" | _parseAndPrint
107+
fi
108+
;;
109+
esac
101110
}
102111

103112
# by Paul Colby (http://colby.id.au), no rights reserved ;)

0 commit comments

Comments
 (0)