"; @$r = file_get_contents("http://{$LB489_HOST_ADDR}/json"); if ($r) { $d = json_decode($r); show_device_info($d); show_device_data($d); } else { echo "

No response from LB-489 device

\n"; } print "\n"; print "\n"; exit(); function show_device_info($d) { print "

Device info

Vendor: {$d->vendor}
Type: {$d->type}
SN: {$d->sn}
Name: {$d->name}
"; } function show_device_data($d) { print"

Input data

"; // iterate all inputs for ($i = 0; $i < 4; ++$i) { // v can be null, when there's no sensor attached // or there's sensor failure if (is_null($d->input[$i]->v)) { $v = ""; } else { // preformat bool values, because default PHP string // conversion show false as empty string, exactly // the same as for null for ($j = 0; $j < 8; ++$j) { if (is_bool($d->input[$i]->v[$j])) { $d->input[$i]->v[$j] = $d->input[$i]->v[$j] ? "true" : "false"; } } $v = implode("
", $d->input[$i]->v); } // u can be null, when there's no sensor attached // or there's sensor failure // or there's no unit for particular sensor if (is_null($d->input[$i]->u)) { $u = ""; } else { $u = implode("
", $d->input[$i]->u); } $nr = $i + 1; print(" "); } print "
Input Name Mode Sensor ID Value Unit
$nr {$d->input[$i]->name} {$d->input[$i]->mode} {$d->input[$i]->id} $v $u
\n"; } ?>