Hi,
I have some code that is checking the presence of some devices on my network - which I have lifted and modified from another thread.
#!/etc/php5
<?php
function readActiveWiFiMacs ($ip,$wifi) {
// $check_openWRT="ssh root@".$ip." 'iw dev ".$wifi." station dump' | awk '/^Station/ {print substr($2,0);}'";
$check_openWRT="sshpass -p password ssh -o StrictHostKeyChecking=no root@".$ip." arp > /tmp/a8ree ; sleep 2 | awk '{print substr($4,0);}' /tmp/a8ree";
exec($check_openWRT,$addresses);
return ($addresses);
}
function sendCommand($item, $data) {
$url = "http://192.168.1.8:8080/rest/items/" . $item;
$options = array(
'http' => array(
'header' => "Content-type: text/plain\r\n",
'method' => 'POST',
'content' => $data //http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
// An array of mac addresses to be checked, adjust to fit your setup
$macAddresses = array(
'00:ed:ed:e9:5a:c4' => 'A_Phone',
'80:ea:e6:e2:e7:6c' => 'R_Phone',
'5c:8e:9e:02:8f:65' => 'D_Phone',
);
$users =array (); // An array to hold WiFi active status indexed by user name
foreach ($macAddresses as $mac => $user)
$users[$user]="0"; // As the openWrt will return only active clients, all known should be initially marked as OFF
$macs = readActiveWiFiMacs ("192.168.1.1","wlan0"); // Let's check the first access point
$macs = array_merge($macs,readActiveWiFiMacs ("192.168.1.1","wlan0")); // Let's see who is online at second AP
$macs = array_merge($macs,readActiveWiFiMacs ("192.168.1.1","wlan1")); // And on 5MHz network at second AP
foreach ($macs as $mac) // Mark users related to returned active mac addresses as active
$users[$macAddresses[$mac]]="1";
foreach ($users as $user => $status)
sendCommand('WiFi_'.$user,$status);
?>
The script works fine without issue for a period of time - sometimes days. Then I notice that this and all other scripts have stopped processing.
The only way in which I can get this to continue working without killing OpenHAB is to list the processes, identify the SSHPASS process and kill it.
Does anyone know why this would hang or a method of auto-killing it?
Thanks