- added dashboard\n- some debugging
This commit is contained in:
68
moha.php
68
moha.php
@ -34,6 +34,8 @@ $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;
|
||||
|
||||
|
||||
if ($testMode)
|
||||
{
|
||||
$mqttServerIp = "192.168.1.253"; // IP address of mqttserver in test mode
|
||||
@ -45,7 +47,7 @@ if ($testMode)
|
||||
$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/config"; // default config dir (production value is /etc/moha/)
|
||||
$configDir = "/etc/moha"; // default config dir (production value is /etc/moha/)
|
||||
|
||||
}
|
||||
|
||||
@ -88,11 +90,7 @@ function logger($level, $log, $pos = false, $notif = true)
|
||||
{
|
||||
logger(INFO, _("Notification not sent"), __FILE__ . ":" . __LINE__, false);
|
||||
}
|
||||
}else
|
||||
{
|
||||
logger(INFO, _("Notification not sent because of testMode"), __FILE__ . ":" . __LINE__, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function init()
|
||||
@ -134,7 +132,10 @@ function endMoha()
|
||||
$x = 0;
|
||||
|
||||
logger(WARNING, _("moha is ending"), __FILE__ . ":" . __LINE__);
|
||||
storeDB($devices, $dataPath . "moha.db");
|
||||
if (storeDB($devices, $dataPath . "moha.db") === false)
|
||||
{
|
||||
logger(ERROR, _("Can not store db" ), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if($testMode) file_put_contents($dataPath . "moha.devices", var_export($devices, true));
|
||||
if ($connected)
|
||||
{
|
||||
@ -160,6 +161,25 @@ function connect2mqttServer()
|
||||
$client->onConnect('connectResponse');
|
||||
}
|
||||
logger(WARNING, _("starting moha"), __FILE__ . ":" . __LINE__);
|
||||
|
||||
|
||||
logger(DEBUG, _("requiring config files -> devices_constants.php"), __FILE__ . ":" . __LINE__);
|
||||
//include predefined file witch define constants for devices
|
||||
if (is_readable($configDir . "/devices_constants.php"))
|
||||
{
|
||||
include $configDir . "/devices_constants.php";
|
||||
//echo "hooklist"; print_r($hooksList); echo EOL;
|
||||
logger(INFO, sprintf(_("%s/devices_constants.define found, so it has been included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
|
||||
}elseif(is_readable("config/devices_constants.php"))
|
||||
{
|
||||
include "config/devices_constants.php";
|
||||
//echo "hooklist"; print_r($hooksList); echo EOL;
|
||||
logger(INFO, sprintf(_("%s/devices_constants.define found, so it has been included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
|
||||
}else
|
||||
{
|
||||
logger(WARNING, sprintf(_("%s/devices_constants.define not found, so not included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
|
||||
}
|
||||
|
||||
logger(DEBUG, _("requiring php modules"), __FILE__ . ":" . __LINE__);
|
||||
require "class/main.php";
|
||||
require "class/db.php";
|
||||
@ -171,11 +191,11 @@ require "events.php";
|
||||
require "db_functions.php";
|
||||
require "webserver.php";
|
||||
|
||||
//logger(DEBUG, _('assigning variable $client to mosquitto class "client"'), false);
|
||||
//$client = new Mosquitto\Client();
|
||||
|
||||
logger(DEBUG, _("Loading stored devices datas"), __FILE__ . ":" . __LINE__);
|
||||
loadDB($devices, "moha.db");
|
||||
if (loadDB($devices, $dataPath . "moha.db") === false)
|
||||
{
|
||||
logger(ERROR, _("Can not load device db"), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
|
||||
|
||||
// topics definition
|
||||
@ -189,22 +209,6 @@ if (!empty($hooksList))
|
||||
}
|
||||
}
|
||||
|
||||
logger(DEBUG, _("requiring config files -> devices_constants.php"), __FILE__ . ":" . __LINE__);
|
||||
//include predefined file witch define constants for devices
|
||||
if (is_readable($configDir . "/" . "devices_constants.php"))
|
||||
{
|
||||
include $configDir . "/" . "devices_constants.php";
|
||||
//echo "hooklist"; print_r($hooksList); echo EOL;
|
||||
logger(INFO, sprintf(_("%s/devices_constants.define found, so it has been included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
|
||||
}elseif(is_readable("config/devices_constants.php"))
|
||||
{
|
||||
include "config/devices_constants.php";
|
||||
//echo "hooklist"; print_r($hooksList); echo EOL;
|
||||
logger(INFO, sprintf(_("%s/devices_constants.define found, so it has been included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
|
||||
}else
|
||||
{
|
||||
logger(WARNING, sprintf(_("%s/devices_constants.define not found, so not included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
|
||||
}
|
||||
|
||||
// making the list of hooks to include
|
||||
listHooks("./hooks", $hooksList);
|
||||
@ -252,13 +256,13 @@ while (true)
|
||||
if (! $included) // hooks not already included
|
||||
{
|
||||
logger(DEBUG, _("Making hooks list"), __FILE__ . ":" . __LINE__, false);
|
||||
getDevicesValues(); // TODO get the values of devices
|
||||
|
||||
if (!empty($hooksList)) // some hooks to include if hooklist is not empty
|
||||
{
|
||||
foreach ($hooksList as $hook) // loop to include hooks in hookslist
|
||||
foreach ($hooksList as $hookFile) // loop to include hooks in hookslist
|
||||
{
|
||||
logger(INFO, _("Including ") . $hook, __FILE__ . ":" . __LINE__, false);
|
||||
include $hook;
|
||||
logger(INFO, _("Including ") . $hookFile, __FILE__ . ":" . __LINE__, false);
|
||||
include $hookFile;
|
||||
}
|
||||
file_put_contents($dataPath . "moha.devices", var_export($devices, true)); // debugging : save device list
|
||||
$included = true;
|
||||
@ -270,11 +274,12 @@ while (true)
|
||||
if ($oneshot === false) // execute once initialization finished :WARNING hooks can to be not initialized
|
||||
{
|
||||
logger(DEBUG, _("Oneshot part of loop"), __FILE__ . ":" . __LINE__, false);
|
||||
|
||||
$oneshot = true;
|
||||
}
|
||||
if($hooksInitialized == 0) // all hooks are not initialized
|
||||
{
|
||||
$i = 1;
|
||||
//$i = 1;
|
||||
foreach($hooks as $hookName => $hook)
|
||||
{
|
||||
if ($hook->initialized === false)
|
||||
@ -288,6 +293,7 @@ while (true)
|
||||
{
|
||||
logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__);
|
||||
$flagHooks = true;
|
||||
getDevicesValues();exit (0);
|
||||
}
|
||||
checkEvents();
|
||||
askWebServer($read);
|
||||
|
Reference in New Issue
Block a user