a lot of debug
This commit is contained in:
@ -47,8 +47,11 @@ function htmlSend($socket, $text, $meta="")
|
||||
function apiServer($read)
|
||||
{
|
||||
global $topics, $indexDevices, $devices;
|
||||
|
||||
logger(DEBUG, "Function apiServer", __FILE__ . ":" . __LINE__);
|
||||
$array = array();
|
||||
$argList =array();
|
||||
|
||||
//logger(DEBUG, _("askWebserver function starting"), __FILE__ . ":" . __LINE__);
|
||||
if ( stream_select( $read, $array, $array, 0 ))
|
||||
{
|
||||
@ -88,50 +91,63 @@ function apiServer($read)
|
||||
switch($command)
|
||||
{
|
||||
case "dashboard":
|
||||
webDashboard($spawn, $argList["dashboard"]);
|
||||
apiDashboard($spawn, $argList["dashboard"]);
|
||||
break;
|
||||
case "browse":
|
||||
logger(DEBUG, _("Browsing"), __FILE__ . ":" . __LINE__);
|
||||
webBrowse($spawn, $argList);
|
||||
apiBrowse($spawn, $argList);
|
||||
//return true;
|
||||
break;
|
||||
case "get":
|
||||
logger(DEBUG, _("GET reached"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, webGet($argList));
|
||||
htmlSend($spawn, apiGet($argList));
|
||||
break;
|
||||
case "set":
|
||||
logger(DEBUG, _("SET reached"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, webSet($argList));
|
||||
htmlSend($spawn, apiSet($argList));
|
||||
break;
|
||||
case "dump":
|
||||
case "print":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, webPrint($argList, $command));
|
||||
htmlSend($spawn, apiPrint($argList, $command));
|
||||
break;
|
||||
case "notify":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, webNotify($argList));
|
||||
htmlSend($spawn, apiNotify($argList));
|
||||
logger(DEBUG, print_r($monitored, true), __FILE__ . ":" . __LINE__);
|
||||
break;
|
||||
case "type":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
//htmlSend($spawn, webDisplayByType($argList));
|
||||
//htmlSend($spawn, apiDisplayByType($argList));
|
||||
/*case "stats":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
displayStats($spawn, $argList);*/
|
||||
break;
|
||||
case "verbose":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, apiVerbose($argList));
|
||||
break;
|
||||
case "friendlyname":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, getFn($argList));
|
||||
break;
|
||||
case "property":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, PropertiesDashboard($argList));
|
||||
break;
|
||||
default:
|
||||
if (is_numeric(array_key_first($argList)))
|
||||
{
|
||||
webDashboard($spawn, $argList[0]);
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, $command . _(" so default action"), __FILE__ . ":" . __LINE__);
|
||||
if (file_exists("php://temp/". $command))
|
||||
if (is_numeric(array_key_first($argList)))
|
||||
{
|
||||
logger(DEBUG, $command . _(" is a file"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, file_get_contents("php://temp/". $command), 'Content-Type: image/png');
|
||||
apiDashboard($spawn, $argList[0]);
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, $command . _(" so default action"), __FILE__ . ":" . __LINE__);
|
||||
if (file_exists("php://temp/". $command))
|
||||
{
|
||||
logger(DEBUG, $command . _(" is a file"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, file_get_contents("php://temp/". $command), 'Content-Type: image/png');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (array_key_exists("page", $argList))
|
||||
@ -141,11 +157,11 @@ function apiServer($read)
|
||||
}
|
||||
}else
|
||||
{
|
||||
webDashboard($spawn);
|
||||
apiDashboard($spawn);
|
||||
}
|
||||
}else
|
||||
{
|
||||
webDashboard($spawn);
|
||||
apiDashboard($spawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
require_once "events.php";
|
||||
|
||||
function webDashboard($socket, $n="Général")
|
||||
function apiDashboard($socket, $n="Général")
|
||||
{
|
||||
global $dashboards, $indexDevices;
|
||||
require_once "apiserver/javascript.php";
|
||||
logger(DEBUG, _("webDashboard function"), __FILE__ . ":" . __LINE__);
|
||||
logger(INFO, _("apiDashboard function"), __FILE__ . ":" . __LINE__);
|
||||
$response = insertJavascript();
|
||||
|
||||
if(array_key_exists($n, $dashboards))
|
||||
@ -20,7 +20,7 @@ function webDashboard($socket, $n="Général")
|
||||
{
|
||||
$propertyObject = $device->properties[$property];
|
||||
$value = $propertyObject["value"];
|
||||
logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)));
|
||||
logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)), __FILE__ . ":" . __LINE__);
|
||||
$response .= $device->friendlyName . aliases($device->friendlyName, $property) . ' => ';
|
||||
if (array_key_exists("access", $propertyObject))
|
||||
{
|
||||
@ -130,7 +130,7 @@ function displayChoice($device, $propertyName, $value)
|
||||
function mkHTML($device, $propertyName, $choice)
|
||||
{
|
||||
$html = "";
|
||||
logger(DEBUG, "function mkHTML", __FILE__ . ":" . __LINE__);
|
||||
logger(INFO, "function mkHTML", __FILE__ . ":" . __LINE__);
|
||||
foreach ($choice as $key => $value)
|
||||
{
|
||||
$html .= '<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyName . "/" . strtolower($value) . '" value="' . $value . "\" onmouseup=\"setPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', '" . $value . "', '" . $propertyName . "')\">";
|
||||
@ -138,10 +138,10 @@ function mkHTML($device, $propertyName, $choice)
|
||||
return $html;
|
||||
}
|
||||
|
||||
function webBrowse($socket, $argList, $page="/browse")
|
||||
function apiBrowse($socket, $argList, $page="/browse")
|
||||
{
|
||||
global $topics, $devices, $listenPort,$indexDevices;
|
||||
logger(DEBUG, _("Generic response to choose device and property"), __FILE__ . ":" . __LINE__);
|
||||
logger(INFO, _("Generic response to choose device and property"), __FILE__ . ":" . __LINE__);
|
||||
//$response = "<html><header></header><body>" . _("unknown command") . "</body></html>";
|
||||
$response = "";
|
||||
$flag = false;
|
||||
@ -220,11 +220,11 @@ function webBrowse($socket, $argList, $page="/browse")
|
||||
}
|
||||
}else
|
||||
{
|
||||
$response = webListTopics();
|
||||
$response = apiListTopics();
|
||||
}
|
||||
}else
|
||||
{
|
||||
$response = webListTopics();
|
||||
$response = apiListTopics();
|
||||
}
|
||||
htmlSend($socket, $response);
|
||||
}
|
||||
@ -279,10 +279,10 @@ function iterateProperty($device, $property, $value, &$response, $tab="")
|
||||
}
|
||||
}
|
||||
|
||||
function webListTopics()
|
||||
function apiListTopics()
|
||||
{
|
||||
global $topics;
|
||||
logger(DEBUG, _("webListTopics function"));
|
||||
logger(INFO, _("apiListTopics function"), __FILE__ . ":" . __LINE__);
|
||||
$response = "";
|
||||
foreach ($topics as $name => $topic)
|
||||
{
|
||||
@ -291,7 +291,7 @@ function webListTopics()
|
||||
return $response;
|
||||
}
|
||||
|
||||
function webGet($argList)
|
||||
function apiGet($argList)
|
||||
{
|
||||
if(!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList))
|
||||
{
|
||||
@ -313,7 +313,7 @@ function webGet($argList)
|
||||
return $response;
|
||||
}
|
||||
|
||||
function webSet($argList)
|
||||
function apiSet($argList)
|
||||
{
|
||||
global $indexFriendlyName;
|
||||
if(!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList) or !array_key_exists("value", $argList))
|
||||
@ -331,13 +331,13 @@ function webSet($argList)
|
||||
{
|
||||
$response = "setting property " . $argList["property"] . " of " . $argList["fn"] . " to value: " . $argList["value"];
|
||||
$payload = array($argList["property"] => $argList["value"]);
|
||||
publish($argList["topic"] . "/" . $argList["fn"], $payload);
|
||||
publish($argList["topic"] . "/" . $argList["fn"], $payload, "set");
|
||||
//removeEvent($indexFriendlyName($argList["fn"]), $argList["property"], "OFF");
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
function webPrint($argList, $command)
|
||||
function apiPrint($argList, $command)
|
||||
{
|
||||
global $GLOBALS, $topics;
|
||||
if (array_key_exists($argList["object"], $GLOBALS))
|
||||
@ -386,7 +386,7 @@ function webPrint($argList, $command)
|
||||
return $response;
|
||||
}
|
||||
|
||||
function webNotify($argList)
|
||||
function apiNotify($argList)
|
||||
{
|
||||
if (!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList) or !array_key_exists("condition", $argList) or !array_key_exists("value", $argList))
|
||||
{
|
||||
@ -398,8 +398,118 @@ function webNotify($argList)
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
function apiVerbose($argList)
|
||||
{
|
||||
global $logLevel, $logLevels;
|
||||
logger(INFO, _("apiVerbose function"), __FILE__ . ":" . __LINE__);
|
||||
$response = "";
|
||||
//print_r($argList);
|
||||
foreach ($logLevels as $value => $level)
|
||||
{
|
||||
//print $level . " => " . $value . " ==>" . strtoupper(trim($argList["cmd"])) . EOL;
|
||||
if (strtoupper(trim($argList["verbose"])) == $level)
|
||||
{
|
||||
print "change of " . $level . EOL;
|
||||
$logLevel ^= $value;
|
||||
}
|
||||
if ($logLevel & $value)
|
||||
{
|
||||
$response .= $level . _(" is active") . EOLH;
|
||||
}else
|
||||
{
|
||||
$response .= $level . _(" is inactive") . EOLH;
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
function getFn($argList)
|
||||
{
|
||||
global $indexDevices;
|
||||
$jsonArray = array();
|
||||
logger(INFO, _("getFn function"), __FILE__ . ":" . __LINE__);
|
||||
|
||||
|
||||
if (array_key_exists("ieeeAddress", $argList))
|
||||
{
|
||||
logger(DEBUG, "ieeeAddress = " . $argList["ieeeAddress"], __FILE__ . ":" . __LINE__);
|
||||
if (array_key_exists($argList["ieeeAddress"], $indexDevices))
|
||||
{
|
||||
logger(DEBUG, "FriendlyName is " . $indexDevices[$argList["ieeeAddress"]]->friendlyName, __FILE__ . ":" . __LINE__);
|
||||
$response = '["' . $argList["ieeeAddress"] . '":"' . $indexDevices[$argList["ieeeAddress"]]->friendlyName . '"]';
|
||||
}
|
||||
}else
|
||||
{
|
||||
$flag = false;
|
||||
//$response = "{";
|
||||
foreach($indexDevices as $ieeeAddress => $device)
|
||||
{
|
||||
/*if ($flag == false)
|
||||
{
|
||||
$flag = true;
|
||||
}else
|
||||
{
|
||||
$response .= ', ';
|
||||
}
|
||||
*/
|
||||
//$response .= '"' . $ieeeAddress . '" : "' . $indexDevices[$ieeeAddress]->friendlyName . '"';
|
||||
$jsonArray[$ieeeAddress] = $indexDevices[$ieeeAddress]->friendlyName;
|
||||
array_multisort($jsonArray);
|
||||
}
|
||||
$response = json_encode($jsonArray, JSON_UNESCAPED_SLASHES);
|
||||
print $response;
|
||||
//print_r(json_decode($response));
|
||||
}
|
||||
logger(DEBUG, "response = " . $response, __FILE__ . ":" . __LINE__);
|
||||
return $response;
|
||||
}
|
||||
|
||||
function PropertiesDashboard($argList)
|
||||
{
|
||||
global $indexProperties;
|
||||
require_once "apiserver/javascript.php";
|
||||
logger(INFO, _("propertiesDashboard function"), __FILE__ . ":" . __LINE__);
|
||||
$response = insertJavascript();
|
||||
$property = $argList["property"];
|
||||
foreach ($indexProperties[$property] as $device)
|
||||
{
|
||||
$propertyObject = $device->properties[$property];
|
||||
$value = $propertyObject["value"];
|
||||
logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)), __FILE__ . ":" . __LINE__);
|
||||
$response .= $device->friendlyName . aliases($device->friendlyName, $property) . ' => ';
|
||||
if (array_key_exists("access", $propertyObject))
|
||||
{
|
||||
logger(DEBUG, _("Access = ") . $propertyObject["access"], __FILE__ . ":" . __LINE__);
|
||||
if(($propertyObject["access"] & 2))
|
||||
{
|
||||
logger(DEBUG, _("Write Access OK ") . ($propertyObject["access"] & 2), __FILE__ . ":" . __LINE__);
|
||||
$response .= " " . displayChoice($device, $property, $value);
|
||||
}
|
||||
if(($propertyObject["access"] & 4))
|
||||
{
|
||||
logger(DEBUG, _("can get value") . ($propertyObject["access"] & 4), __FILE__ . ":" . __LINE__);
|
||||
$response .= '<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyObject["name"] . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "','" . $device->friendlyName . "','" . $propertyObject["name"] . "')\">";
|
||||
}else
|
||||
{
|
||||
$response .= $value;
|
||||
}
|
||||
$response .= EOLH;
|
||||
}else
|
||||
{
|
||||
$response .= bool2string(_($value));
|
||||
if(array_key_exists("unit", $propertyObject))
|
||||
{
|
||||
$response .= $propertyObject["unit"];
|
||||
logger(DEBUG, _("unit = ") . $unit, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
$response .= EOLH;
|
||||
}
|
||||
}
|
||||
return "json=" . $response;
|
||||
}
|
||||
/*
|
||||
function webDisplayByType($argList)
|
||||
function apiDisplayByType($argList)
|
||||
{
|
||||
global $indexTypes, $config;
|
||||
require_once $config . "porpertiesbytype.php";
|
||||
|
Reference in New Issue
Block a user