1
0

debugging api and add notify command

This commit is contained in:
2022-02-02 21:18:44 +01:00
parent 85db4e3ff4
commit 18d5b74a96
9 changed files with 100 additions and 43 deletions

View File

@ -29,18 +29,27 @@ $dbInit = 0; // flag to indicate that devices db is initializedl
$connected = false; // connected to MQTT server
$included = false; // flag indicate scripts are loaded
$nSubscribed = 0; // Number of topics subsribed
$logFile = "/var/log/moha.log"; // Path of log file
$logFh = null; // filehandle of log file
$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;
$mqttServerIp = "127.0.0.1"; // IP address of mqttserver in production mode
if ($testMode)
{
$mqttServerIp = "192.168.1.253"; // IP address of mqttserver in test mode
$dataPath = ".";
$logFile = "./moha.log"; // Path of log file
$configDir = "./config"; // default config dir (production value is /etc/moha/)
}else
{
$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/)
}
if (!init()) exit(1);
// gettext
@ -79,7 +88,11 @@ 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()
@ -117,12 +130,12 @@ function listHooks($dir, &$hookList)
function endMoha()
{
global $testMode, $devices, $topics, $nSubscribed ,$client, $logFh, $connected;
global $testMode, $devices, $topics, $nSubscribed ,$client, $logFh, $connected, $dataPath;
$x = 0;
logger(WARNING, _("moha is ending"), __FILE__ . ":" . __LINE__);
storeDB($devices, "/usr/share/moha/moha.db");
if($testMode) file_put_contents("moha.devices", print_r($devices, true));
storeDB($devices, $dataPath . "moha.db");
if($testMode) file_put_contents($dataPath . "moha.devices", var_export($devices, true));
if ($connected)
{
$mid = $client->unsubscribe("#");
@ -152,7 +165,7 @@ require "class/main.php";
require "class/db.php";
require "class/hook_class.php";
require "utils.php";
require $configDir . "/properties2log.php";
require "config/properties2log.php";
require "mqtt_functions.php";
require "events.php";
require "db_functions.php";
@ -183,6 +196,11 @@ 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);
@ -242,7 +260,7 @@ while (true)
logger(INFO, _("Including ") . $hook, __FILE__ . ":" . __LINE__, false);
include $hook;
}
file_put_contents("/usr/share/moha/moha.devices", print_r($devices, true)); // debugging : save device list
file_put_contents($dataPath . "moha.devices", var_export($devices, true)); // debugging : save device list
$included = true;
}