Skip to content

Commit

Permalink
Add error handling if sensor not available
Browse files Browse the repository at this point in the history
  • Loading branch information
NEMS Linux committed Jun 2, 2020
1 parent 4b8410d commit 02f8a26
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions info2.sh
Expand Up @@ -468,8 +468,16 @@ EOQ;
if (isset($temperARR[0]->{'internal humidity'})) $temperARR['sensors']['humidity'] = 1 ?: $temperARR['sensors']['humidity'] = 0;
$temperTempOffset = floatval(trim(shell_exec("cat /usr/local/share/nems/nems.conf | grep temper.temp | printf '%s' $(cut -n -d '=' -f 2)")));
$temperHumOffset = floatval(trim(shell_exec("cat /usr/local/share/nems/nems.conf | grep temper.hum | printf '%s' $(cut -n -d '=' -f 2)")));
$temperARR['output']['temperature'] = ($temperARR[0]->{'internal temperature'} + $temperTempOffset);
$temperARR['output']['humidity'] = ($temperARR[0]->{'internal humidity'} + $temperHumOffset);
if (isset($temperARR[0]->{'internal temperature'})) {
$temperARR['output']['temperature'] = ($temperARR[0]->{'internal temperature'} + $temperTempOffset);
} else {
$temperARR['output']['temperature'] = 0;
}
if (isset($temperARR[0]->{'internal humidity'})) {
$temperARR['output']['humidity'] = ($temperARR[0]->{'internal humidity'} + $temperHumOffset);
} else {
$temperARR['output']['humidity'] = 0;
}
print_r(json_encode($temperARR));

break;
Expand Down

0 comments on commit 02f8a26

Please sign in to comment.