cpuTemperature() fixed raspberry pi sensors issue

This commit is contained in:
Sebastian Hildebrandt
2020-06-06 11:44:16 +02:00
parent a792db68d4
commit 1b78e9fec1
4 changed files with 38 additions and 31 deletions
+31 -30
View File
@@ -816,37 +816,38 @@ function cpuTemperature(callback) {
result.max = tdieTemp;
}
}
if (callback) { callback(result); }
resolve(result);
} else {
fs.stat('/sys/class/thermal/thermal_zone0/temp', function (err) {
if (err === null) {
fs.readFile('/sys/class/thermal/thermal_zone0/temp', function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
if (lines.length > 0) {
result.main = parseFloat(lines[0]) / 1000.0;
result.max = result.main;
}
}
if (callback) { callback(result); }
resolve(result);
});
} else {
exec('/opt/vc/bin/vcgencmd measure_temp', function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
if (lines.length > 0 && lines[0].indexOf('=')) {
result.main = parseFloat(lines[0].split('=')[1]);
result.max = result.main;
}
}
if (callback) { callback(result); }
resolve(result);
});
}
});
if (result.main !== -1.0 || result.max !== -1.0) {
if (callback) { callback(result); }
resolve(result);
}
}
fs.stat('/sys/class/thermal/thermal_zone0/temp', function (err) {
if (err === null) {
fs.readFile('/sys/class/thermal/thermal_zone0/temp', function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
if (lines.length > 0) {
result.main = parseFloat(lines[0]) / 1000.0;
result.max = result.main;
}
}
if (callback) { callback(result); }
resolve(result);
});
} else {
exec('/opt/vc/bin/vcgencmd measure_temp', function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
if (lines.length > 0 && lines[0].indexOf('=')) {
result.main = parseFloat(lines[0].split('=')[1]);
result.max = result.main;
}
}
if (callback) { callback(result); }
resolve(result);
});
}
});
});
});
}