1
0

- debug\n- webserver fonctionnel

This commit is contained in:
2022-03-04 22:30:16 +01:00
parent a29aa9b653
commit 9d10e51a24
17 changed files with 273 additions and 128 deletions

View File

@ -21,7 +21,7 @@ function loadDB(& $db, $filepath)
function mkDevicesDB($topic, $json, $group=false)
{
global $devices, $listProperties, $listPropertiesKeys, $indexDevices, $dbInit, $logFh, $hooks;
global $devices, $listProperties, $listPropertiesKeys, $indexDevices, $dbInit, $logFh, $hooks, $indexFriendlyNames;
if (!isset($devices[$topic]))
{
$devices[$topic]= array();
@ -63,11 +63,11 @@ function mkDevicesDB($topic, $json, $group=false)
fwrite($logFh, "################################START##################################################");
fwrite($logFh, var_export($devices, true));
fwrite($logFh, "################################END##################################################");
logger(DEBUG, _("Devices DB made"), __FILE__ . ":" . __LINE__);
logger(INFO, _("Devices DB made"), __FILE__ . ":" . __LINE__);
//print_r($devices);
}
function addDevice($topic, & $device, $fn, $jsonDevice )
function addDevice($topic, &$device, $fn, $jsonDevice )
{
global $listProperties, $listPropertiesKeys, $hooks, $indexDevices, $indexFriendlyNames;
$device->type = $jsonDevice->type;
@ -99,16 +99,17 @@ function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
{
logger(DEBUG, _("propertyKey exists filling properties"), __FILE__ . ":" . __LINE__ );
$string = $inputObject->property;
$device->properties[$string]["value"] = null;
$device->properties[$string]["functions"] = array();
if (!array_key_exists($string, $device->properties))
{
$device->properties[$string]["value"] = null;
}
$device->properties[$string]["functions"] = array();
foreach($inputObject as $key2 => $value2)
{
if ($key2 != "property")
{
$device->properties[$string][$key2] = $value2;
logger(DEBUG, sprintf(_("property %s value %s"), $key2, print_r($device->properties[$string][$key2])), __FILE__ . ":" . __LINE__ );
//logger(DEBUG, sprintf(_("property %s value %s"), $key2, print_r($device->properties[$string][$key2])), __FILE__ . ":" . __LINE__ );
}
}
}else
@ -154,8 +155,6 @@ function changeDevice($topic, $fn, &$device, $payloadArray)
//print_r($payloadArray);
if (!empty($payloadArray))
{
//echo "==================== New ChangeDevice =====================" .EOL;
iterateDevice($topic, $fn, $device, $device->properties, $payloadArray);
}else
{
@ -194,8 +193,10 @@ function iterateDevice($topic, $fn, $parentDevice, &$properties, $payloadArray,
{
$properties[$key] = array("value" => $value);
$properties[$key]["functions"] = array();
}elseif ($properties[$key]["value"] !== $value)
{
changeValue($properties[$key], $value, $parentDevice, $propertyTree, $key);
}
changeValue($properties[$key], $value, $parentDevice, $propertyTree, $key);
}
}
}
@ -217,7 +218,13 @@ function getDevicesValues($topic)
{
foreach($device->properties as $property => $value)
{
$device->payload[$property] = "";
if (array_key_exists("access", $value))
{
if ($value["access"] & 5)
{
$device->payload[$property] = "";
}
}
}
//logger(DEBUG, print_r($device->payload, true), __FILE__ . ":" . __LINE__ );
$device->get();
@ -230,47 +237,6 @@ function getDevicesValues($topic)
}
}
/*function getDeviceByFriendlyname(&$device, $topic, $fn, $payloadArray, $create = false)
{
global $devices, $indexDevices, $indexFriendlyNames;
$n = explode("/", $fn);
$device = &$devices[$topic];
foreach($n as $value)
{
//print_r($device[$value]);
if (array_key_exists($value, $device))
{
$device = &$device[$value];
}elseif($create === true)
{
$device[$value] = array();
$device = &$device[$value];
}else
{
logger(ERROR, sprintf(_(" device with friendlyname %s not found"), $fn), __FILE__ . ":" . __LINE__);
return false;
}
}
if (! array_key_exists("device", $device))
{
if ($create === true)
{
logger(WARNING, _("init of ") . $fn, __FILE__ . ":" . __LINE__);
$device["device"] = new device;
$device["device"]->type = $payloadArray->type;
$device["device"]->ieeeAddress = $payloadArray->ieeeAddress;
$device["device"]->friendlyname = $fn;
$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
$indexFriendlyNames[$topic][$fn] = & $device["device"];
}
}else
{
logger(INFO, sprintf(_(" device with friendlyname %s exists"), $fn), __FILE__ . ":" . __LINE__);
}
//var_dump($device);
return true;
}*/
function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key)
{
global $mohaDB;