pws2mqtt is fonctional\ndebugging
This commit is contained in:
parent
e7618f9d86
commit
7acec3a3c4
@ -138,7 +138,7 @@ function iterateDevice($topic, $fn, &$device, $payloadArray)
|
||||
//echo "device =>";print_r($device);echo EOL;
|
||||
foreach($payloadArray as $key => $value)
|
||||
{
|
||||
$oldValue = 0;
|
||||
$oldValue = null;
|
||||
//echo "key =>"; print_r($key); echo EOL;
|
||||
//echo "value =>"; print_r($value); echo EOL;
|
||||
|
||||
@ -170,7 +170,7 @@ function iterateDevice($topic, $fn, &$device, $payloadArray)
|
||||
$device->{$key}["value"] = null;
|
||||
$device->$key["functions"] = array();
|
||||
}
|
||||
if ($oldValue != $value)
|
||||
if ($oldValue !== $value)
|
||||
{
|
||||
$device->$key["value"] = $value;
|
||||
$changed[$fn]["key"] = $key;
|
||||
|
30
moha.php
30
moha.php
@ -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,10 +217,13 @@ function loadHooks($dir, &$hookList)
|
||||
}elseif (strpos($file, ".php", -4) !== false)
|
||||
{
|
||||
//echo "file : " . $dir . "/" . $file . EOL;
|
||||
if (substr($file, -4) == ".php")
|
||||
{
|
||||
$hookList[] = $dir . "/" . $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//print_r($hookList);
|
||||
$included = true;
|
||||
}
|
||||
|
@ -4,6 +4,9 @@ function messageReceived($message)
|
||||
{
|
||||
global $topics, $logFh, $devices, $included;
|
||||
$topic = explode ("/", $message->topic);
|
||||
$callback = $topics[$topic[0]]->callback;
|
||||
$callback($topic, $message);
|
||||
/*
|
||||
if ($topic[1] == "bridge")
|
||||
{
|
||||
switch ($topic[2])
|
||||
@ -65,7 +68,7 @@ function messageReceived($message)
|
||||
}
|
||||
changeDevice($topic[0], $topic[1], $device["device"], $payloadArray);
|
||||
//fwrite($logFh, print_r($msg, true));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
// payload is an array :
|
||||
|
@ -1,8 +1,28 @@
|
||||
<?php
|
||||
$topics["pws2mqtt"] = new topic;
|
||||
|
||||
$topics["pws2mqtt"]->callback = function()
|
||||
$topics["pws2mqtt"]->callback = function($topic, $message)
|
||||
{
|
||||
global $topics, $logFh, $devices, $included;
|
||||
|
||||
$topic = explode ("/", $message->topic, 2); // get topic name
|
||||
$fnTree = explode ("/" , $topic[1]); // get friendlyname
|
||||
echo $topic[0] . " => " . $topic[1] . EOL;
|
||||
$device = & $devices[$topic[0]];
|
||||
foreach($fnTree as $fn)
|
||||
{
|
||||
//print_r($device) ;
|
||||
if (!isset($device[$fn])) //must not exists, but ...
|
||||
{
|
||||
logger(LOG_WARNING, $logFh, "init of " . $fn .EOL);
|
||||
$device[$fn] = array();
|
||||
$device[$fn]["device"] = new device;
|
||||
//addDevice($device[$fn], $fn, );
|
||||
}
|
||||
$device = & $device[$fn];
|
||||
print_r($device);
|
||||
}
|
||||
$payloadArray = json_decode($message->payload);
|
||||
changeDevice($topic[0], $topic[1], $device["device"], $payloadArray);
|
||||
print_r($device["device"]);
|
||||
}
|
||||
?>
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
$topics["zigbee2mqtt"]->callback = function()
|
||||
|
||||
$callback = function($topic, $message)
|
||||
{
|
||||
global $topics, $logFh, $devices, $included;
|
||||
if ($topic[1] == "bridge")
|
||||
@ -64,5 +65,8 @@ $topics["zigbee2mqtt"]->callback = function()
|
||||
changeDevice($topic[0], $topic[1], $device["device"], $payloadArray);
|
||||
//fwrite($logFh, print_r($msg, true));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$topics["zigbee2mqtt"] = new topic;
|
||||
$topics["zigbee2mqtt"]->callback = & $callback;
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user