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

@ -4,7 +4,7 @@ cli_set_process_title($title);
file_put_contents("/proc/".getmypid()."/comm",$title);
declare(ticks = 1);
$testMode = true;
$testMode = false;
$webServerIsActive = true;
require "constants.php";
@ -14,15 +14,17 @@ $listPropertiesKeys = array("expose");
//global variables
$notificationLevel = ALERT | ERROR;
$notificationLevel = ALERT;
$topics = array(); // list of topics
$mids = array(); // list of message IDs
$devices = array(); // array of device objetcs
$indexDevices = array(); // index of devices by ieee_address
$indexFriendlyNames = array(); // index of devices by freindly name
$indexTypes = array(); // index of devices by type
$indexFriendlyNames = array(); // index of devices by friendly name
$indexTypes = array();
$indexProperties = array(); // index of properties
$hooksList = array(); // list of hooks to be included
$hooks = array(); // array of hooks
$topicsCallbacks = array(); // array of topics's callbacks
$notificationMethods = array(); // array of notification methods objects
$events = array(); // list of event objects
$monitored = array(); // list of device to watch
@ -36,7 +38,7 @@ $curlErr = 0; // Number of errors returned by curl
$configDir = "./config"; // default config dir (production value is /etc/moha/)
$hooksInitialized = 0; // are all hooks initialized ? false/true
$flagHooks = false;
$devicesRequest = false; //say to true when publishing device request to zigbee2mqtt
if ($testMode)
{
@ -199,10 +201,10 @@ require "db_functions.php";
require "apiserver/apiserver.php";
// topics definition
listHooks("./topics_callbacks", $hooksList);
if (!empty($hooksList))
listHooks("./topics_callbacks", $topicsCallbacks);
if (!empty($topicsCallbacks))
{
foreach ($hooksList as $callback)
foreach ($topicsCallbacks as $callback)
{
logger(INFO, _("Including ") . $callback, __FILE__ . ":" . __LINE__);
include $callback;
@ -211,7 +213,7 @@ if (!empty($hooksList))
// making the list of hooks to include
listHooks("./hooks", $hooksList);
if (!empty($hooksList)) // some hooks to include if hooklist is not empty
if (!empty($hooksList)) // hooks to include if hooklist is not empty
{
foreach ($hooksList as $hookFile) // loop to include hooks in hookslist
{
@ -268,7 +270,6 @@ if (file_exists($dataPath . "events.db"))
logger(DEBUG, _("Program start"), __FILE__ . ":" . __LINE__, false);
$client = new Mosquitto\Client();
// defining callback functions
try
{
@ -298,6 +299,8 @@ foreach($topics as $name => &$topic)
$topic->status = false;
}
// starting main loop
logger(INFO, _("Starting loop"), __FILE__ . ":" . __LINE__, false);
$oneshot = false;
@ -305,56 +308,37 @@ $oneshot = false;
while (true)
{
$client->loop(); // mqtt server loop()
/*if (! $included) // hooks not already included
if ($oneshot === false) // execute while the first loop :WARNING hooks can to be not initialized
{
logger(DEBUG, _("Loading hooks list"), __FILE__ . ":" . __LINE__, false);
if (!empty($hooksList)) // some hooks to include if hooklist is not empty
{
foreach ($hooksList as $hookFile) // loop to include hooks in hookslist
{
logger(INFO, _("Including ") . $hookFile, __FILE__ . ":" . __LINE__, false);
include_once $hookFile;
}
if ($logLevel & DEBUG)
{
file_put_contents($dataPath . "moha.devices", var_export($devices, true)); // debugging : save device list
}
$included = true;
}
}else
{*/
logger(DEBUG, _("Oneshot part of loop"), __FILE__ . ":" . __LINE__, false);
pws2mqttGetList();
if ($oneshot === false) // execute while the first loop :WARNING hooks can to be not initialized
$oneshot = true;
}
$nn = 0;
if($hooksInitialized == 0) // all hooks are not initialized
{
$i = 1;
foreach($hooks as $hookName => &$hook)
{
logger(DEBUG, _("Oneshot part of loop"), __FILE__ . ":" . __LINE__, false);
$oneshot = true;
}
$nn = 0;
if($hooksInitialized == 0) // all hooks are not initialized
{
$i = 1;
foreach($hooks as $hookName => &$hook)
if ($hook->initialized === false and $hook->active === true)
{
if ($hook->initialized === false and $hook->active === true)
{
logger(WARNING, _("Initializing Hook not completely initialized :") . $hookName, __FILE__ . ":" . __LINE__);
$i &= $hook->installHooks($indexDevices);
}
logger(WARNING, _("Initializing Hook not completely initialized :") . $hookName, __FILE__ . ":" . __LINE__);
$i &= $hook->installHooks($indexDevices);
}
$hooksInitialized = $i;
}elseif($flagHooks === false)
{
logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__);
$flagHooks = true;
}else // executed when hooks initialization finished but database init not finished
{
//logger(DEBUG, _("looping"), __FILE__ . ":" . __LINE__);
}
checkEvents();
apiServer($read);
//}
$hooksInitialized = $i;
}elseif($flagHooks === false)
{
logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__);
$flagHooks = true;
}else // executed when hooks initialization finished but database init not finished
{
//logger(DEBUG, _("looping"), __FILE__ . ":" . __LINE__);
}
checkEvents();
apiServer($read);
}
endMoha();