1
0

a lot of debug

This commit is contained in:
2022-04-23 02:00:52 +02:00
parent f8fc3f63ec
commit d1f1065e44
21 changed files with 544 additions and 217 deletions

View File

@ -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 .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . 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";