diff --git a/apiserver/apiserver.php b/apiserver/apiserver.php
index 0ff5f48..888d355 100644
--- a/apiserver/apiserver.php
+++ b/apiserver/apiserver.php
@@ -90,13 +90,16 @@ function apiServer($read)
logger(DEBUG, _("command is ") . $command, __FILE__ . ":" . __LINE__);
switch($command)
{
+ case "?":
+ case "help":
+ htmlSend($spawn, help($argList));
+ break;
case "dashboard":
apiDashboard($spawn, $argList["dashboard"]);
break;
case "browse":
logger(DEBUG, _("Browsing"), __FILE__ . ":" . __LINE__);
apiBrowse($spawn, $argList);
- //return true;
break;
case "get":
logger(DEBUG, _("GET reached"), __FILE__ . ":" . __LINE__);
@@ -116,8 +119,8 @@ function apiServer($read)
htmlSend($spawn, apiNotify($argList));
logger(DEBUG, print_r($monitored, true), __FILE__ . ":" . __LINE__);
break;
- case "type":
- logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
+ //case "type":
+ //logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
//htmlSend($spawn, apiDisplayByType($argList));
case "enable":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
@@ -155,6 +158,10 @@ function apiServer($read)
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, test($argList));
break;
+ case "unavailable":
+ logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
+ htmlSend($spawn, unavailable($argList));
+ break;
default:
if (is_numeric(array_key_first($argList)))
{
diff --git a/apiserver/cmd_functions.php b/apiserver/cmd_functions.php
index 2e70761..5e00a05 100644
--- a/apiserver/cmd_functions.php
+++ b/apiserver/cmd_functions.php
@@ -606,22 +606,86 @@ function whoIsPresent($argList)
function test()
{
- global $hooks;
+ global $scripts;
$portes = array();
- $msg = "";
+ $msg = _("Opened doors:") . EOLH;
logger(DEBUG, _("Testing doors") , __FILE__ . ":" . __LINE__);
echo "testing doors";
- $portes = $hooks["test_portes"]->testPortes();
+ $portes = $scripts["test_portes"]->testPortes();
if (!empty($portes))
{
- $msg = _("Opened doors:") . EOLH;
foreach($portes as $value)
{
$msg .= $value . EOL;
}
+ }else
+ {
+ $msg .= _("No doors opened");
+ }
+ return $msg;
+}
+
+function unavailable()
+{
+ global $indexDevices;
+ $msg = _("List of unavailable devices:") . EOLH;
+ foreach($indexDevices as $ieeeAddress => $device)
+ {
+ if (key_exists("availability", $device->properties))
+ {
+ if ($device->properties["availability"]["value"] == "offline")
+ {
+ $msg .= $device->friendlyName . EOLH;
+ }
+ }
}
return $msg;
}
+function help()
+{
+ $msg = "
";
+ $msg .= "Commands | Description and Parameters | ";
+ $msg .= "
browse | Browse device List fn=friendlyname topic=topicname |
";
+ $msg .= "dashboard | Display dashboards Name of the dashboard |
";
+// $msg .= "deletedevice | |
";
+ $msg .= "disable | Disable a hook name of the hook |
";
+ $msg .= "dump | Display the content of a variable variable name |
";
+ $msg .= "enable | Enable a hook name of the hook |
";
+ $msg .= "friendlyname | Return friendlyname from ieeeadress ieeeadress of device |
";
+ $msg .= "get | Get value of the property of a device fn=friendlyname, topic=topic name, property=property name |
";
+ $msg .= "ispresent | Return the presence of a person Name of the person |
";
+ $msg .= "notify | Notify when property condition and value topic, fn, property, condition, value |
";
+// $msg .= "type | |
";
+ $msg .= "present | List persons present |
";
+ $msg .= "print | Dump the content of a variable variable name |
";
+ $msg .= "property | Display all devices with given property Property to display |
";
+ $msg .= "set | Set value of the property of a device fn=friendlyname, topic=topic name, property=property name |
";
+ $msg .= "test | Return all opened doors |
";
+ $msg .= "unavailable | Displey all unavalaible devices |
";
+ $msg .= "verbose | Enable or disable log levels " . htmlDisplayLoglevels() . " |
";
+ $msg .= "
";
+ return $msg;
+}
+
+function htmlDisplayLoglevels()
+{
+ global $logLevels;
+ $text = "";
+ $flag = false;
+
+ foreach($logLevels as $level)
+ {
+ if ($flag === true)
+ {
+ $text .= " ,";
+ }else
+ {
+ $flag = true;
+ }
+ $text .= $level;
+ }
+ return $text;
+}
?>
diff --git a/class/hook_class.php b/class/hook_class.php
index 72b9d62..b62c30b 100644
--- a/class/hook_class.php
+++ b/class/hook_class.php
@@ -18,10 +18,6 @@ class hook
{
$this->init();
}
- if (method_exists($this, "iterate"))
- {
- $this->iterate();
- }
foreach ($this->devicelist as $ieeeAddress => $property)
{
$this->propertyInitialized[$ieeeAddress][$property] = false;
diff --git a/class/main.php b/class/main.php
index 56a6892..544a53c 100644
--- a/class/main.php
+++ b/class/main.php
@@ -41,13 +41,16 @@ class device
public function __construct()
{
- $this->availability = array("value" => null, "functions" => array());
+ $this->properties["availability"] = array("value" => null, "functions" => array());
}
- public function set($property, $method = IDLE) //, $event = null)
+ public function set($property, $method = null) //, $event = null)
{
+ if ($method !== null)
+ {
+ $this->properties[$property]["method"] = $method;
+ }
publish($this->topic . "/" . $this->friendlyName, $this->payload, "set");//, $event);
- $this->properties[$property]["method"] = $method;
}
public function get()
diff --git a/config/config.php b/config/config.php
index a7262f1..1df224d 100644
--- a/config/config.php
+++ b/config/config.php
@@ -1,8 +1,9 @@
"Daniel",
diff --git a/config/properties2log.php b/config/properties2log.php
index a851c9e..ee81ece 100644
--- a/config/properties2log.php
+++ b/config/properties2log.php
@@ -35,7 +35,7 @@ $properties2log = array(
"UV" => null,
"indoortempc" => 0.5,
"indoorhumidity" => 0.5,
- "baromin" => 10,
+ "barominmb" => 10,
"presence" => null,
"vibration" => null
);
diff --git a/configVent.php b/configVent.php
index d3bcc01..c966cbb 100644
--- a/configVent.php
+++ b/configVent.php
@@ -1,22 +1,22 @@
array("N", "Nord", "0"),
+2 => array("NNE", "NordNordEst", "22,5"),
+3 => array("NE", "NordEst", "45"),
+4 => array("ENE", "EstNordEst", "67,5"),
+5 => array("E", "Est", "90"),
+6 => array("ESE", "EstSudEst", "112,5"),
+7 => array("SE", "SudEst", "135"),
+8 => array("SSE", "SudSudEst", "157,5"),
+9 => array("S", "Sud", "180"),
+10 => array("SSO", "SudSudOuest", "202,5"),
+11 => array("SO", "SudOuest", "225"),
+12 => array("OSO", "OuestSudOuest", "247,5"),
+13 => array("O", "Ouest", "270"),
+14 => array("ONO", "OuestNordOuest", "292,5"),
+15 => array("NO", "NordOuest", "315"),
+16 => array("NNO", "NordNordOuest", "337,5")
)
?>
diff --git a/configWatch.php b/configWatch.php
index b2dfa33..3a2f807 100644
--- a/configWatch.php
+++ b/configWatch.php
@@ -23,5 +23,12 @@ function configWatchInit()
}
}
+function configWatchStop()
+{
+// stop la surveillance
+ inotify_rm_watch($cwfd, $watch_descriptor);
+ // Destruction de l'instance inotify
+ fclose($cwfd);
+}
?>
diff --git a/daemons/presenceDaemon.php b/daemons/presenceDaemon.php
index ee5f30c..dd5149e 100755
--- a/daemons/presenceDaemon.php
+++ b/daemons/presenceDaemon.php
@@ -51,7 +51,7 @@ while (1)
}
}
$result = array();
- //ésleep(1);
+ //sleep(1);
}
function search($string)
@@ -63,15 +63,15 @@ function search($string)
//echo "searching in " . $string . EOL;
foreach ($macAddresses as $needle => $nom)
{
- echo $string . " ==> presenceD:" . $nom ." => " . $needle . EOL;
+ //echo $string . " ==> presenceD:" . $nom ." => " . $needle . EOL;
if (str_contains($string, $needle))
{
- echo "presenceD: found " . $needle . EOL;
+ //echo "presenceD: found " . $needle . EOL;
$presenceTemp[$nom] = true;
$flag = true;
}
}
- var_dump($presenceTemp);
+ //var_dump($presenceTemp);
return $presenceTemp;
}
@@ -87,7 +87,7 @@ function send($msg)
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $result contains the output string
- echo _("presenceDaemon: Curl sending message -") . $msg . __FILE__ . ":" . __LINE__ . EOL;
+ //echo _("presenceDaemon: Curl sending message -") . $msg . __FILE__ . ":" . __LINE__ . EOL;
if ($curlErr <= 5)
{
diff --git a/db_functions.php b/db_functions.php
index 9b76b83..8a906ee 100644
--- a/db_functions.php
+++ b/db_functions.php
@@ -88,6 +88,7 @@ function addDevice($topic, $fn, $jsonDevice, $group=false )
{
$device["device"]->type = $jsonDevice["type"];
$device["device"]->ieeeAddress = $jsonDevice["ieee_address"];
+ $hooks["availability"]->installHook($device);
if ( !empty($jsonDevice["power_source"] ))
{
$device["device"]->powerSource = $jsonDevice["power_source"];
@@ -126,7 +127,7 @@ function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
$device->properties[$string]["functions"] = array();
if(array_key_exists("access", $inputObject))
{
- if ($inputObject["access"] && 2)
+ if ($inputObject["access"] & 2)
{
$device->properties[$string]["method"] = IDLE;
}
@@ -231,7 +232,7 @@ function iterateDevice($topic, $fn, &$parentDevice, &$properties, $payloadArray,
$properties[$key]["functions"] = array();
if (array_key_exists("access", $properties[$key]))
{
- if ($properties[$key]["access]"] && 2)
+ if ($properties[$key]["access]"] & 2)
{
$properties[$key]["method"] = IDLE;
}
@@ -265,21 +266,17 @@ function getDevicesValues($topic)
{
if ($value["access"] & 4)
{
+ logger(DEBUG, _("Getting values of property: " . $property), __FILE__ . ":" . __LINE__ );
$device->payload[$property] = "";
- $flag = true;
+ $device->get();
break;
}
}
}
- //logger(DEBUG, print_r($device->payload, true), __FILE__ . ":" . __LINE__ );
- if ($flag === true)
- {
- $device->get();
- }
- }else
- {
+ }else
+ {
logger(DEBUG, _("no properties to get for device: " . $device->friendlyName ), __FILE__ . ":" . __LINE__ );
- }
+ }
}
}
@@ -295,6 +292,15 @@ function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key)
{
logger(INFO, sprintf(_("Logging Device property %s, %s"), $propertyTree . $key, bool2string($value)), __FILE__ . ":" . __LINE__);
$mohaDB->logProperty($parentDevice, $key, $value);
+ /*
+ if (!empty($propertiesLoggers))
+ {
+ foreach($propertiesLoggers as $logger)
+ {
+ $logger->callBack($parentDevice, $key, $value);
+ }
+ }
+ */
logger(DEBUG, sprintf(_("old value was %s, new is %s" ), bool2string($property["value"]), bool2string($value)), __FILE__ . ":" . __LINE__);
}
$property["value"] = $value;
diff --git a/hooks/scripts/availability.php b/hooks/scripts/availability.php
index b3afa7e..5d7c298 100644
--- a/hooks/scripts/availability.php
+++ b/hooks/scripts/availability.php
@@ -7,34 +7,31 @@ class availability extends hook
// by default all devices are listening for availability
protected $devicelist = array();
- function init()
- {
- global $indexDevices;
- $this->iterate();
- }
-
protected function iterate()
{
global $indexDevices;
foreach ($indexDevices as $ieeeAddress => $value)
{
- $deviceList[] = array( $ieeeAddress => "availability");
+ if (!key_exists("availability", $value->properties))
+ {
+ $value->properties["availability"] = "";
+ }
}
$this->installHooksFunction($indexDevices);
}
function installHooks(&$indexDevices)
{
- static $indexDevicesSize;
- $tmp = count($indexDevices);
- if ($tmp != $indexDevicesSize)
- {
- $this->iterate();
- $indexDevicesSize = $tmp;
- }
+ $this->installHooksFunction($indexDevices);
return false;
}
+ function installHook(&$device)
+ {
+ global $indexDevices;
+ $this->devicelist = array($device["device"]->ieeeAddress => "availability");
+ $this->installHooksFunction($indexDevices);
+ }
// callback fonction. Is called with these 3 parameters
// $device -> calling device
// $property -> parameter passed by mqtt
@@ -48,7 +45,7 @@ class availability extends hook
{
//echo "==========>>>>>> Availability $value" . EOL;
//if (!empty($device->availability))
- //{[ Torrent911.com]
+ //{
$log = ALERT;
//}else
//{
diff --git a/hooks/scripts/etage_temperature_int_ext.php b/hooks/scripts/etage_temperature_int_ext.php
index c062b9e..2ca4554 100644
--- a/hooks/scripts/etage_temperature_int_ext.php
+++ b/hooks/scripts/etage_temperature_int_ext.php
@@ -9,7 +9,7 @@ class etage_temperature_int_ext extends hook
protected $devicelist = array(
- METEO=> "tempc",
+ METEO => "tempc",
);
protected $portesList = array(
diff --git a/hooks/scripts/radiateurs.php b/hooks/scripts/radiateurs.php
index 4a90e48..ca09a32 100644
--- a/hooks/scripts/radiateurs.php
+++ b/hooks/scripts/radiateurs.php
@@ -49,11 +49,6 @@ class radiateurs extends hook
// ETAGE_CHAMBRE_RADIATEUR => 0
);
- function installHooks(&$indexDevices)
- {
- return $this->installHooksFunction($indexDevices);
- }
-
// callback fonction. Is called with these 3 parameters
public function callBack(&$device, $property, $value)
{
@@ -61,6 +56,7 @@ class radiateurs extends hook
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
if ($this->active === true)
{
+ // test mois entre mai et octobre
$now = date("MM");
if ($now <= 5 or $now >= 11)
{
@@ -98,17 +94,22 @@ class radiateurs extends hook
}
}
+ // state = true when a door or window is open
+
function send($device, $state)
{
global $indexDevices;
$flag = false;
- if ($state === false)
+ $setTo = 0;
+
+ if ($state === true)
{
$t = getValue($device->ieeeAddress, "current_heating_setpoint");
if ($t != $this->minTemp)
{
$this->prevTemp[$device->ieeeAddress] = getValue($device->ieeeAddress, "current_heating_setpoint");
}
+ $setTo = $minTemp;
}else
{
$r = array_keys($this->hvac, $device->ieeeAddress);
@@ -123,13 +124,18 @@ class radiateurs extends hook
}
if ($flag === false)
{
- $msg = array("current_heating_setpoint" => (!empty($this->prevTemp[$device->ieeeAddress])?$this->prevTemp[$device->ieeeAddress]:19));
- logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName), __FILE__ . ":" . __LINE__);
- $device->payload = $msg;
- $device->set("current_heating_setpoint", AUTO);
- $device->properties["current_heating_setpoint"]["method"] = AUTO;
+ $setTo = (!empty($this->prevTemp[$device->ieeeAddress])?$this->prevTemp[$device->ieeeAddress]:19);
+
}
}
+ if ($setTo <> 0)
+ {
+ $msg = array("current_heating_setpoint" => $setTo );
+ logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName), __FILE__ . ":" . __LINE__);
+ $device->payload = $msg;
+ $device->set("current_heating_setpoint", AUTO);
+ //$device->properties["current_heating_setpoint"]["method"] = AUTO;
+ }
}
}
$hooks["radiateurs"] = new radiateurs();
diff --git a/hooks/scripts/rdc_salon_eclairage.php b/hooks/scripts/rdc_salon_eclairage.php
index 7d28a24..e897f27 100644
--- a/hooks/scripts/rdc_salon_eclairage.php
+++ b/hooks/scripts/rdc_salon_eclairage.php
@@ -48,20 +48,22 @@ class rdc_salon_eclairage extends hook
$method = $deviceTarget->properties["state"]["method"];
logger(INFO, sprintf (_("CASE: %s => "), $param) . bool2string($value), __FILE__ . ":" . __LINE__);
//print_r(getValue(RDC_SALON_LUMINOSITE, "illuminance_lux"));
- if ($value == ON and $method == IDLE)
+ if ($value == ON)
{
- logger(INFO, _("illuminance value : ") . $illuminance, __FILE__ . ":" . __LINE__);
- if ($illuminance <= $this->luminance_min)
+ if ($method == IDLE)
{
- logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
- $this->send($deviceTarget, "ON", false, AUTO);
- removeEvent($deviceTarget, "state", "OFF");
+ logger(INFO, _("illuminance value : ") . $illuminance, __FILE__ . ":" . __LINE__);
+ if ($illuminance <= $this->luminance_min)
+ {
+ logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
+ $this->send($deviceTarget, "ON", false, AUTO);
+ removeEvent($deviceTarget, "state", "OFF");
+ }
}
- }else
+ }elseif ($method == AUTO)
{
logger(INFO, _("Value is OFF and method is ") . $method, __FILE__ . ":" . __LINE__);
- if ((testActionneurs($this->actionneurs) == false) and ($method == AUTO))
- //if ((getValue(RDC_SALON_MVMT, "occupancy") == OFF) and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF) and $method == AUTO)
+ if (testActionneurs($this->actionneurs) == 0)
{
logger(INFO, _("Setting to OFF"), __FILE__ . ":" . __LINE__);
$this->send($deviceTarget, "OFF", false, IDLE);
@@ -97,10 +99,13 @@ class rdc_salon_eclairage extends hook
case "state":
logger(INFO, _("CASE : State"), __FILE__ . ":" . __LINE__);
$method = $deviceTarget->properties["state"]["method"];
- if($value == "ON" and $method == IDLE)
+ if($value == "ON")
{
- $deviceTarget->properties["state"]["method"] = MANUAL;
- removeEvent($deviceTarget, "state", "OFF");
+ if ($method == IDLE)
+ {
+ $deviceTarget->properties["state"]["method"] = MANUAL;
+ removeEvent($deviceTarget, "state", "OFF");
+ }
}else
{
$deviceTarget->properties["state"]["method"] = IDLE;
diff --git a/hooks/scripts/rdc_sdb_eclairage.php b/hooks/scripts/rdc_sdb_eclairage.php
index af801dd..cc92335 100644
--- a/hooks/scripts/rdc_sdb_eclairage.php
+++ b/hooks/scripts/rdc_sdb_eclairage.php
@@ -9,9 +9,9 @@ class rdc_sdb_eclairage extends hook
// public $active = true;
//public $initlialized = false;
- public $delay = 3; // amount of time in $timeunit
- public $delayManual = 20; // amount of time in $timeunit for manual mode
- public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
+ //public $delay = 3; // amount of time in $timeunit
+ public $delayManual = 2; // amount of time in $timeunit for manual mode
+ public $timeUnit = "hour"; // unit of time for delay, second, minute, day, week, month, year
// list of devices we are listening to
// devicelist[$ieeAddress][0] => property to watch
@@ -45,42 +45,42 @@ class rdc_sdb_eclairage extends hook
$deviceTarget = &$indexDevices[RDC_SDB_WC_ECLAIRAGE];
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
$method = $deviceTarget->properties["state_l1"]["method"];
+ logger(DEBUG, "Method is " . $method, __FILE__ . ":" . __LINE__);
+
switch($property)
{
case "occupancy":
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
- if ($value == ON)
+ if ($value === ON)
{
- if($method == IDLE)
+ if($method === IDLE)
{
logger(DEBUG, _("lighting with method auto"), __FILE__ . ":" . __LINE__);
- //$deviceTarget->properties["state_l1"]["method"] = AUTO;
$this->send("ON", AUTO);
- removeEvent($deviceTarget, "state", "OFF");
+ //removeEvent($deviceTarget, "state", "OFF");
}
- }elseif (!testActionneurs($this->actionneurs))
+ }elseif ((testActionneurs($this->actionneurs) == 0) and ($method == AUTO))
{
logger(DEBUG, _("Actionneurs are all false"), __FILE__ . ":" . __LINE__);
$this->send("OFF", IDLE);
- removeEvent($deviceTarget, "state", "OFF");
+ //removeEvent($deviceTarget, "state", "OFF");
}
break;
case "state_l1":
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
- if ($method == IDLE)
+ if ($method === IDLE)
{
logger(DEBUG, _("State_l1 is IDLE"), __FILE__ . ":" . __LINE__);
- removeEvent($deviceTarget, "state_l1", "OFF");
+ //removeEvent($deviceTarget, "state_l1", "OFF");
$deviceTarget->properties["state_l1"]["method"] = MANUAL;
- //setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE);
+ setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE);
}
- }elseif ($value == "OFF" and $method == MANUAL)
+ }elseif ($value == "OFF")
{
$deviceTarget->properties["state_l1"]["method"] = IDLE;
removeEvent($deviceTarget, "state_l1", "OFF");
- //$deviceTarget->properties["state_l1"]["method"] = IDLE;
logger(DEBUG, _("State_l1 is false light is off and method is ") . $method, __FILE__ . ":" . __LINE__);
}
break;
@@ -93,17 +93,17 @@ class rdc_sdb_eclairage extends hook
}
}
- private function send($state, $method)
+ public function send($state, $method)
{
global $indexDevices;
$device = &$indexDevices[RDC_SDB_WC_ECLAIRAGE];
- $device->properties["state_l1"]["method"] = $method;
+ //$device->properties["state_l1"]["method"] = $method;
+ logger(DEBUG, "method = " . $device->properties["state_l1"]["method"], __FILE__ . ":" . __LINE__);
$msg = array("state_l1" => $state);
$device->payload = $msg;
- $device->set("state_l1");
+ $device->set("state_l1", $method);
logger(INFO, sprintf(_("publishing message: %s to %s"), $state, $device->friendlyName), __FILE__ . ":" . __LINE__);
-
}
}
$hooks["rdc_sdb_eclairage"] = new rdc_sdb_eclairage();
diff --git a/hooks/scripts/rdc_store.php b/hooks/scripts/rdc_store.php
index 05179d7..63c6e30 100644
--- a/hooks/scripts/rdc_store.php
+++ b/hooks/scripts/rdc_store.php
@@ -251,7 +251,7 @@ class rdc_store extends hook
{
global $indexDevices;
$deviceObject = $indexDevices[RDC_STORE];
- $msg = array("position" => $level);
+ $msg = array("position" => 100 - $level);
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg;
$deviceObject->set("position", $method);
diff --git a/hooks/scripts/rdc_temperature_int_ext.php b/hooks/scripts/rdc_temperature_int_ext.php
index b11cc8e..c6c59dd 100644
--- a/hooks/scripts/rdc_temperature_int_ext.php
+++ b/hooks/scripts/rdc_temperature_int_ext.php
@@ -29,7 +29,7 @@ class rdc_temperature_int_ext extends hook
// callback fonction. Is called with these 4 parameters
public function callBack(&$device, $property, $value)
{
- global $indexDevices, $hooks;
+ global $indexDevices, $scripts;
static $time;
$portes = array();
$status = -1;
@@ -76,7 +76,7 @@ class rdc_temperature_int_ext extends hook
//print_r($portes);
if ($status == 1)
{
- $portes = $hooks["test_portes"]->testPortes($this->portesList, false, false);
+ $portes = $scripts["test_portes"]->testPortes($this->portesList, false, false);
if (empty($portes))
{
$time = now();
@@ -88,7 +88,7 @@ class rdc_temperature_int_ext extends hook
}
}else
{
- $portes = $hooks["test_portes"]->testPortes($this->portesList, false, true);
+ $portes = $scripts["test_portes"]->testPortes($this->portesList, false, true);
if (!empty($portes))
{
$time = now();
diff --git a/moha.php b/moha.php
index 4b5e4d1..e66fe9e 100644
--- a/moha.php
+++ b/moha.php
@@ -1,14 +1,17 @@
"batterie");
$listPropertiesKeys = array("expose");
@@ -42,6 +47,8 @@ $indexTypes = array();
$indexProperties = array(); // index of properties
$hooksList = array(); // list of hooks to be included
$hooks = array(); // array of hooks
+$scripts = array(); // array of user's script
+$propertiesLoggers = array(); // array of loggers's callbacks
$topicsCallbacks = array(); // array of topics's callbacks
$notificationMethods = array(); // array of notification methods objects
$events = array(); // list of event objects
@@ -58,10 +65,9 @@ $hooksInitialized = 0; // are all hooks initialized ? false/true
$flagHooks = false;
$devicesRequest = false; // set to true when publishing device request to zigbee2mqtt
$presence = array(); // name and status of presence
+$timeLoop = new datetime("now");
-
-
-
+// initalisation
if (!init()) exit(1);
// (re)démarre le démon de présence
@@ -71,6 +77,10 @@ system("sudo /usr/bin/systemctl restart presenceD.service");
bindtextdomain("moha", "./locale");
textdomain("moha");
+######################################################################################################################
+## Fonctions ##
+######################################################################################################################
+
function notify($message, $device)
{
global $notificationMethods, $defaultUser;
@@ -192,10 +202,9 @@ function endMoha()
logger(ERROR, _("Can not store events db" ), __FILE__ . ":" . __LINE__);
}
if($testMode) file_put_contents($dataPath . "moha.devices", var_export($devices, true));
- // stop la surveillance
- inotify_rm_watch($cwfd, $watch_descriptor);
- // Destruction de l'instance inotify
- fclose($cwfd);
+
+ configWatchStop();
+
if ($connected)
{
$mid = $client->unsubscribe("#");
@@ -219,9 +228,12 @@ function connect2mqttServer()
global $client;
$client->onConnect('connectResponse');
}
+
+######################################################################################################################
+## Main program ##
+######################################################################################################################
+
logger(ALERT, _("starting moha"), __FILE__ . ":" . __LINE__);
-
-
logger(DEBUG, _("requiring config files -> devices_constants.php"), __FILE__ . ":" . __LINE__);
//include predefined file witch define constants for devices
if (is_readable($configDir . "/devices_constants.php"))
@@ -247,9 +259,6 @@ require "config/liste_telephones.php";
require "presence.php";
require "apiserver/apiserver.php";
require "configWatch.php";
-require $configDir . "/liste_telephones.php";
-
-
logger(DEBUG, _("Loading stored events datas from ") . $dataPath . "events.db", __FILE__ . ":" . __LINE__);
if (file_exists($dataPath . "events.db"))
@@ -290,6 +299,17 @@ if (!empty($hooksList)) // hooks to include if hooklist is not empty
$included = true;
}
+//making list of scripts to include
+listHooks("./scripts", $scriptsList);
+if (!empty($scriptsList))
+{
+ foreach ($scriptsList as $script)
+ {
+ logger(INFO, _("Including ") . $script, __FILE__ . ":" . __LINE__);
+ include $script;
+ }
+}
+
logger(DEBUG, _("Loading stored topics datas from ") . $dataPath . "topics.db", __FILE__ . ":" . __LINE__);
if (file_exists($dataPath . "topics.db"))
{
@@ -366,16 +386,25 @@ configWatchInit();
while (true)
{
+ // test if looping is more then 5 second and send and alert
+ $now = new datetime("now");
+ $testTime = clone $now;
+ $testTime->modify("-5 second");
+ if ($timeLoop < $testTime)
+ {
+ logger(ALERT, _("MOHA Looping is > to 5 seconds"), __FILE__ . ":" . __LINE__);
+ }
+ $timeLoop = $now;
+
$client->loop(); // mqtt server loop()
- if ($oneshot === false) // execute while the first loop :WARNING hooks can to be not initialized
+ if ($oneshot === false) // execute while the first loop :WARNING hooks may not be initialized
{
logger(DEBUG, _("Oneshot part of loop"), __FILE__ . ":" . __LINE__, false);
pws2mqttGetList();
-
$oneshot = true;
}
- $nn = 0;
+
if($hooksInitialized == 0) // all hooks are not initialized
{
$i = 1;
@@ -394,16 +423,17 @@ while (true)
}
}
$hooksInitialized = $i;
- }elseif($flagHooks === false)
+ /*}elseif($flagHooks === false)
{
logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__);
- $flagHooks = true;
- }else // executed when hooks initialization finished but database init not finished
+ $flagHooks = true;*/
+ }else // executed when hooks initialization finished but database init may be not finished
{
//logger(DEBUG, _("looping"), __FILE__ . ":" . __LINE__);
}
checkEvents();
checkTopicsAvailability();
+
if ($apiServerIsActive) apiServer($read);
// surveillance du dossier de configuration
@@ -420,13 +450,11 @@ while (true)
include $configDir . "/" . $event["name"];
}else
{
- logger(DEBUG, _("configWatch : mauvaise extension, n'inclus pas ") . $configDir . "/" . $event["name"], __FILE__ . ":" . __LINE__);
+ logger(DEBUG, _("configWatch : mauvaise extension, je n'inclus pas ") . $configDir . "/" . $event["name"], __FILE__ . ":" . __LINE__);
}
-
}
}
}
- //presence();
}
endMoha();
diff --git a/mqtt_functions.php b/mqtt_functions.php
index 8fd2348..f5a4d55 100644
--- a/mqtt_functions.php
+++ b/mqtt_functions.php
@@ -1,4 +1,6 @@
"contact",
+ GARAGE_PORTAIL => "contact",
+ GARAGE_PORTE => "contact",
+ ETAGE_PORTE_FENETRE => "contact",
+ ETAGE_CUISINE_FENETRE => "contact",
+ ETAGE_SALON_FENETRE => "contact",
+ RDC_CHAMBRE_BAIE => "contact",
+ RDC_SALON_BAIE => "contact",
);
- function installHooks(&$indexDevices)
+ /*function installHooks(&$indexDevices)
{
- return $this->installHooksFunction($indexDevices);
- }
+ return 1;
+ }*/
public function testPortes($deviceList=false, $send=true, $opened=true) :array
{
- global $indexDevices;
+ global $indexDevices, $hooks;
$portes = array();
logger(DEBUG, _("Function testPorte"), __FILE__ . ":" . __LINE__);
- if ($deviceList === false) $deviceList = $hooks["rdc_portes_ouvertes"]->devicelist;
+ if ($deviceList === false)
+ {
+ if (key_exists("rdc_portes_ouvertes", $hooks))
+ {
+ if (property_exists($hooks["rdc_portes_ouvertes"], devicelist))
+ {
+ $deviceList = $hooks["rdc_portes_ouvertes"]->devicelist;
+ }else
+ {
+ $deviceList = $this->deviceList;
+ }
+ }else
+ {
+ $deviceList = $this->deviceList;
+ }
+ }
+
$msg = "";
foreach ($deviceList as $device => $property)
{
@@ -55,8 +79,8 @@ class test_portes extends hook
return $portes;
}
}
-$hooks["test_portes"] = new test_portes();
-logger(DEBUG, _("Initializing event"), __FILE__ . ":" . __LINE__);
-$function = array($hooks["test_portes"], "testPortes");
+$scripts["test_portes"] = new test_portes();
+logger(DEBUG, _("Initializing test_portes"), __FILE__ . ":" . __LINE__);
+$function = array($scripts["test_portes"], "testPortes");
//setRecurrentEvent("test_portes", $function, "", "", 0, -1, "", "", false, 21);
?>
diff --git a/tools/install.sh b/tools/install.sh
index 0435ca1..76374cd 100755
--- a/tools/install.sh
+++ b/tools/install.sh
@@ -17,7 +17,14 @@ chown domotique:domotique -R /var/log/moha.log
# GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
systemctl daemon-reload
-systemctl enable presenceD.service
-systemctl enable moha.service
-
+R=`systemctl is-enabled presenceD.service`
+if [ $R != "enabled" ];then
+ echo "enabling presenceD.service"
+ systemctl enable presenceD.service
+fi
+R=`systemctl is-enabled moha.service`
+if [ $R != "enabled" ];then
+ echo "enabling moha.service"
+ systemctl enable moha.service
+fi
#must enable service
diff --git a/utils.php b/utils.php
index a6723fd..90ecd10 100644
--- a/utils.php
+++ b/utils.php
@@ -24,7 +24,7 @@ function checkTopicsAvailability()
{
if ($topic->status == 1)
{
- logger(DEBUG, "Topic is :" . $topicName . " and time is " . time() . " lastSeen is " . $topic->lastSeen, __FILE__ . ":" . __LINE__ );
+ //logger(DEBUG, "Topic is :" . $topicName . " and time is " . time() . " lastSeen is " . $topic->lastSeen, __FILE__ . ":" . __LINE__ );
if ((time() - $topic->lastSeen > $topic->timeOut*60) and ($topic->notificationSent == false))
{
if (logger(ALERT, $topicName . _(" is not available"), __FILE__ . ":" . __LINE__) == false);