some debugging and modifying hooks functions to fetch parameters
This commit is contained in:
parent
c97f05d2b6
commit
85a7fd7ed9
28
config/devices_constants.php
Normal file
28
config/devices_constants.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/************************************************************************************/
|
||||||
|
/*edit this file for defining constants of devices */
|
||||||
|
/*e.g. */
|
||||||
|
/* $deviceTable = array( <ieeeAdress of device> => <name of the constant>, ...); */
|
||||||
|
/************************************************************************************/
|
||||||
|
|
||||||
|
$deviceTable = array(
|
||||||
|
"0x00124b0022ebac5c" => "RDC_SALON_MVMT2",
|
||||||
|
"0x588e81fffe2cf695" => "RDC_SALON_MVMT",
|
||||||
|
"0x00124b001f900753" => "RDC_ENTREE_PORTE",
|
||||||
|
"0x04cf8cdf3c78aff0" => "RDC_SALON_LUMINOSITE",
|
||||||
|
"0x588e81fffe343e8f" => "RDC_SALON_ECLAIRAGE_PANNEAU",
|
||||||
|
"0x00158d0003f0f3b4" => "RDC_SDB_DOUCHE",
|
||||||
|
"0x842e14fffe1c0cd1" => "RDC_SDB_PLAFOND_MVMT",
|
||||||
|
"0x00124b0022ec05dc" => "RDC_SDB_MVMT",
|
||||||
|
"0x00158d0005c1a998" => "RDC_SDB_WC_ECLAIRAGE"
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach($deviceTable as $device => $name)
|
||||||
|
{
|
||||||
|
define($name, $device);
|
||||||
|
logger(INFO, _("defining constant ") . $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -93,8 +93,10 @@ function searchPropertyKey($fn, &$device, $object, $listPropertiesKeys)
|
|||||||
}
|
}
|
||||||
if ( isset($value->property))
|
if ( isset($value->property))
|
||||||
{
|
{
|
||||||
|
$string = $value->property;
|
||||||
//echo "property ===> " . $value->property . EOL;
|
//echo "property ===> " . $value->property . EOL;
|
||||||
$device->{$value->property} = null;
|
$device->{$string}["value"] = null;
|
||||||
|
$device->$string["functions"] = array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//print_r($device);
|
//print_r($device);
|
||||||
@ -163,9 +165,14 @@ function iterateDevice($topic, $fn, &$device, $payloadArray)
|
|||||||
{
|
{
|
||||||
$oldValue = $device->$key;
|
$oldValue = $device->$key;
|
||||||
|
|
||||||
}if ($oldValue != $value)
|
}else
|
||||||
{
|
{
|
||||||
$device->{$key} = $value;
|
$device->{$key}["value"] = null;
|
||||||
|
$device->$key["functions"] = array();
|
||||||
|
}
|
||||||
|
if ($oldValue != $value)
|
||||||
|
{
|
||||||
|
$device->$key["value"] = $value;
|
||||||
$changed[$fn]["key"] = $key;
|
$changed[$fn]["key"] = $key;
|
||||||
$changed[$fn]["value"] = $value;
|
$changed[$fn]["value"] = $value;
|
||||||
|
|
||||||
@ -180,13 +187,13 @@ function iterateDevice($topic, $fn, &$device, $payloadArray)
|
|||||||
echo " to " . $value . EOL;*/
|
echo " to " . $value . EOL;*/
|
||||||
}
|
}
|
||||||
//print_r($device->functions); print_r($value);
|
//print_r($device->functions); print_r($value);
|
||||||
|
print_r($device);
|
||||||
if (!empty($device->functions))
|
if (!empty($device->$key["functions"]))
|
||||||
{
|
{
|
||||||
//echo "executing notifications functions " . EOL;
|
echo "executing notifications functions " . EOL;
|
||||||
foreach($device->functions as $function)
|
foreach($device->$key["functions"] as $function)
|
||||||
{
|
{
|
||||||
//print_r($function);
|
print_r($function);
|
||||||
$function($device, $key, $value);
|
$function($device, $key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,19 +25,19 @@ class notificationFreemobile
|
|||||||
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
|
||||||
// $result contains the output string
|
// $result contains the output string
|
||||||
echo "1 curlErr =>"; var_dump($curlErr); echo EOL;
|
//echo "1 curlErr =>"; var_dump($curlErr); echo EOL;
|
||||||
if ($curlErr <= 10)
|
if ($curlErr <= 10)
|
||||||
{
|
{
|
||||||
$result = curl_exec($ch);
|
$result = curl_exec($ch);
|
||||||
echo "1 result => "; var_dump($result);echo EOL;
|
//echo "1 result => "; var_dump($result);echo EOL;
|
||||||
if ($result === false)
|
if ($result === false)
|
||||||
{
|
{
|
||||||
$curlErr += 1;
|
$curlErr += 1;
|
||||||
logger(ERROR, sprintf( _("Curl return error %d: %s when sending notification"), curl_errno($ch), curl_error($ch)), false);
|
logger(ERROR, sprintf( _("Curl return error %d: %s when sending notification"), curl_errno($ch), curl_error($ch)), false);
|
||||||
}else
|
}/*else
|
||||||
{
|
{
|
||||||
logger(INFO, sprintf(_("Curl return: %s when sending notification"), $result), false);
|
logger(INFO, sprintf(_("Curl return: %s when sending notification"), $result), false);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
// close curl resource to free up system resources
|
// close curl resource to free up system resources
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
@ -4,7 +4,14 @@ class rdc_salon_eclairage
|
|||||||
public $hookName = "rdc_salon_eclairage";
|
public $hookName = "rdc_salon_eclairage";
|
||||||
public $active = true;
|
public $active = true;
|
||||||
// list of devices we are listening to
|
// list of devices we are listening to
|
||||||
private $devicelist = array("0x00124b0022ebac5c", "0x588e81fffe2cf695", "0x00124b001f900753", "0x04cf8cdf3c78aff0");
|
|
||||||
|
private $devicelist = array(
|
||||||
|
RDC_SALON_MVMT => "occupancy",
|
||||||
|
RDC_SALON_MVMT2 => "occupancy",
|
||||||
|
RDC_ENTREE_PORTE => "contact",
|
||||||
|
RDC_SALON_LUMINOSITE => "illuminance_lux"
|
||||||
|
);
|
||||||
|
|
||||||
public $delay = 3; // amount of time in $timeunit
|
public $delay = 3; // amount of time in $timeunit
|
||||||
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
|
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
|
||||||
public $luminance_min = 80;
|
public $luminance_min = 80;
|
||||||
@ -18,9 +25,9 @@ class rdc_salon_eclairage
|
|||||||
// assigne the function to the sensors devices
|
// assigne the function to the sensors devices
|
||||||
if ($this->active === true)
|
if ($this->active === true)
|
||||||
{
|
{
|
||||||
foreach ($this->devicelist as $ieeeAddress)
|
foreach ($this->devicelist as $ieeeAddress => $param)
|
||||||
{
|
{
|
||||||
$indexDevices[$ieeeAddress]->functions[] = array($this,"callback");
|
$indexDevices[$ieeeAddress]->$param["functions"][] = array($this,"callback");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,13 +39,13 @@ class rdc_salon_eclairage
|
|||||||
switch($param)
|
switch($param)
|
||||||
{
|
{
|
||||||
case "occupancy":
|
case "occupancy":
|
||||||
if ($value == 1 and $indexDevices["0x04cf8cdf3c78aff0"]->illuminance_lux <= $this->luminance_min)
|
if ($value == 1 and $indexDevices[RDC_SALON_LUMINOSITE]->illuminance_lux["value"] <= $this->luminance_min)
|
||||||
{
|
{
|
||||||
$this->send("ON");
|
$this->send("ON");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "contact":
|
case "contact":
|
||||||
if ($value == false and $indexDevices["0x04cf8cdf3c78aff0"]->illuminance_lux <= $this->luminance_min)
|
if ($value == false and $indexDevices[RDC_SALON_LUMINOSITE]->illuminance_lux["value"] <= $this->luminance_min)
|
||||||
{
|
{
|
||||||
$this->send("ON");
|
$this->send("ON");
|
||||||
}
|
}
|
||||||
@ -54,7 +61,7 @@ class rdc_salon_eclairage
|
|||||||
{
|
{
|
||||||
global $devices, $indexDevices;
|
global $devices, $indexDevices;
|
||||||
$msg = array("state" => $state);
|
$msg = array("state" => $state);
|
||||||
$device = & $indexDevices["0x588e81fffe343e8f"];
|
$device = & $indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU];
|
||||||
logger(INFO, sprintf(_("publishing message: %s to %s"), $msg, $device->friendlyName));
|
logger(INFO, sprintf(_("publishing message: %s to %s"), $msg, $device->friendlyName));
|
||||||
$device->payload = $msg;
|
$device->payload = $msg;
|
||||||
$device->set(null);
|
$device->set(null);
|
||||||
|
@ -23,9 +23,9 @@ class rdc_sdb_eclairage
|
|||||||
// assigne the function to the sensors devices
|
// assigne the function to the sensors devices
|
||||||
if ($this->active === true)
|
if ($this->active === true)
|
||||||
{
|
{
|
||||||
foreach ($this->devicelist as $ieeeAddress)
|
foreach ($this->devicelist as $ieeeAddress => $param)
|
||||||
{
|
{
|
||||||
$indexDevices[$ieeeAddress]->functions[] = array($this,"callback");
|
$indexDevices[$ieeeAddress]->$param["functions"][] = array($this,"callback");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
moha.php
21
moha.php
@ -21,6 +21,7 @@ $topics = array(); // list of topics
|
|||||||
$mids = array(); // list of message IDs
|
$mids = array(); // list of message IDs
|
||||||
$devices = array(); // array of device objetcs
|
$devices = array(); // array of device objetcs
|
||||||
$indexDevices = array(); // index devices by ieee_address
|
$indexDevices = array(); // index devices by ieee_address
|
||||||
|
$hooksList = array(); // list of hooks to be included
|
||||||
$hooks = array(); // array of hooks
|
$hooks = array(); // array of hooks
|
||||||
$notificationMethods = array(); // array of notification methods objects
|
$notificationMethods = array(); // array of notification methods objects
|
||||||
$events = array(); // list of event objects
|
$events = array(); // list of event objects
|
||||||
@ -31,6 +32,7 @@ $included = false; // flag indicate scripts are loaded
|
|||||||
$nSubscribed = 0; // Number of topics subsribed
|
$nSubscribed = 0; // Number of topics subsribed
|
||||||
$logFh = null; // filehandle of log file
|
$logFh = null; // filehandle of log file
|
||||||
$curlErr = 0; // Number of errors returned by curl
|
$curlErr = 0; // Number of errors returned by curl
|
||||||
|
$configDir = "./config"; // default config dir (production value is /etc/moha/)
|
||||||
|
|
||||||
// topics definition
|
// topics definition
|
||||||
$topics["zigbee2mqtt"] = new topic;
|
$topics["zigbee2mqtt"] = new topic;
|
||||||
@ -55,13 +57,23 @@ define( "ALL", DEBUG | INFO | NOTICE | WARNING | ERROR);
|
|||||||
$logLevel = ALL;
|
$logLevel = ALL;
|
||||||
$notificationLevel = WARNING | ERROR;
|
$notificationLevel = WARNING | ERROR;
|
||||||
|
|
||||||
|
|
||||||
require "utils.php";
|
require "utils.php";
|
||||||
require "mqtt_functions.php";
|
require "mqtt_functions.php";
|
||||||
require "events.php";
|
require "events.php";
|
||||||
require "db_functions.php";
|
require "db_functions.php";
|
||||||
require "class/availability.php";
|
require "class/availability.php";
|
||||||
|
|
||||||
|
//include predefined file witch define constants for devices
|
||||||
|
if (is_readable($configDir . "/" . "devices_constants.php"))
|
||||||
|
{
|
||||||
|
$hooksList[] = $configDir . "/" . "devices_constants.php";
|
||||||
|
//echo "hooklist"; print_r($hooksList); echo EOL;
|
||||||
|
logger(INFO, sprintf(_("%s/devices_constants.define found, so it will be included :-)"), $configDir));
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
logger(WARNING, sprintf(_("%s/devices_constants.define not found, so not included :-)"), $configDir));
|
||||||
|
}
|
||||||
|
|
||||||
// defining callback functions
|
// defining callback functions
|
||||||
$client->onConnect('connectResponse');
|
$client->onConnect('connectResponse');
|
||||||
$client->onDisconnect('disconnectResponse');
|
$client->onDisconnect('disconnectResponse');
|
||||||
@ -92,14 +104,12 @@ while (true)
|
|||||||
$client->loop();
|
$client->loop();
|
||||||
if ($dbInit == 2 and ! $included)
|
if ($dbInit == 2 and ! $included)
|
||||||
{
|
{
|
||||||
$hooksList = array();
|
|
||||||
loadHooks("./hooks", $hooksList);
|
loadHooks("./hooks", $hooksList);
|
||||||
//print_r($hooksList);
|
|
||||||
if (!empty($hooksList))
|
if (!empty($hooksList))
|
||||||
{
|
{
|
||||||
foreach ($hooksList as $hook)
|
foreach ($hooksList as $hook)
|
||||||
{
|
{
|
||||||
echo "Including $hook" . EOL;
|
logger(INFO, _("Including ") . $hook . EOL);
|
||||||
include $hook;
|
include $hook;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,6 +143,7 @@ function loadHooks($dir, &$hookList)
|
|||||||
global $included;
|
global $included;
|
||||||
$files = scandir($dir);
|
$files = scandir($dir);
|
||||||
//print_r($files);
|
//print_r($files);
|
||||||
|
|
||||||
foreach ($files as $file)
|
foreach ($files as $file)
|
||||||
{
|
{
|
||||||
//echo "=====> $file" . EOL;
|
//echo "=====> $file" . EOL;
|
||||||
@ -155,8 +166,6 @@ function loadHooks($dir, &$hookList)
|
|||||||
$included = true;
|
$included = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function endMoha()
|
function endMoha()
|
||||||
{
|
{
|
||||||
global $topics, $nSubscribed ,$client, $logFh, $connected;
|
global $topics, $nSubscribed ,$client, $logFh, $connected;
|
||||||
|
@ -24,16 +24,15 @@ function notify($message)
|
|||||||
function logger($level, $log, $notif = true)
|
function logger($level, $log, $notif = true)
|
||||||
{
|
{
|
||||||
global $logFh, $logLevel, $notificationLevel;
|
global $logFh, $logLevel, $notificationLevel;
|
||||||
echo "=====>>>> $level => $logLevel => $notificationLevel" . EOL ;
|
//echo "=====>>>> $level => $logLevel => $notificationLevel" . EOL ;
|
||||||
echo $log .EOL;
|
//echo $log .EOL;
|
||||||
$test = $level & $logLevel;
|
if ($level & $logLevel)
|
||||||
if ($test != 0)
|
|
||||||
{
|
{
|
||||||
fwrite($logFh, "$level : $log" . EOL);
|
fwrite($logFh, "$level : $log" . EOL);
|
||||||
print ("$level : $log" . EOL);
|
print ("$level : $log" . EOL);
|
||||||
}
|
}
|
||||||
$test = $level & $notificationLevel;
|
$test = $level & $notificationLevel;
|
||||||
echo "test => " . $test . "notif =>" .$notif . EOL;
|
//echo "notif =>" .$notif . EOL;
|
||||||
if (($test != 0) and ($notif === true))
|
if (($test != 0) and ($notif === true))
|
||||||
{
|
{
|
||||||
if(notify("Moha\n" . $log) === false)
|
if(notify("Moha\n" . $log) === false)
|
||||||
|
Loading…
Reference in New Issue
Block a user