1
0

pws2mqtt is fonctional\ndebugging

This commit is contained in:
2022-01-08 23:45:38 +01:00
parent e7618f9d86
commit 7acec3a3c4
5 changed files with 56 additions and 17 deletions

View File

@@ -31,10 +31,13 @@ $dbInit = false; // flag to indicate that desvices db is initialized
$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/)
if (!init()) exit(1);
function logger($level, $log, $notif = true)
{
global $logFh, $logLevel, $notificationLevel;
@@ -55,9 +58,7 @@ function logger($level, $log, $notif = true)
}
}
}
// topics definition
/*
logger(DEBUG, _("Require topics definition -> zigbee3mqtt"), false);
$topics["zigbee2mqtt"] = new topic;
require "topics_callbacks/zigbee2mqtt.php";
@@ -65,14 +66,14 @@ require "topics_callbacks/zigbee2mqtt.php";
logger(DEBUG, _("Require topics definition -> pws2mqtt"), false);
$topics["pws2mqtt"] = new topic;
require "topics_callbacks/pws2mqtt.php";
*/
logger(DEBUG, _("gettext init"), false);
// gettext
bindtextdomain("moha", "./locale");
textdomain("moha");
logger(DEBUG, _("lauching init function"), false);
if (!init()) exit(1);
logger(DEBUG, _('assigning variable : $client'), false);
$client = new Mosquitto\Client();
@@ -94,7 +95,16 @@ require "mqtt_functions.php";
require "events.php";
require "db_functions.php";
// topics definition
loadHooks("./topics_callbacks", $hooksList);
if (!empty($hooksList))
{
foreach ($hooksList as $callback)
{
logger(INFO, _("Including ") . $callback, false);
include $callback;
}
}
logger(DEBUG, _("requiring config files -> devices_constants.php"), false);
//include predefined file witch define constants for devices
@@ -177,10 +187,10 @@ endMoha();
function init()
{
global $logFh, $client;
global $logFile, $logFh, $client;
date_default_timezone_set('Europe/Paris');
if (! $logFh = fopen("moha.log", "w") )
if (! $logFh = fopen($logFile, "w") )
{
echo _("error opening log file");
return false;
@@ -197,7 +207,6 @@ function loadHooks($dir, &$hookList)
foreach ($files as $file)
{
//echo "=====> $file" . EOL;
if ($file != "." and $file != "..")
{
//echo "not . or .." . EOL;echo strpos($file, ".php", -4) . EOL;
@@ -208,7 +217,10 @@ function loadHooks($dir, &$hookList)
}elseif (strpos($file, ".php", -4) !== false)
{
//echo "file : " . $dir . "/" . $file . EOL;
$hookList[] = $dir . "/" . $file;
if (substr($file, -4) == ".php")
{
$hookList[] = $dir . "/" . $file;
}
}
}
}