making compatibility with mqtt's friendly names
This commit is contained in:
44
moha.php
44
moha.php
@ -35,12 +35,13 @@ class topic {
|
||||
|
||||
class device
|
||||
{
|
||||
public $method; //auto or manual
|
||||
public $topic;
|
||||
public $device;
|
||||
public $json;
|
||||
public $ieeeAddress;
|
||||
public $groupID;
|
||||
public $friendlyName;
|
||||
public $type;
|
||||
public $type; // if true then not a device but parameter of device(eg. topic/FRIENDLYNAME/PARAMETER
|
||||
public $powerSource;
|
||||
public $description;
|
||||
public $functions;
|
||||
@ -50,6 +51,11 @@ class device
|
||||
{
|
||||
publish($this, $this->payload, "set", $event);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
publish($this, $this->payload, "get", $event);
|
||||
}
|
||||
}
|
||||
|
||||
class event
|
||||
@ -136,15 +142,14 @@ $topics["zigbee2mqtt"] = new topic;
|
||||
bindtextdomain("moha", "./locale");
|
||||
textdomain("moha");
|
||||
|
||||
//signal handling
|
||||
pcntl_signal(SIGTERM, 'signalHandler');// Termination ('kill' was called)
|
||||
pcntl_signal(SIGHUP, 'signalHandler'); // Terminal log-out
|
||||
pcntl_signal(SIGINT, 'signalHandler');
|
||||
|
||||
if (!init()) exit(1);
|
||||
|
||||
require "mqtt_functions.php";
|
||||
require "utils.php";
|
||||
require "events.php";
|
||||
require "db_functions.php";
|
||||
|
||||
$client = new Mosquitto\Client();
|
||||
if (!init()) exit(1);
|
||||
$client->onConnect('connectResponse');
|
||||
$client->onDisconnect('disconnectResponse');
|
||||
$client->onSubscribe('subscribeResponse');
|
||||
@ -152,8 +157,16 @@ $client->onMessage('message');
|
||||
$client->onLog('logger');
|
||||
$client->onPublish('publishResponse');
|
||||
|
||||
$include 'mqtt_functions.php';
|
||||
|
||||
//signal handling
|
||||
pcntl_signal(SIGTERM, 'signalHandler');// Termination ('kill' was called)
|
||||
pcntl_signal(SIGHUP, 'signalHandler'); // Terminal log-out
|
||||
pcntl_signal(SIGINT, 'signalHandler');
|
||||
|
||||
// Program start
|
||||
|
||||
|
||||
$client->connect("192.168.1.253", 1883, 5);
|
||||
foreach($topics as $name => $topic)
|
||||
{
|
||||
//echo $name;
|
||||
@ -178,6 +191,10 @@ while (true)
|
||||
}elseif($dbInit and $included)
|
||||
{
|
||||
checkEvents();
|
||||
if (empty($flag))
|
||||
{
|
||||
$flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,7 +204,7 @@ function init()
|
||||
{
|
||||
global $logFh, $client;
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
$client->connect("192.168.1.253", 1883, 5);
|
||||
|
||||
if (! $logFh = fopen("moha.log", "w") )
|
||||
{
|
||||
echo _("error opening log file");
|
||||
@ -211,7 +228,7 @@ function loadHooks($dir)
|
||||
if (is_dir($file))
|
||||
{
|
||||
//echo "directory" . EOL;
|
||||
listHooks($dir . '/' . $file);
|
||||
loadHooks($dir . '/' . $file);
|
||||
}else
|
||||
{
|
||||
//echo "file" . EOL;
|
||||
@ -234,14 +251,15 @@ function endMoha()
|
||||
{
|
||||
if ($object->status)
|
||||
{
|
||||
$client->unsubscribe($topic);
|
||||
$mid = $client->unsubscribe($topic);
|
||||
$mids[$mid] = $topic;
|
||||
}
|
||||
}
|
||||
|
||||
while ($nSubscribed != 0)
|
||||
{
|
||||
//echo $nSubscribed;0x00124b0022ebac5c
|
||||
if ( $x++ > 30) exit (0);
|
||||
if ( $x++ > 60) exit (0);
|
||||
$client->loop();
|
||||
}
|
||||
$client->disconnect();
|
||||
|
Reference in New Issue
Block a user