debugage
This commit is contained in:
25
moha.php
25
moha.php
@ -13,7 +13,7 @@ $listProperties = array("powerSource" => "batterie");
|
||||
$listPropertiesKeys = array("expose");
|
||||
|
||||
//global variables
|
||||
$logLevel = ALL; // INFO | NOTICE | WARNING | ERROR | ALERT; //ALL;
|
||||
|
||||
$notificationLevel = ALERT | ERROR;
|
||||
$topics = array(); // list of topics
|
||||
$mids = array(); // list of message IDs
|
||||
@ -39,20 +39,20 @@ $flagHooks = false;
|
||||
|
||||
if ($testMode)
|
||||
{
|
||||
$logLevel = ALL; // INFO | NOTICE | WARNING | ERROR | ALERT; //ALL;
|
||||
$mqttServerIp = "192.168.1.253"; // IP address of mqttserver in test mode
|
||||
$dataPath = ".";
|
||||
$dataPath = "./";
|
||||
$logFile = "./moha.log"; // Path of log file
|
||||
$configDir = "./config"; // default config dir (production value is /etc/moha/)
|
||||
}else
|
||||
{
|
||||
$logLevel = INFO | NOTICE | WARNING | ERROR | ALERT;
|
||||
$mqttServerIp = "127.0.0.1"; // IP address of mqttserver in production mode
|
||||
$dataPath = "/usr/share/moha/";
|
||||
$logFile = "/var/log/moha.log"; // Path of log file
|
||||
$configDir = "/etc/moha"; // default config dir (production value is /etc/moha/)
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!init()) exit(1);
|
||||
|
||||
// gettext
|
||||
@ -70,7 +70,7 @@ function notify($message)
|
||||
return $result;
|
||||
}
|
||||
|
||||
function logger($level, $log, $pos = false, $notif = true)
|
||||
function logger($level, $log, $pos = "", $notif = true)
|
||||
{
|
||||
global $logFh, $logLevel, $notificationLevel, $logLevels;
|
||||
$logString = date("c") . ' ' . $logLevels[$level] . " " ;
|
||||
@ -100,7 +100,7 @@ function init()
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
if (! $logFh = fopen($logFile, "w") )
|
||||
{
|
||||
echo _("error opening log file");
|
||||
echo _("error opening log file in ") . getcwd();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -144,7 +144,7 @@ function endMoha()
|
||||
$client->disconnect();
|
||||
while ($connected)
|
||||
{
|
||||
if ( $x++ <= 60)
|
||||
if ( $x++ >= 60)
|
||||
{
|
||||
fclose($logFh);
|
||||
exit (1);
|
||||
@ -190,9 +190,9 @@ require "config/properties2log.php";
|
||||
require "mqtt_functions.php";
|
||||
require "events.php";
|
||||
require "db_functions.php";
|
||||
require "webserver.php";
|
||||
require "webserver/webserver.php";
|
||||
|
||||
logger(DEBUG, _("Loading stored devices datas"), __FILE__ . ":" . __LINE__);
|
||||
logger(DEBUG, _("Loading stored devices datas from ") . $dataPath . "moha.db", __FILE__ . ":" . __LINE__);
|
||||
if (loadDB($devices, $dataPath . "moha.db") === false)
|
||||
{
|
||||
logger(ERROR, _("Can not load device db"), __FILE__ . ":" . __LINE__);
|
||||
@ -251,6 +251,7 @@ foreach($topics as $name => $topic)
|
||||
// starting main loop
|
||||
logger(INFO, _("Starting loop"), __FILE__ . ":" . __LINE__, false);
|
||||
$oneshot = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
$client->loop(); // mqtt server loop()
|
||||
@ -280,7 +281,7 @@ while (true)
|
||||
}
|
||||
if($hooksInitialized == 0) // all hooks are not initialized
|
||||
{
|
||||
//$i = 1;
|
||||
$i = 1;
|
||||
foreach($hooks as $hookName => $hook)
|
||||
{
|
||||
if ($hook->initialized === false)
|
||||
@ -295,9 +296,9 @@ while (true)
|
||||
logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__);
|
||||
$flagHooks = true;
|
||||
|
||||
}else // executed when initialization finished
|
||||
}else // executed when hooks initialization finished but database init not finished
|
||||
{
|
||||
logger(DEBUG, _("looping"), __FILE__ . ":" . __LINE__);
|
||||
//logger(DEBUG, _("looping"), __FILE__ . ":" . __LINE__);
|
||||
|
||||
}
|
||||
checkEvents();
|
||||
|
Reference in New Issue
Block a user