mirror of
https://github.com/librenms/librenms-agent.git
synced 2024-05-09 09:54:52 +00:00
4s max time limit was causing some timeouts, especially given the two 1s sleeps. Especially with a lot of sentences coming back from the GPS chip it was probably not enough to always catch the right variables.
54 lines
1.2 KiB
PHP
Executable File
54 lines
1.2 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
|
|
$server = 'localhost';
|
|
$port = 2947;
|
|
|
|
set_time_limit(6);
|
|
ini_set('max_execution_time', 6);
|
|
|
|
|
|
$sock = @fsockopen($server, $port, $errno, $errstr, 2);
|
|
@fwrite($sock, "?WATCH={\"enable\":true}\n");
|
|
usleep(1000);
|
|
@fwrite($sock, "?POLL;\n");
|
|
usleep(1000);
|
|
for($tries = 0; $tries < 20; $tries++){
|
|
$resp = @fread($sock, 2000);
|
|
if (preg_match('/{"class":"POLL".+}/i', $resp, $m)){
|
|
$resp = $m[0];
|
|
break;
|
|
}
|
|
}
|
|
@fwrite($sock, "?WATCH={\"enable\":false}\n");
|
|
@fclose($sock);
|
|
|
|
if ($resp) {
|
|
$resp = json_decode($resp);
|
|
|
|
if ($resp) {
|
|
print "<<<gpsd>>>\n";
|
|
|
|
if (!empty($resp->tpv[0])) {
|
|
$tpv = $resp->tpv[0];
|
|
print "mode:{$tpv->mode}\n";
|
|
}
|
|
|
|
if (!empty($resp->sky[0])) {
|
|
$sky = $resp->sky[0];
|
|
|
|
$sat_count = count($sky->satellites);
|
|
$sat_used = count(array_filter($sky->satellites, "satellite_used"));
|
|
|
|
print "hdop:{$sky->hdop}\n";
|
|
print "vdop:{$sky->vdop}\n";
|
|
print "satellites:{$sat_count}\n";
|
|
print "satellites_used:{$sat_used}\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
function satellite_used($sat) {
|
|
return $sat->used;
|
|
}
|