added custom script plus some debugging
This commit is contained in:
33
moha.php
33
moha.php
@ -3,6 +3,10 @@
|
||||
//Constants
|
||||
define( "EOL", "\n");
|
||||
define("Z2M", "zigbee2mqtt");
|
||||
define("ON", 1);
|
||||
define("OFF", 0);
|
||||
define("AUTO", 0);
|
||||
define("MANUAL", 1);
|
||||
|
||||
declare(ticks = 1);
|
||||
|
||||
@ -26,6 +30,7 @@ $connected = false; // connected to MQTT server
|
||||
$included = false; // flag indicate scripts are loaded
|
||||
$nSubscribed = 0; // Number of topics subsribed
|
||||
$logFh = null; // filehandle of log file
|
||||
$curlErr = 0; // Number of errors returned by curl
|
||||
|
||||
// topics definition
|
||||
$topics["zigbee2mqtt"] = new topic;
|
||||
@ -41,15 +46,16 @@ if (!init()) exit(1);
|
||||
$client = new Mosquitto\Client();
|
||||
|
||||
// log levels
|
||||
define( "DEBUG", $client::LOG_DEBUG);
|
||||
define( "INFO", $client::LOG_INFO);
|
||||
define( "NOTICE", $client::LOG_NOTICE);
|
||||
define( "WARNING", $client::LOG_WARNING);
|
||||
define( "ERROR", $client::LOG_ERR);
|
||||
define( "DEBUG", $client::LOG_DEBUG); // => 16
|
||||
define( "INFO", $client::LOG_INFO); // => 1
|
||||
define( "NOTICE", $client::LOG_NOTICE); // => 2
|
||||
define( "WARNING", $client::LOG_WARNING); // => 4
|
||||
define( "ERROR", $client::LOG_ERR); // => 8
|
||||
define( "ALL", DEBUG | INFO | NOTICE | WARNING | ERROR);
|
||||
$logLevel = DEBUG;
|
||||
$logLevel = ALL;
|
||||
$notificationLevel = WARNING | ERROR;
|
||||
|
||||
|
||||
require "utils.php";
|
||||
require "mqtt_functions.php";
|
||||
require "events.php";
|
||||
@ -80,7 +86,7 @@ foreach($topics as $name => $topic)
|
||||
$mids[$topic->mid] = $name;
|
||||
$topic->status = false;
|
||||
}
|
||||
|
||||
$oneshot = false;
|
||||
while (true)
|
||||
{
|
||||
$client->loop();
|
||||
@ -99,6 +105,10 @@ while (true)
|
||||
}
|
||||
}elseif($dbInit == 2 and $included)
|
||||
{
|
||||
if ($oneshot === false) // execute once initialization finished
|
||||
{
|
||||
$oneshot = true;
|
||||
}
|
||||
checkEvents();
|
||||
}
|
||||
}
|
||||
@ -151,14 +161,7 @@ function endMoha()
|
||||
{
|
||||
global $topics, $nSubscribed ,$client, $logFh, $connected;
|
||||
$x = 0;
|
||||
/*foreach($topics as $topic => $object)
|
||||
{
|
||||
if ($object->status)
|
||||
{*/
|
||||
$mid = $client->unsubscribe("#");
|
||||
/*$mids[$mid] = $topic;
|
||||
}
|
||||
}*/
|
||||
$mid = $client->unsubscribe("#");
|
||||
|
||||
while ($connected)
|
||||
{
|
||||
|
Reference in New Issue
Block a user