a lot of bugs corrected\nrdc_wc_eclairage
This commit is contained in:
parent
9dde1c2d53
commit
c8772aeda0
@ -81,7 +81,7 @@ class db extends mysqli
|
|||||||
|
|
||||||
function moyenne($deviceObject, $property, $time)
|
function moyenne($deviceObject, $property, $time)
|
||||||
{
|
{
|
||||||
$query = "SELECT AVG(value) WHERE device='" . $deviceObject->ieeeAddress . "' AND property='" . $property . "' AND TIMEDIFF(NOW(), 'date') < " . $time;
|
$query = "SELECT AVG(value) FROM logs WHERE device='" . $deviceObject->ieeeAddress . "' AND property='" . $property . "' AND TIMEDIFF(NOW(), 'date') < " . $time;
|
||||||
if(!$this->result = $this->query($query))
|
if(!$this->result = $this->query($query))
|
||||||
{
|
{
|
||||||
logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__);
|
logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__);
|
||||||
|
@ -5,40 +5,45 @@ class hook
|
|||||||
public $active = true;
|
public $active = true;
|
||||||
public $initialized = false;
|
public $initialized = false;
|
||||||
protected $devicelist;
|
protected $devicelist;
|
||||||
|
protected $propertyInitialized;
|
||||||
|
|
||||||
// list of devices we are listening to
|
// list of devices we are listening to
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
logger(INFO, _("Initializing hook: ") . $this->hookName);
|
logger(INFO, _("Initializing hook: ") . $this->hookName);
|
||||||
$this->installHooks();
|
//$this->installHooks();
|
||||||
|
foreach ($this->devicelist as $ieeeAddress => $property)
|
||||||
|
{
|
||||||
|
$this->propertyInitialized[$ieeeAddress][$property] = false;
|
||||||
|
}
|
||||||
if (method_exists($this, "init"))
|
if (method_exists($this, "init"))
|
||||||
{
|
{
|
||||||
$this->init();
|
$this->init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function installHooks()
|
function installHooks(&$indexDevices)
|
||||||
{
|
{
|
||||||
global $indexDevices;
|
global $devices;
|
||||||
$result = true;
|
$result = true;
|
||||||
// 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 => $property2change)
|
foreach ($this->devicelist as $ieeeAddress => $property)
|
||||||
{
|
{
|
||||||
logger(DEBUG, _("Device: ") . $ieeeAddress, __FILE__ . ":" . __LINE__);
|
logger(DEBUG, _("Device: ") . $ieeeAddress, __FILE__ . ":" . __LINE__);
|
||||||
if ($property2change[1] === false)
|
if ($this->propertyInitialized[$ieeeAddress][$property] === false)
|
||||||
{
|
{
|
||||||
logger(DEBUG, _("Trying to store callback"), __FILE__ . ":" . __LINE__);
|
logger(DEBUG, _("Trying to store callback"), __FILE__ . ":" . __LINE__);
|
||||||
if (isset($indexDevices[$ieeeAddress]))
|
if (isset($indexDevices[$ieeeAddress]->properties[$property]["functions"]))
|
||||||
{
|
{
|
||||||
$property = $property2change[0];
|
$indexDevices[$ieeeAddress]->properties[$property]["functions"][$this->hookName] = array($this,"callback");
|
||||||
$indexDevices[$ieeeAddress]->properties[$property]["functions"][] = array($this,"callback");
|
$this->propertyInitialized[$ieeeAddress][$property] = true;
|
||||||
$property2change[1] = true;
|
logger(DEBUG, sprintf(_("Property '%s' of %s is initialized with callback"), $property, $indexDevices[$ieeeAddress]->friendlyName), __FILE__ . ":" . __LINE__);
|
||||||
logger(DEBUG, sprintf(_("Property '%s' is initialized with callback"), $property2change[0]), __FILE__ . ":" . __LINE__);
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
logger(WARNING, sprintf(_("Hook %s can not initialize Property '%s' of device %s"), $this->hookName, $property2change[0], $ieeeAddress), __FILE__ . ":" . __LINE__);
|
logger(WARNING, sprintf(_("Hook %s can not initialize Property '%s' of device %s"), $this->hookName, $property, $ieeeAddress), __FILE__ . ":" . __LINE__);
|
||||||
$result = false;
|
$result = false;
|
||||||
}
|
}
|
||||||
}else
|
}else
|
||||||
@ -53,12 +58,13 @@ class hook
|
|||||||
logger(INFO, $this->hookName . _(" initialized"), __FILE__ . ":" . __LINE__);
|
logger(INFO, $this->hookName . _(" initialized"), __FILE__ . ":" . __LINE__);
|
||||||
//var_dump($this);
|
//var_dump($this);
|
||||||
}
|
}
|
||||||
}else
|
}/*else
|
||||||
{
|
{
|
||||||
$this->initialized = true;
|
$this->initialized = true;
|
||||||
logger(INFO, $this->hookName . _("hook is disabled"), __FILE__ . ":" . __LINE__);
|
logger(INFO, $this->hookName . _("hook is disabled"), __FILE__ . ":" . __LINE__);
|
||||||
}
|
}*/
|
||||||
|
//print(var_export($indexDevices[$ieeeAddress],true));
|
||||||
|
//storeDB($devices,"debug.devices");
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ class watch
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function notifyCallback(&$device, $property, $value)
|
public function notifyCallback($device, $property, $value)
|
||||||
{
|
{
|
||||||
if (eval($this->function))
|
if (eval($this->function))
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
array(RDC_SDB_WC_ECLAIRAGE, "state_l2"),
|
array(RDC_SDB_WC_ECLAIRAGE, "state_l2"),
|
||||||
array(RDC_CHAMBRE_AMBIANCE, "state"),
|
array(RDC_CHAMBRE_AMBIANCE, "state"),
|
||||||
array(RDC_CHAMBRE_ECLAIRAGE, "state_l1"),
|
array(RDC_CHAMBRE_ECLAIRAGE, "state_l1"),
|
||||||
|
array(RDC_SDB_TEMP_HUM, "temperature"),
|
||||||
|
array(RDC_SDB_RADIATEUR, "current_heating_setpoint"),
|
||||||
array(METEO, "tempc"),
|
array(METEO, "tempc"),
|
||||||
array(METEO, "humidity"),
|
array(METEO, "humidity"),
|
||||||
array(METEO, "winddir"),
|
array(METEO, "winddir"),
|
||||||
|
@ -10,19 +10,35 @@ $deviceTable = array(
|
|||||||
"0x00124b0022ebac5c" => "RDC_SALON_MVMT2",
|
"0x00124b0022ebac5c" => "RDC_SALON_MVMT2",
|
||||||
"0x588e81fffe2cf695" => "RDC_SALON_MVMT",
|
"0x588e81fffe2cf695" => "RDC_SALON_MVMT",
|
||||||
"0x00124b001f900753" => "RDC_ENTREE_PORTE",
|
"0x00124b001f900753" => "RDC_ENTREE_PORTE",
|
||||||
|
"0x00158d0001923c21" => "RDC_CHAMBRE_RADIATEUR",
|
||||||
"0x04cf8cdf3c78aff0" => "RDC_SALON_LUMINOSITE",
|
"0x04cf8cdf3c78aff0" => "RDC_SALON_LUMINOSITE",
|
||||||
"0x588e81fffe343e8f" => "RDC_SALON_ECLAIRAGE_PANNEAU",
|
"0x588e81fffe343e8f" => "RDC_SALON_ECLAIRAGE_PANNEAU",
|
||||||
"0x00158d0003f0f3b4" => "RDC_SDB_DOUCHE_MVMT",
|
"0x804b50fffef31656" => "RDC_SALON_RADIATEUR",
|
||||||
|
"0xbc33acfffe458c65" => "RDC_SDB_RADIATEUR",
|
||||||
|
"0xa4c138b5a98db785" => "RDC_SDB_DOUCHE_MVMT",
|
||||||
"0x842e14fffe1c0cd1" => "RDC_SDB_PLAFOND_MVMT",
|
"0x842e14fffe1c0cd1" => "RDC_SDB_PLAFOND_MVMT",
|
||||||
"0x00124b0022ec05dc" => "RDC_SDB_MVMT",
|
"0x00124b0022ec05dc" => "RDC_SDB_MVMT",
|
||||||
"0x00158d0005c1a998" => "RDC_SDB_WC_ECLAIRAGE",
|
"0x00158d0005c1a998" => "RDC_SDB_WC_ECLAIRAGE",
|
||||||
|
"0xbc33acfffe458c65" => "RDC_SDB_RADIATEUR",
|
||||||
|
"0x00158d000533c45e" => "RDC_SDB_TEMP_HUM",
|
||||||
|
"0xa4c1384a2b586da9" => "RDC_WC_MVMT",
|
||||||
"0x00124b001f90ee7e" => "ENTREE_PORTE",
|
"0x00124b001f90ee7e" => "ENTREE_PORTE",
|
||||||
"0x00124b002226d9a2" => "GARAGE_PORTE",
|
"0x00124b002226d9a2" => "GARAGE_PORTE",
|
||||||
"0x00124b001f90e725" => "RDC_CHAMBRE_BAIE",
|
"0x00124b001f90e725" => "RDC_CHAMBRE_BAIE",
|
||||||
"0x00124b002226e384" => "RDC_SALON_BAIE",
|
"0x00124b002226e384" => "RDC_SALON_BAIE",
|
||||||
|
"0xbc33acfffe4583f7" => "ETAGE_SALON_RADIATEUR",
|
||||||
|
// "" => "ETAGE_CHAMBRE_RADIATEUR",
|
||||||
|
// "" => "ETAGE_SDB_RADIATEUR",
|
||||||
|
"0x5c0272fffec4de9e" => "ETAGE_BUREAU_RADIATEUR",
|
||||||
|
"0x00158d0001a0028c" => "ETAGE_BUREAU_FENETRE",
|
||||||
|
"0x00158d0001de080d" => "ETAGE_CHAMBRE_FENETRE",
|
||||||
"0x842e14fffe8c53a5" => "ETAGE_CUISINE_PLAN_TRAVAIL_INTER",
|
"0x842e14fffe8c53a5" => "ETAGE_CUISINE_PLAN_TRAVAIL_INTER",
|
||||||
"0x680ae2fffe403f22" => "ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE",
|
"0x680ae2fffe403f22" => "ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE",
|
||||||
"0xbc33acfffe65621b" => "ETAGE_CUISINE_PLAN_TRAVAIL_SPOT",
|
"0xbc33acfffe65621b" => "ETAGE_CUISINE_PLAN_TRAVAIL_SPOT",
|
||||||
|
"0x00158d0001ddefe1" => "ETAGE_ENTREE_PORTE",
|
||||||
|
"0x00158d00044fd579" => "ETAGE_SALON_FENETRE",
|
||||||
|
"0x00158d0004621e1f" => "ETAGE_CUISINE_FENETRE",
|
||||||
|
"0x00158d0001ddefe1" => "ETAGE_PORTE_FENETRE",
|
||||||
"0x086bd7fffe5aeab6" => "RDC_CHAMBRE_AMBIANCE",
|
"0x086bd7fffe5aeab6" => "RDC_CHAMBRE_AMBIANCE",
|
||||||
"0xbc33acfffe6561e4" => "RDC_CHAMBRE_ECLAIRAGE",
|
"0xbc33acfffe6561e4" => "RDC_CHAMBRE_ECLAIRAGE",
|
||||||
"0x00124b00234484ad" => "RDC_CHAMBRE_MVMT",
|
"0x00124b00234484ad" => "RDC_CHAMBRE_MVMT",
|
||||||
|
18
config/propertiesbytype.php
Normal file
18
config/propertiesbytype.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$propertyByType = array(
|
||||||
|
"light" => array(
|
||||||
|
"state",
|
||||||
|
"brightness",
|
||||||
|
"state_l1",
|
||||||
|
"state_l2"
|
||||||
|
)
|
||||||
|
"climate" => array(
|
||||||
|
"local_temperature",
|
||||||
|
"value",
|
||||||
|
"current_heating_setpoint",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
@ -5,18 +5,29 @@ logger(DEBUG,_("Including db_functions.php"), __FILE__ . ":" . __LINE__);
|
|||||||
//to save or not to save the DB, that is the question ...
|
//to save or not to save the DB, that is the question ...
|
||||||
function storeDB($db, $filepath)
|
function storeDB($db, $filepath)
|
||||||
{
|
{
|
||||||
|
logger(DEBUG,_("Storing database ") . $filepath, __FILE__ . ":" . __LINE__);
|
||||||
$data = serialize($db);
|
$data = serialize($db);
|
||||||
return file_put_contents($filepath, $data);
|
if (file_put_contents($filepath, $data) === false)
|
||||||
|
{
|
||||||
|
logger(DEBUG,_("Failed storing database ") . $filepath , __FILE__ . ":" . __LINE__);
|
||||||
|
return false;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadDB(& $db, $filepath)
|
function loadDB($filepath)
|
||||||
{
|
{
|
||||||
|
logger(DEBUG,_("Loading database ") . $filepath, __FILE__ . ":" . __LINE__);
|
||||||
$data = file_get_contents($filepath);
|
$data = file_get_contents($filepath);
|
||||||
if ($data === false)
|
if ($data === false)
|
||||||
{
|
{
|
||||||
|
logger(DEBUG,_("Failed loading database ") . $filepath , __FILE__ . ":" . __LINE__);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$db = unserialize($data);
|
$db = unserialize($data);
|
||||||
|
return $db;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mkDevicesDB($topic, $json, $group=false)
|
function mkDevicesDB($topic, $json, $group=false)
|
||||||
@ -52,14 +63,15 @@ function mkDevicesDB($topic, $json, $group=false)
|
|||||||
{
|
{
|
||||||
//print_r($device);
|
//print_r($device);
|
||||||
$device["device"]->groupID = $jsonDevice->id;
|
$device["device"]->groupID = $jsonDevice->id;
|
||||||
$indexDevices[$device["device"]->groupID] = & $device["device"];
|
//$indexDevices[$device["device"]->groupID] = & $device["device"];
|
||||||
$indexFriendlyNames[$topic][$fn] = & $device["device"];
|
//$indexFriendlyNames[$topic][$fn] = & $device["device"];
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
addDevice($topic, $device["device"], $fn, $jsonDevice);
|
addDevice($topic, $device["device"], $fn, $jsonDevice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$dbInit += 1;
|
$dbInit += 1;
|
||||||
|
mkIndexes();
|
||||||
fwrite($logFh, "################################START##################################################");
|
fwrite($logFh, "################################START##################################################");
|
||||||
fwrite($logFh, var_export($devices, true));
|
fwrite($logFh, var_export($devices, true));
|
||||||
fwrite($logFh, "################################END##################################################");
|
fwrite($logFh, "################################END##################################################");
|
||||||
@ -84,8 +96,8 @@ function addDevice($topic, &$device, $fn, $jsonDevice )
|
|||||||
searchPropertyValue($fn, $device, $jsonDevice, $listProperties);
|
searchPropertyValue($fn, $device, $jsonDevice, $listProperties);
|
||||||
|
|
||||||
//indexing device
|
//indexing device
|
||||||
$indexDevices[$device->ieeeAddress] = & $device;
|
//$indexDevices[$device->ieeeAddress] = & $device;
|
||||||
$indexFriendlyNames[$topic][$fn] = & $device;
|
//$indexFriendlyNames[$topic][$fn] = & $device;
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
|
function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
|
||||||
@ -102,8 +114,8 @@ function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
|
|||||||
if (!array_key_exists($string, $device->properties))
|
if (!array_key_exists($string, $device->properties))
|
||||||
{
|
{
|
||||||
$device->properties[$string]["value"] = null;
|
$device->properties[$string]["value"] = null;
|
||||||
}
|
|
||||||
$device->properties[$string]["functions"] = array();
|
$device->properties[$string]["functions"] = array();
|
||||||
|
}
|
||||||
foreach($inputObject as $key2 => $value2)
|
foreach($inputObject as $key2 => $value2)
|
||||||
{
|
{
|
||||||
if ($key2 != "property")
|
if ($key2 != "property")
|
||||||
@ -162,7 +174,7 @@ function changeDevice($topic, $fn, &$device, $payloadArray)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function iterateDevice($topic, $fn, $parentDevice, &$properties, $payloadArray, $propertyTree="")
|
function iterateDevice($topic, $fn, &$parentDevice, &$properties, $payloadArray, $propertyTree="")
|
||||||
{
|
{
|
||||||
global $changed, $mohaDB, $testMode;
|
global $changed, $mohaDB, $testMode;
|
||||||
//if (is_a($device, "device")) // = true if object
|
//if (is_a($device, "device")) // = true if object
|
||||||
@ -181,13 +193,16 @@ function iterateDevice($topic, $fn, $parentDevice, &$properties, $payloadArray,
|
|||||||
|
|
||||||
if ($valueType == "array")
|
if ($valueType == "array")
|
||||||
{
|
{
|
||||||
logger(DEBUG,_("valueType == array"), __FILE__ . ":" . __LINE__);
|
//logger(DEBUG,_("valueType == array"), __FILE__ . ":" . __LINE__);
|
||||||
$propertyTree .= $key . "/";
|
$propertyTree .= $key . "/";
|
||||||
|
if(!array_key_exists($key, $properties))
|
||||||
|
{
|
||||||
$properties[$key] = array();
|
$properties[$key] = array();
|
||||||
|
}
|
||||||
iterateDevice($topic, $fn, $parentDevice, $properties[$key], $value, $propertyTree);
|
iterateDevice($topic, $fn, $parentDevice, $properties[$key], $value, $propertyTree);
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
logger(DEBUG,_("valueType is ") . $valueType, __FILE__ . ":" . __LINE__);
|
//logger(DEBUG,_("valueType is ") . $valueType, __FILE__ . ":" . __LINE__);
|
||||||
//var_dump($properties);echo EOL;
|
//var_dump($properties);echo EOL;
|
||||||
if (!array_key_exists($key, $properties))
|
if (!array_key_exists($key, $properties))
|
||||||
{
|
{
|
||||||
@ -205,7 +220,7 @@ function getDevicesValues($topic)
|
|||||||
{
|
{
|
||||||
global $indexDevices, $topics;
|
global $indexDevices, $topics;
|
||||||
logger(DEBUG, _("getDevicesValues function" ), __FILE__ . ":" . __LINE__ );
|
logger(DEBUG, _("getDevicesValues function" ), __FILE__ . ":" . __LINE__ );
|
||||||
foreach($indexDevices as $device)
|
foreach($indexDevices as &$device)
|
||||||
{
|
{
|
||||||
if ($device->topic == $topic)
|
if ($device->topic == $topic)
|
||||||
{
|
{
|
||||||
@ -220,9 +235,10 @@ function getDevicesValues($topic)
|
|||||||
{
|
{
|
||||||
if (array_key_exists("access", $value))
|
if (array_key_exists("access", $value))
|
||||||
{
|
{
|
||||||
if ($value["access"] & 5)
|
if ($value["access"] & 4)
|
||||||
{
|
{
|
||||||
$device->payload[$property] = "";
|
$device->payload[$property] = "";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -256,23 +272,45 @@ function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mkIndexes($devices)
|
function mkIndexes()
|
||||||
{
|
{
|
||||||
global $indexDevices, $indexFriendlyNames;
|
global $devices, $indexDevices, $indexFriendlyNames;
|
||||||
|
$device = null;
|
||||||
logger(INFO, _("function mkIndexes"), __FILE__ . ":" . __LINE__);
|
logger(INFO, _("function mkIndexes"), __FILE__ . ":" . __LINE__);
|
||||||
foreach ($devices as $key => $object)
|
foreach ($devices as $key => &$object)
|
||||||
{
|
{
|
||||||
//print "======####" . $key . EOL;
|
print "======####" . $key . EOL;
|
||||||
if (is_a($object, "device"))
|
$r = iterate2device($object);
|
||||||
{
|
|
||||||
//echo "==========>" . $object->friendlyName . EOL;
|
|
||||||
$indexDevices[$object->ieeeAddress] = &$object;
|
|
||||||
$indexFriendlyNames[$object->friendlyName] = &$object;
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
mkIndexes($object);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function iterate2device(&$object)
|
||||||
|
{
|
||||||
|
global $indexDevices, $indexFriendlyNames, $indexTypes;
|
||||||
|
foreach ($object as $key => &$device)
|
||||||
|
{
|
||||||
|
if (is_a($device, "device"))
|
||||||
|
{
|
||||||
|
|
||||||
|
$object = &$device;
|
||||||
|
//print("=============" . $device->friendlyName);
|
||||||
|
if (!array_key_exists($object->ieeeAddress, $indexDevices))
|
||||||
|
{
|
||||||
|
//print("============>");
|
||||||
|
$indexDevices[$object->ieeeAddress] = &$object;
|
||||||
|
$indexFriendlyNames[$object->topic][$object->friendlyName] = &$object;
|
||||||
|
if (property_exists($object, "type"))
|
||||||
|
{
|
||||||
|
$indexTypes[$object->type][] = &$object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
iterate2device($device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -10,7 +10,7 @@ function checkEvents()
|
|||||||
$oldLevel = $logLevel;
|
$oldLevel = $logLevel;
|
||||||
$logLevel = DEBUG;
|
$logLevel = DEBUG;
|
||||||
$exception = false;
|
$exception = false;
|
||||||
foreach ($events as $key => $event)
|
foreach ($events as $key => &$event)
|
||||||
{
|
{
|
||||||
$now = now();
|
$now = now();
|
||||||
if (!empty($event->startDatetime))
|
if (!empty($event->startDatetime))
|
||||||
|
@ -15,7 +15,7 @@ class availability
|
|||||||
private function iterate()
|
private function iterate()
|
||||||
{
|
{
|
||||||
global $indexDevices;
|
global $indexDevices;
|
||||||
foreach ($indexDevices as $value)
|
foreach ($indexDevices as &$value)
|
||||||
{
|
{
|
||||||
$value->properties["availability"]["functions"][] = array($this,"callback");
|
$value->properties["availability"]["functions"][] = array($this,"callback");
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ class etage_plan_travail_eclairage extends hook
|
|||||||
public $active = false; //enable/disable hook (true => enabled)
|
public $active = false; //enable/disable hook (true => enabled)
|
||||||
public $delay = 3; // amount of time in $timeunit
|
public $delay = 3; // amount of time in $timeunit
|
||||||
public $timeUnit = "hour"; // unit of time for delay, second, minute, hour, day, week, month, year
|
public $timeUnit = "hour"; // unit of time for delay, second, minute, hour, day, week, month, year
|
||||||
protected $devicelist = array(ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE => array("state", false));
|
protected $devicelist = array(ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE => "state");
|
||||||
|
|
||||||
// callback fonction. Is called with these 3 parameters
|
// callback fonction. Is called with these 3 parameters
|
||||||
// $device -> calling device
|
// $device -> calling device
|
||||||
@ -14,6 +14,7 @@ class etage_plan_travail_eclairage extends hook
|
|||||||
// $value -> value of the property
|
// $value -> value of the property
|
||||||
public function callBack($device, $property, $value)
|
public function callBack($device, $property, $value)
|
||||||
{
|
{
|
||||||
|
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||||
// here your code
|
// here your code
|
||||||
if($value == "ON") // ON
|
if($value == "ON") // ON
|
||||||
{
|
{
|
||||||
|
128
hooks/scripts/radiateurs.php
Normal file
128
hooks/scripts/radiateurs.php
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
class radiateurs extends hook
|
||||||
|
{
|
||||||
|
public $hookName = "radiateurs";
|
||||||
|
public $active = false;
|
||||||
|
|
||||||
|
/* already defined in hook class */
|
||||||
|
// public $active = true;
|
||||||
|
//public $initlialized = false;
|
||||||
|
public $minTemp = 5;
|
||||||
|
public $delay = 3; // amount of time in $timeunit
|
||||||
|
public $delayManual = 15; // amount of time in $timeunit for manual mode
|
||||||
|
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
|
||||||
|
// list of devices we are listening to
|
||||||
|
|
||||||
|
// devicelist[$ieeAddress][0] => property to watch
|
||||||
|
// devicelist[$ieeAddress][1] => initialized = true
|
||||||
|
protected $devicelist = array(
|
||||||
|
RDC_CHAMBRE_BAIE => "contact",
|
||||||
|
RDC_SALON_BAIE => "contact",
|
||||||
|
RDC_ENTREE_PORTE => "contact",
|
||||||
|
ETAGE_ENTREE_PORTE => "contact",
|
||||||
|
ETAGE_CUISINE_FENETRE => "contact",
|
||||||
|
ETAGE_SALON_FENETRE => "contact",
|
||||||
|
ETAGE_SALON_PORTE_FENETRE => "contact",
|
||||||
|
ETAGE_CHAMBRE_FENETRE => "contact",
|
||||||
|
ETAGE_BUREAU_FENETRE => "contact"
|
||||||
|
);
|
||||||
|
|
||||||
|
PROTECTED $hvac = array(
|
||||||
|
RDC_CHAMBRE_BAIE => RDC_CHAMBRE_RADIATEUR,
|
||||||
|
RDC_SALON_BAIE => RDC_SALON_RADIATEUR,
|
||||||
|
RDC_ENTREE_PORTE => RDC_SALON_RADIATEUR,
|
||||||
|
RDC_GARAGE_PORTE => RDC_SDB_RADIATEUR,
|
||||||
|
ETAGE_ENTREE_PORTE => ETAGE_SALON_RADIATEUR,
|
||||||
|
ETAGE_CUISINE_FENETRE => ETAGE_SALON_RADIATEUR,
|
||||||
|
ETAGE_SALON_FENETRE => ETAGE_SALON_RADIATEUR,
|
||||||
|
ETAGE_SALON_PORTE_FENETRE => ETAGE_SALON_RADIATEUR,
|
||||||
|
// ETAGE_CHAMBRE_FENETRE => ETAGE_CHAMBRE_RADIATEUR,
|
||||||
|
ETAGE_BUREAU_FENETRE => ETAGE_BUREAU_RADIATEUR,
|
||||||
|
// ETAGE_SDB_FENETRE => ETAGE_SDB_RADIATEUR
|
||||||
|
);
|
||||||
|
|
||||||
|
protected $prevTemp = array(
|
||||||
|
RDC_CHAMBRE_RADIATEUR => 0,
|
||||||
|
RDC_SALON_RADIATEUR => 0,
|
||||||
|
RDC_SDB_RADIATEUR => 0,
|
||||||
|
ETAGE_SALON_RADIATEUR => 0,
|
||||||
|
ETAGE_BUREAU_RADIATEUR => 0
|
||||||
|
// ETAGE_SDB_RADIATEUR => 0,
|
||||||
|
// ETAGE_CHAMBRE_RADIATEUR => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
// callback fonction. Is called with these 3 parameters
|
||||||
|
public function callBack(&$device, $property, $value)
|
||||||
|
{
|
||||||
|
global $indexDevices;
|
||||||
|
$now = date("MM");
|
||||||
|
if ($now <= 5 or $now >= 11)
|
||||||
|
{
|
||||||
|
if ($value === false)
|
||||||
|
{
|
||||||
|
send($indexDevices[$hvac[$device->ieeeAddress]], true);
|
||||||
|
/* switch ($device->$ieeeAdress)
|
||||||
|
{
|
||||||
|
send($indexDevices[$hvac[$device->ieeeAddress]], false);
|
||||||
|
case RDC_CHAMBRE_BAIE:
|
||||||
|
break;
|
||||||
|
case RDC_SALON_BAIE:
|
||||||
|
case RDC_ENTREE_PORTE:
|
||||||
|
break;
|
||||||
|
case RDC_GARAGE_PORTE:
|
||||||
|
break;
|
||||||
|
case ETAGE_CUISINE_FENETRE:
|
||||||
|
case ETAGE_SALON_FENETRE:
|
||||||
|
case ETAGE_SALON_PORTE_FENETRE:
|
||||||
|
case ETAGE_ENTREE_PORTE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ETAGE_CHAMBRE_FENETRE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ETAGE_BUREAU_FENETRE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
}*/
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
send($indexDevices[$hvac[$device->ieeeAddress]], false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function send($device, $state)
|
||||||
|
{
|
||||||
|
global $indexDevices;
|
||||||
|
if ($state === false)
|
||||||
|
{
|
||||||
|
$t = getValue($device, "current_heating_setpoint");
|
||||||
|
if ($t != $minTemp)
|
||||||
|
{
|
||||||
|
$prevTemp[$device] = getValue($device, "current_heating_setpoint");
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
$r = array_keys($hvac, $device->ieeeAddress);
|
||||||
|
foreach($r as $value)
|
||||||
|
{
|
||||||
|
if (getValue($indexDevices[$value], "contact") === true)
|
||||||
|
{
|
||||||
|
$flag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($flag === false)
|
||||||
|
{
|
||||||
|
$msg = array("current_heating_setpoint" => (!empty($prevTemp[$device])?$prevTemp[$device]:19));
|
||||||
|
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__);
|
||||||
|
$deviceTarget->payload = $msg;
|
||||||
|
$deviceTarget->set();
|
||||||
|
$deviceTarget->method = AUTO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$hooks["radiateurs"] = new radiateurs();
|
||||||
|
|
||||||
|
?>
|
@ -9,10 +9,10 @@ class rdc_chambre_eclairage extends hook
|
|||||||
public $luminance_min = 60;
|
public $luminance_min = 60;
|
||||||
public $luminance_max = 3000;
|
public $luminance_max = 3000;
|
||||||
protected $devicelist = array(
|
protected $devicelist = array(
|
||||||
RDC_CHAMBRE_AMBIANCE => array("state", false), // "ON"/"OFF"
|
RDC_CHAMBRE_AMBIANCE => "state", // "ON"/"OFF"
|
||||||
RDC_CHAMBRE_ECLAIRAGE => array("state_l1", false), // "ON"/"OFF"
|
RDC_CHAMBRE_ECLAIRAGE => "state_l1", // "ON"/"OFF"
|
||||||
RDC_CHAMBRE_MVMT => array("occupancy", false),
|
RDC_CHAMBRE_MVMT => "occupancy",
|
||||||
RDC_CHAMBRE_ARMOIRE_GAUCHE => array("contact", false)
|
RDC_CHAMBRE_ARMOIRE_GAUCHE => "contact"
|
||||||
);
|
);
|
||||||
|
|
||||||
// callback fonction. Is called with these 3 parameters
|
// callback fonction. Is called with these 3 parameters
|
||||||
@ -25,9 +25,10 @@ class rdc_chambre_eclairage extends hook
|
|||||||
$lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->properties["illuminance_lux"];
|
$lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->properties["illuminance_lux"];
|
||||||
$targetAmbiance = $indexDevices[RDC_CHAMBRE_AMBIANCE];
|
$targetAmbiance = $indexDevices[RDC_CHAMBRE_AMBIANCE];
|
||||||
$targetEclairage = $indexDevices[RDC_CHAMBRE_ECLAIRAGE];
|
$targetEclairage = $indexDevices[RDC_CHAMBRE_ECLAIRAGE];
|
||||||
|
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||||
if ($property == "occupancy" and $value == ON)
|
if ($property == "occupancy" and $value == ON)
|
||||||
{
|
{
|
||||||
|
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
|
||||||
$this->send($targetAmbiance, "state", "ON", "OFF", AUTO);
|
$this->send($targetAmbiance, "state", "ON", "OFF", AUTO);
|
||||||
}elseif ($property == "contact")
|
}elseif ($property == "contact")
|
||||||
{
|
{
|
||||||
@ -42,7 +43,7 @@ class rdc_chambre_eclairage extends hook
|
|||||||
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
|
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function send($deviceObject, $property, $state, $delayState = false, $method = MANUAL)
|
private function send(&$deviceObject, $property, $state, $delayState = false, $method = MANUAL)
|
||||||
{
|
{
|
||||||
global $indexDevices;
|
global $indexDevices;
|
||||||
$msg = array($property => $state);
|
$msg = array($property => $state);
|
||||||
|
@ -5,19 +5,21 @@ class alerte_intrusion extends hook
|
|||||||
public $active = true;
|
public $active = true;
|
||||||
|
|
||||||
protected $devicelist = array(
|
protected $devicelist = array(
|
||||||
ENTREE_PORTE => array("contact", false),
|
ENTREE_PORTE => "contact",
|
||||||
GARAGE_PORTE => array("contact", false),
|
GARAGE_PORTE => "contact",
|
||||||
RDC_CHAMBRE_BAIE => array("contact", false),
|
RDC_CHAMBRE_BAIE => "contact",
|
||||||
RDC_SALON_BAIE => array("contact", false));
|
RDC_SALON_BAIE => "contact"
|
||||||
|
);
|
||||||
|
|
||||||
public $delay = 3; // amount of time in $timeunit
|
public $delay = 3; // amount of time in $timeunit
|
||||||
public $delayManual = 10; // amount of time in $timeunit for manual mode
|
public $delayManual = 10; // amount of time in $timeunit for manual mode
|
||||||
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
|
||||||
|
|
||||||
// callback fonction. Is called with these 4 parameters
|
// callback fonction. Is called with these 4 parameters
|
||||||
public function callBack($device, $param, $value)
|
public function callBack($device, $property, $value)
|
||||||
{
|
{
|
||||||
switch($param)
|
|
||||||
|
switch($property)
|
||||||
{
|
{
|
||||||
case "contact":
|
case "contact":
|
||||||
if ($value == false)
|
if ($value == false)
|
||||||
|
@ -6,10 +6,10 @@ class rdc_salon_eclairage extends hook
|
|||||||
public $active = true;
|
public $active = true;
|
||||||
// list of devices we are listening to
|
// list of devices we are listening to
|
||||||
protected $devicelist = array(
|
protected $devicelist = array(
|
||||||
RDC_SALON_MVMT => array("occupancy", false),
|
RDC_SALON_MVMT => "occupancy",
|
||||||
RDC_SALON_MVMT2 => array("occupancy", false),
|
RDC_SALON_MVMT2 => "occupancy",
|
||||||
RDC_ENTREE_PORTE => array("contact", false),
|
RDC_ENTREE_PORTE => "contact",
|
||||||
RDC_SALON_LUMINOSITE => array("illuminance_lux", false)
|
RDC_SALON_LUMINOSITE => "illuminance_lux"
|
||||||
);
|
);
|
||||||
|
|
||||||
public $delay = 3; // amount of time in $timeunit
|
public $delay = 3; // amount of time in $timeunit
|
||||||
@ -18,7 +18,7 @@ class rdc_salon_eclairage extends hook
|
|||||||
public $luminance_max = 100;
|
public $luminance_max = 100;
|
||||||
|
|
||||||
// callback fonction. Is called with these 4 parameters
|
// callback fonction. Is called with these 4 parameters
|
||||||
public function callBack(&$device, $param, $value)
|
public function callBack($device, $param, $value)
|
||||||
{
|
{
|
||||||
global $indexDevices;
|
global $indexDevices;
|
||||||
logger(INFO, _("hook : rdc_salon_eclairage"), __FILE__ . ":" . __LINE__);
|
logger(INFO, _("hook : rdc_salon_eclairage"), __FILE__ . ":" . __LINE__);
|
||||||
@ -33,12 +33,17 @@ class rdc_salon_eclairage extends hook
|
|||||||
case "occupancy":
|
case "occupancy":
|
||||||
logger(INFO, _("CASE: Occupancy => ") . bool2string($value), __FILE__ . ":" . __LINE__);
|
logger(INFO, _("CASE: Occupancy => ") . bool2string($value), __FILE__ . ":" . __LINE__);
|
||||||
//print_r(getValue(RDC_SALON_LUMINOSITE, "illuminance_lux"));
|
//print_r(getValue(RDC_SALON_LUMINOSITE, "illuminance_lux"));
|
||||||
if ($value == ON and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min)
|
if ($value == ON)
|
||||||
|
{
|
||||||
|
$illuminance = getValue(RDC_SALON_LUMINOSITE, "illuminance_lux");
|
||||||
|
logger(INFO, _("illuminance value : ") . $illuminance, __FILE__ . ":" . __LINE__);
|
||||||
|
if ($illuminance <= $this->luminance_min)
|
||||||
{
|
{
|
||||||
logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
|
logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
|
||||||
$this->send($deviceTarget, "ON", null, AUTO);
|
$this->send($deviceTarget, "ON", null, AUTO);
|
||||||
removeEvent($deviceTarget, "state", "OFF");
|
removeEvent($deviceTarget, "state", "OFF");
|
||||||
}elseif ($value == OFF)
|
}
|
||||||
|
}else
|
||||||
{
|
{
|
||||||
logger(INFO, _("Value is OFF"), __FILE__ . ":" . __LINE__);
|
logger(INFO, _("Value is OFF"), __FILE__ . ":" . __LINE__);
|
||||||
if (getValue(RDC_SALON_MVMT, "occupancy") == OFF and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF))
|
if (getValue(RDC_SALON_MVMT, "occupancy") == OFF and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF))
|
||||||
@ -74,7 +79,7 @@ class rdc_salon_eclairage extends hook
|
|||||||
{
|
{
|
||||||
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", "OFF", true);
|
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", "OFF", true);
|
||||||
}
|
}
|
||||||
}elseif ($value <= $this->luminance_min and (getValue(RDC_SALON_MVMT, "occupancy") == ON OR getValue(RDC_SALON_MVMT2,"occupancy") == ON))
|
}elseif ($value <= $this->luminance_min and (getValue(RDC_SALON_MVMT, "occupancy") == ON || getValue(RDC_SALON_MVMT2,"occupancy") == ON))
|
||||||
{
|
{
|
||||||
logger(INFO, _("illuminance < min and movement detected"), __FILE__ . ":" . __LINE__);
|
logger(INFO, _("illuminance < min and movement detected"), __FILE__ . ":" . __LINE__);
|
||||||
$this->send($deviceTarget, "ON", null, AUTO);
|
$this->send($deviceTarget, "ON", null, AUTO);
|
||||||
|
@ -17,10 +17,10 @@ class rdc_sdb_eclairage extends hook
|
|||||||
// devicelist[$ieeAddress][0] => property to watch
|
// devicelist[$ieeAddress][0] => property to watch
|
||||||
// devicelist[$ieeAddress][1] => initialized = true
|
// devicelist[$ieeAddress][1] => initialized = true
|
||||||
protected $devicelist = array(
|
protected $devicelist = array(
|
||||||
//RDC_SDB_DOUCHE_MVMT => array("occupancy", false),
|
RDC_SDB_DOUCHE_MVMT => "occupancy",
|
||||||
RDC_SDB_PLAFOND_MVMT => array("occupancy", false),
|
RDC_SDB_PLAFOND_MVMT => "occupancy",
|
||||||
RDC_SDB_MVMT => array("occupancy", false),
|
RDC_SDB_MVMT => "occupancy",
|
||||||
RDC_SDB_WC_ECLAIRAGE => array("state_l1", false)
|
RDC_SDB_WC_ECLAIRAGE => "state_l1"
|
||||||
);
|
);
|
||||||
|
|
||||||
// callback fonction. Is called with these 3 parameters
|
// callback fonction. Is called with these 3 parameters
|
||||||
@ -29,10 +29,11 @@ class rdc_sdb_eclairage extends hook
|
|||||||
global $indexDevices;
|
global $indexDevices;
|
||||||
//var_dump($value);
|
//var_dump($value);
|
||||||
$deviceTarget = $indexDevices[RDC_SDB_WC_ECLAIRAGE];
|
$deviceTarget = $indexDevices[RDC_SDB_WC_ECLAIRAGE];
|
||||||
|
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||||
switch($property)
|
switch($property)
|
||||||
{
|
{
|
||||||
case "occupancy":
|
case "occupancy":
|
||||||
|
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
|
||||||
if ($value == ON)
|
if ($value == ON)
|
||||||
{
|
{
|
||||||
if (getValue($deviceTarget->ieeeAddress, "state_l1") != "ON")
|
if (getValue($deviceTarget->ieeeAddress, "state_l1") != "ON")
|
||||||
@ -44,6 +45,7 @@ class rdc_sdb_eclairage extends hook
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "state_l1":
|
case "state_l1":
|
||||||
|
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
|
||||||
if ($value == "ON")
|
if ($value == "ON")
|
||||||
{
|
{
|
||||||
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state_l1", "OFF", true);
|
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state_l1", "OFF", true);
|
||||||
|
@ -7,16 +7,16 @@ class rdc_store extends hook
|
|||||||
public $timer = 0;
|
public $timer = 0;
|
||||||
public $luminance_min = 60;
|
public $luminance_min = 60;
|
||||||
public $luminance_max = 3000;
|
public $luminance_max = 3000;
|
||||||
public $storeDownTime = 20;
|
public $storeDownTime = 38;
|
||||||
public $storeUpTime = 25;
|
public $storeUpTime = 41;
|
||||||
protected $storeLevel;
|
protected $storeLevel;
|
||||||
|
protected $propertyInitialized =array();
|
||||||
protected $devicelist = array(
|
protected $devicelist = array(
|
||||||
RDC_EXTERIEUR_LUMINOSITE => array("illuminance_lux", false), // "ON"/"OFF"
|
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux", // "ON"/"OFF"
|
||||||
METEO => array("rainin", false),
|
METEO => "rainin",
|
||||||
//METEO => array("solarradiation", false),
|
//METEO => array("solarradiation", false),
|
||||||
METEO => array("windspeedkmh", false),
|
METEO => "windspeedkmh",
|
||||||
METEO => array("windgustkmh", false)
|
METEO => "windgustkmh"
|
||||||
);
|
);
|
||||||
|
|
||||||
// callback fonction. Is called with these 3 parameters
|
// callback fonction. Is called with these 3 parameters
|
||||||
@ -27,22 +27,50 @@ class rdc_store extends hook
|
|||||||
{
|
{
|
||||||
global $mohaDB, $devices, $indexDevices;
|
global $mohaDB, $devices, $indexDevices;
|
||||||
|
|
||||||
|
logger(DEBUG, "Callback : RDC_STORE", __FILE__ . ":" . __LINE__);
|
||||||
|
$rain = 0;
|
||||||
|
$exterieur_lux = 0;
|
||||||
|
$rafale = 0;
|
||||||
|
$soleil = 0;
|
||||||
$storeDevice = $indexDevices[RDC_STORE];
|
$storeDevice = $indexDevices[RDC_STORE];
|
||||||
|
if (array_key_exists("position", $storeDevice->properties))
|
||||||
|
{
|
||||||
$storeLevel = $storeDevice->properties["position"];
|
$storeLevel = $storeDevice->properties["position"];
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
|
||||||
|
{
|
||||||
$exterieur_lux = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 15);
|
$exterieur_lux = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 15);
|
||||||
|
}
|
||||||
|
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
|
||||||
|
{
|
||||||
$rain = $indexDevices[METEO]->properties["rainin"];
|
$rain = $indexDevices[METEO]->properties["rainin"];
|
||||||
|
}
|
||||||
|
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
|
||||||
|
{
|
||||||
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 12);
|
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 12);
|
||||||
|
}
|
||||||
|
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
|
||||||
|
{
|
||||||
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12);
|
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12);
|
||||||
|
}
|
||||||
|
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||||
if ($rafale >= 6 or $rain != 0)
|
if ($rafale >= 6 or $rain != 0)
|
||||||
{
|
{
|
||||||
$maxLevel = 0;
|
$maxLevel = 0;
|
||||||
}else
|
}else
|
||||||
|
{
|
||||||
|
if ($rafale != 0)
|
||||||
{
|
{
|
||||||
$maxLevel = 100 / $rafale;
|
$maxLevel = 100 / $rafale;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
switch ($property)
|
switch ($property)
|
||||||
{
|
{
|
||||||
case "illuminance_lux":
|
case "illuminance_lux":
|
||||||
|
logger(DEBUG, "CASE: illuminance_lux:" . $value, __FILE__ . ":" . __LINE__);
|
||||||
if ($exterieur_lux > 3000)
|
if ($exterieur_lux > 3000)
|
||||||
{
|
{
|
||||||
if ($rain == 0 and $maxLevel != 0)
|
if ($rain == 0 and $maxLevel != 0)
|
||||||
@ -62,26 +90,29 @@ class rdc_store extends hook
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "rainin":
|
case "rainin":
|
||||||
|
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
|
||||||
$this->close("Pluie");
|
$this->close("Pluie");
|
||||||
break;
|
break;
|
||||||
case "windgustkmh";
|
case "windgustkmh";
|
||||||
|
logger(DEBUG, "CASE: windgustkmh:" . $value, __FILE__ . ":" . __LINE__);
|
||||||
case "windspeedkmh":
|
case "windspeedkmh":
|
||||||
|
logger(DEBUG, "CASE: windspeedkmh:" . $value, __FILE__ . ":" . __LINE__);
|
||||||
if($value > 50)
|
if($value > 50)
|
||||||
{
|
{
|
||||||
$this->close("Trop de vent");
|
$this->close("Trop de vent");
|
||||||
}elseif ($value > 40 and $level > 20)
|
}elseif ($value > 40 and $this->storeLevel > 20)
|
||||||
{
|
{
|
||||||
$this->maxLevel = 20;
|
$this->maxLevel = 20;
|
||||||
$this->send(20);
|
$this->send(20);
|
||||||
}elseif ($value > 30 and $level > 40)
|
}elseif ($value > 30 and $this->storeLevel > 40)
|
||||||
{
|
{
|
||||||
$this->maxLevel = 40;
|
$this->maxLevel = 40;
|
||||||
$this->send(40);
|
$this->send(40);
|
||||||
}elseif ($value >20 and $level > 60)
|
}elseif ($value >20 and $this->storeLevel > 60)
|
||||||
{
|
{
|
||||||
$this->maxLevel = 60;
|
$this->maxLevel = 60;
|
||||||
$this->send(60);
|
$this->send(60);
|
||||||
}elseif ($value >10 and $level > 80)
|
}elseif ($value >10 and $this->storeLevel > 80)
|
||||||
{
|
{
|
||||||
$this->maxLevel = 80;
|
$this->maxLevel = 80;
|
||||||
$this->send(80);
|
$this->send(80);
|
||||||
@ -91,6 +122,8 @@ class rdc_store extends hook
|
|||||||
}
|
}
|
||||||
$this->close("Fortes rafales de vent");
|
$this->close("Fortes rafales de vent");
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +131,8 @@ class rdc_store extends hook
|
|||||||
{
|
{
|
||||||
if ($this->storeLevel < $level)
|
if ($this->storeLevel < $level)
|
||||||
{
|
{
|
||||||
$this->send($level);
|
logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
|
||||||
|
$this->send(100 - $level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +140,9 @@ class rdc_store extends hook
|
|||||||
{
|
{
|
||||||
if ($this->storeLevel != 0)
|
if ($this->storeLevel != 0)
|
||||||
{
|
{
|
||||||
|
logger(DEBUG, "Close store :" . $level, __FILE__ . ":" . __LINE__);
|
||||||
print ( "store fermé " . $reason);
|
print ( "store fermé " . $reason);
|
||||||
|
$this->send(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,8 +153,7 @@ class rdc_store extends hook
|
|||||||
$msg = array("position" => $level);
|
$msg = array("position" => $level);
|
||||||
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
|
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
|
||||||
$deviceObject->payload = $msg;
|
$deviceObject->payload = $msg;
|
||||||
$deviceObject->set();
|
$deviceObject->set(AUTO);
|
||||||
$deviceObject->method = AUTO;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,20 +4,24 @@ class rdc_wc_eclairage extends hook
|
|||||||
{
|
{
|
||||||
public $hookName = "rdc_wc_eclairage";
|
public $hookName = "rdc_wc_eclairage";
|
||||||
|
|
||||||
protected $devicelist = array(RDC_SDB_WC_ECLAIRAGE => array("state_l2", false));
|
protected $devicelist = array(
|
||||||
|
RDC_SDB_WC_ECLAIRAGE => "state_l2",
|
||||||
|
RDC_WC_MVMT => "occupancy"
|
||||||
|
);
|
||||||
|
|
||||||
public $delay = 3; // amount of time in $timeunit
|
public $delay = 3; // amount of time in $timeunit
|
||||||
public $delayManual = 8; // amount of time in $timeunit for manual mode
|
public $delayManual = 8; // amount of time in $timeunit for manual mode
|
||||||
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
|
||||||
|
|
||||||
// callback fonction. Is called with these 4 parameters
|
// callback fonction. Is called with these 4 parameters
|
||||||
public function callBack($device, $property, $value)
|
public function callBack(&$device, $property, $value)
|
||||||
{
|
{
|
||||||
global $indexDevices;
|
global $indexDevices;
|
||||||
//var_dump($value);
|
//var_dump($value);
|
||||||
switch($property)
|
switch($property)
|
||||||
{
|
{
|
||||||
case "state_l2":
|
case "state_l2":
|
||||||
|
logger(DEBUG, _("CASE: state_l2"), __FILE__ . ":" . __LINE__);
|
||||||
if ($value == "ON")
|
if ($value == "ON")
|
||||||
{
|
{
|
||||||
setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
|
setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
|
||||||
@ -27,9 +31,29 @@ class rdc_wc_eclairage extends hook
|
|||||||
deleteEvent(searchEvent($device, "state_l2", "OFF"));
|
deleteEvent(searchEvent($device, "state_l2", "OFF"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "occupancy":
|
||||||
|
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
|
||||||
|
if ($value == true)
|
||||||
|
{
|
||||||
|
$this->send("ON");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
|
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
|
||||||
}
|
}
|
||||||
|
private function send($state)
|
||||||
|
{
|
||||||
|
global $indexDevices;
|
||||||
|
$deviceObject = $indexDevices[RDC_SDB_WC_ECLAIRAGE];
|
||||||
|
$msg = array("state_l2" => $state);
|
||||||
|
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
|
||||||
|
$deviceObject->payload = $msg;
|
||||||
|
$deviceObject->set(null);
|
||||||
|
if ($deviceObject->method != MANUAL)
|
||||||
|
{
|
||||||
|
$deviceObject->method = AUTO;
|
||||||
|
}
|
||||||
|
setDelay($deviceObject, $this->delay, $this->timeUnit, "state_l2", "OFF", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$hooks["rdc_wc_eclairage"] = new rdc_wc_eclairage();
|
$hooks["rdc_wc_eclairage"] = new rdc_wc_eclairage();
|
||||||
|
91
moha.php
91
moha.php
@ -20,6 +20,7 @@ $mids = array(); // list of message IDs
|
|||||||
$devices = array(); // array of device objetcs
|
$devices = array(); // array of device objetcs
|
||||||
$indexDevices = array(); // index of devices by ieee_address
|
$indexDevices = array(); // index of devices by ieee_address
|
||||||
$indexFriendlyNames = array(); // index of devices by freindly name
|
$indexFriendlyNames = array(); // index of devices by freindly name
|
||||||
|
$indexTypes = array(); // index of devices by type
|
||||||
$hooksList = array(); // list of hooks to be included
|
$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
|
||||||
@ -75,7 +76,7 @@ function notify($message)
|
|||||||
function logger($level, $log, $pos = "", $notif = true)
|
function logger($level, $log, $pos = "", $notif = true)
|
||||||
{
|
{
|
||||||
global $logFh, $logLevel, $notificationLevel, $logLevels;
|
global $logFh, $logLevel, $notificationLevel, $logLevels;
|
||||||
$logString = date("c") . ' ' . $logLevels[$level] . " " ;
|
$logString = $logLevels[$level] . " " ;
|
||||||
if ($pos !== false)
|
if ($pos !== false)
|
||||||
{
|
{
|
||||||
$logString .= $pos;
|
$logString .= $pos;
|
||||||
@ -83,8 +84,8 @@ function logger($level, $log, $pos = "", $notif = true)
|
|||||||
$logString .= " - " . $log;
|
$logString .= " - " . $log;
|
||||||
if ($level & $logLevel)
|
if ($level & $logLevel)
|
||||||
{
|
{
|
||||||
fwrite($logFh, $logString . EOL);
|
fwrite($logFh, date("c") . ' ' . $logString . EOL);
|
||||||
print ($logString . EOL);
|
print ("MOHA-" . $logString . EOL);
|
||||||
}
|
}
|
||||||
$test = $level & $notificationLevel;
|
$test = $level & $notificationLevel;
|
||||||
if (($test != 0) and ($notif === true))
|
if (($test != 0) and ($notif === true))
|
||||||
@ -135,9 +136,13 @@ function endMoha()
|
|||||||
$x = 0;
|
$x = 0;
|
||||||
|
|
||||||
logger(WARNING, _("moha is ending"), __FILE__ . ":" . __LINE__);
|
logger(WARNING, _("moha is ending"), __FILE__ . ":" . __LINE__);
|
||||||
if (storeDB($devices, $dataPath . "moha.db") === false)
|
if (storeDB($devices, $dataPath . "devices.db") === false)
|
||||||
{
|
{
|
||||||
logger(ERROR, _("Can not store db" ), __FILE__ . ":" . __LINE__);
|
logger(ERROR, _("Can not store devices db" ), __FILE__ . ":" . __LINE__);
|
||||||
|
}
|
||||||
|
if (storeDB($topics, $dataPath . "topics.db") === false)
|
||||||
|
{
|
||||||
|
logger(ERROR, _("Can not store topics db" ), __FILE__ . ":" . __LINE__);
|
||||||
}
|
}
|
||||||
if($testMode) file_put_contents($dataPath . "moha.devices", var_export($devices, true));
|
if($testMode) file_put_contents($dataPath . "moha.devices", var_export($devices, true));
|
||||||
if ($connected)
|
if ($connected)
|
||||||
@ -173,11 +178,6 @@ if (is_readable($configDir . "/devices_constants.php"))
|
|||||||
include $configDir . "/devices_constants.php";
|
include $configDir . "/devices_constants.php";
|
||||||
//echo "hooklist"; print_r($hooksList); echo EOL;
|
//echo "hooklist"; print_r($hooksList); echo EOL;
|
||||||
logger(INFO, sprintf(_("%s/devices_constants.define found, so it has been included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
|
logger(INFO, sprintf(_("%s/devices_constants.define found, so it has been included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
|
||||||
}elseif(is_readable("config/devices_constants.php"))
|
|
||||||
{
|
|
||||||
include "config/devices_constants.php";
|
|
||||||
//echo "hooklist"; print_r($hooksList); echo EOL;
|
|
||||||
logger(INFO, sprintf(_("%s/devices_constants.define found, so it has been included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
logger(WARNING, sprintf(_("%s/devices_constants.define not found, so not included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
|
logger(WARNING, sprintf(_("%s/devices_constants.define not found, so not included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
|
||||||
@ -194,17 +194,6 @@ require "events.php";
|
|||||||
require "db_functions.php";
|
require "db_functions.php";
|
||||||
require "webserver/webserver.php";
|
require "webserver/webserver.php";
|
||||||
|
|
||||||
logger(DEBUG, _("Loading stored devices datas from ") . $dataPath . "moha.db", __FILE__ . ":" . __LINE__);
|
|
||||||
if (loadDB($devices, $dataPath . "moha.db") === false)
|
|
||||||
{
|
|
||||||
logger(ERROR, _("Can not load device db"), __FILE__ . ":" . __LINE__);
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
mkIndexes($devices);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// topics definition
|
// topics definition
|
||||||
listHooks("./topics_callbacks", $hooksList);
|
listHooks("./topics_callbacks", $hooksList);
|
||||||
if (!empty($hooksList))
|
if (!empty($hooksList))
|
||||||
@ -216,9 +205,42 @@ if (!empty($hooksList))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// making the list of hooks to include
|
// making the list of hooks to include
|
||||||
listHooks("./hooks", $hooksList);
|
listHooks("./hooks", $hooksList);
|
||||||
|
if (!empty($hooksList)) // some hooks to include if hooklist is not empty
|
||||||
|
{
|
||||||
|
foreach ($hooksList as $hookFile) // loop to include hooks in hookslist
|
||||||
|
{
|
||||||
|
logger(INFO, _("Including ") . $hookFile, __FILE__ . ":" . __LINE__, false);
|
||||||
|
include_once $hookFile;
|
||||||
|
}
|
||||||
|
if ($logLevel & DEBUG)
|
||||||
|
{
|
||||||
|
file_put_contents($dataPath . "moha.devices", var_export($devices, true)); // debugging : save device list
|
||||||
|
}
|
||||||
|
$included = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger(DEBUG, _("Loading stored topics datas from ") . $dataPath . "topics.db", __FILE__ . ":" . __LINE__);
|
||||||
|
if (file_exists($dataPath . "topics.db"))
|
||||||
|
{
|
||||||
|
if (($topics = loadDB($dataPath . "topics.db")) === false)
|
||||||
|
{
|
||||||
|
logger(ERROR, _("Can not load topics db"), __FILE__ . ":" . __LINE__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger(DEBUG, _("Loading stored devices datas from ") . $dataPath . "devices.db", __FILE__ . ":" . __LINE__);
|
||||||
|
if (file_exists($dataPath . "devices.db"))
|
||||||
|
{
|
||||||
|
if (($devices = loadDB($dataPath . "devices.db")) === false)
|
||||||
|
{
|
||||||
|
logger(ERROR, _("Can not load devices db"), __FILE__ . ":" . __LINE__);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
mkIndexes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Program start
|
// Program start
|
||||||
logger(DEBUG, _("Program start"), __FILE__ . ":" . __LINE__, false);
|
logger(DEBUG, _("Program start"), __FILE__ . ":" . __LINE__, false);
|
||||||
@ -247,7 +269,7 @@ $client->onPublish('publishResponse');
|
|||||||
$client->connect($mqttServerIp, 1883, 5);
|
$client->connect($mqttServerIp, 1883, 5);
|
||||||
|
|
||||||
logger(INFO, _("Subscribing to bridge"), __FILE__ . ":" . __LINE__, false);
|
logger(INFO, _("Subscribing to bridge"), __FILE__ . ":" . __LINE__, false);
|
||||||
foreach($topics as $name => $topic)
|
foreach($topics as $name => &$topic)
|
||||||
{
|
{
|
||||||
$topic->mid = $client->subscribe($name . "/#", 2);
|
$topic->mid = $client->subscribe($name . "/#", 2);
|
||||||
$mids[$topic->mid] = $name;
|
$mids[$topic->mid] = $name;
|
||||||
@ -261,23 +283,24 @@ $oneshot = false;
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
$client->loop(); // mqtt server loop()
|
$client->loop(); // mqtt server loop()
|
||||||
if (! $included) // hooks not already included
|
/*if (! $included) // hooks not already included
|
||||||
{
|
{
|
||||||
logger(DEBUG, _("Making hooks list"), __FILE__ . ":" . __LINE__, false);
|
logger(DEBUG, _("Loading hooks list"), __FILE__ . ":" . __LINE__, false);
|
||||||
|
|
||||||
if (!empty($hooksList)) // some hooks to include if hooklist is not empty
|
if (!empty($hooksList)) // some hooks to include if hooklist is not empty
|
||||||
{
|
{
|
||||||
foreach ($hooksList as $hookFile) // loop to include hooks in hookslist
|
foreach ($hooksList as $hookFile) // loop to include hooks in hookslist
|
||||||
{
|
{
|
||||||
logger(INFO, _("Including ") . $hookFile, __FILE__ . ":" . __LINE__, false);
|
logger(INFO, _("Including ") . $hookFile, __FILE__ . ":" . __LINE__, false);
|
||||||
include $hookFile;
|
include_once $hookFile;
|
||||||
}
|
}
|
||||||
|
if ($logLevel & DEBUG)
|
||||||
|
{
|
||||||
file_put_contents($dataPath . "moha.devices", var_export($devices, true)); // debugging : save device list
|
file_put_contents($dataPath . "moha.devices", var_export($devices, true)); // debugging : save device list
|
||||||
|
}
|
||||||
$included = true;
|
$included = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}else
|
}else
|
||||||
{
|
{*/
|
||||||
|
|
||||||
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 can to be not initialized
|
||||||
{
|
{
|
||||||
@ -285,15 +308,16 @@ while (true)
|
|||||||
|
|
||||||
$oneshot = true;
|
$oneshot = true;
|
||||||
}
|
}
|
||||||
|
$nn = 0;
|
||||||
if($hooksInitialized == 0) // all hooks are not initialized
|
if($hooksInitialized == 0) // all hooks are not initialized
|
||||||
{
|
{
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach($hooks as $hookName => $hook)
|
foreach($hooks as $hookName => &$hook)
|
||||||
{
|
{
|
||||||
if ($hook->initialized === false)
|
if ($hook->initialized === false and $hook->active === true)
|
||||||
{
|
{
|
||||||
logger(WARNING, _("Initializing Hook not completely initialized :") . $hookName, __FILE__ . ":" . __LINE__);
|
logger(WARNING, _("Initializing Hook not completely initialized :") . $hookName, __FILE__ . ":" . __LINE__);
|
||||||
$i &= $hook->installHooks();
|
$i &= $hook->installHooks($indexDevices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$hooksInitialized = $i;
|
$hooksInitialized = $i;
|
||||||
@ -301,7 +325,6 @@ while (true)
|
|||||||
{
|
{
|
||||||
logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__);
|
logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__);
|
||||||
$flagHooks = true;
|
$flagHooks = true;
|
||||||
|
|
||||||
}else // executed when hooks initialization finished but database init not finished
|
}else // executed when hooks initialization finished but database init not finished
|
||||||
{
|
{
|
||||||
//logger(DEBUG, _("looping"), __FILE__ . ":" . __LINE__);
|
//logger(DEBUG, _("looping"), __FILE__ . ":" . __LINE__);
|
||||||
@ -309,7 +332,7 @@ while (true)
|
|||||||
}
|
}
|
||||||
checkEvents();
|
checkEvents();
|
||||||
askWebServer($read);
|
askWebServer($read);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
endMoha();
|
endMoha();
|
||||||
|
@ -13,13 +13,15 @@ function messageReceived($message)
|
|||||||
// payload is an array :
|
// payload is an array :
|
||||||
// $key is property and $value is value of the property
|
// $key is property and $value is value of the property
|
||||||
|
|
||||||
function publish($topic, $payload, $commande="set") //, $eventKey)
|
function publish($topic, $payloadArray, $commande="set") //, $eventKey)
|
||||||
{
|
{
|
||||||
global $client, $mids, $logFh, $testMode;
|
global $client, $mids, $logFh, $testMode;
|
||||||
$string = $topic . "/" . $commande;
|
$string = $topic . "/" . $commande;
|
||||||
if ($testMode === false)
|
if ($testMode === false)
|
||||||
{
|
{
|
||||||
$mid = $client->publish($string, json_encode($payload) , 2);
|
if ($client !== null)
|
||||||
|
{
|
||||||
|
$mid = $client->publish($string, json_encode($payloadArray) , 2);
|
||||||
if (isset($mids[$mid]))
|
if (isset($mids[$mid]))
|
||||||
{
|
{
|
||||||
//echo "unsetting mids" .EOL;
|
//echo "unsetting mids" .EOL;
|
||||||
@ -29,7 +31,12 @@ function publish($topic, $payload, $commande="set") //, $eventKey)
|
|||||||
//echo "setting mids" .EOL;
|
//echo "setting mids" .EOL;
|
||||||
$mids[$mid] = true;
|
$mids[$mid] = true;
|
||||||
}
|
}
|
||||||
logger(LOG_INFO, $logFh, "Publishing " . $string . " with payload => " . json_encode($payload), __FILE__ . ":" . __LINE__);
|
logger(LOG_INFO, $logFh, "Publishing " . $string . " with payload => " . json_encode($payloadArray), __FILE__ . ":" . __LINE__);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
logger(ERROR, $logFh, "MQTT client is null not publishing " . $string . " with payload => " . json_encode($payloadArray), __FILE__ . ":" . __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
logger(INFO, _("Test mode on: no publishing "), __FILE__ . ":" . __LINE__);
|
logger(INFO, _("Test mode on: no publishing "), __FILE__ . ":" . __LINE__);
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
//TODO to test and debug
|
//TODO to test and debug
|
||||||
$topics["linky2mqtt"] = new topic;
|
var_dump($topics);
|
||||||
$devices["linky2mqtt"] = array();
|
if (!array_key_exists("linky2mqtt", $topics)) $topics["linky2mqtt"] = new topic;
|
||||||
|
if (!array_key_exists("linky2mqtt", $devices)) $devices["linky2mqtt"] = array();
|
||||||
|
|
||||||
|
|
||||||
$topics["linky2mqtt"]->callback = function($topic, $message)
|
function linky2mqttCallback($topic, $message)
|
||||||
{
|
{
|
||||||
global $topics, $logFh, $devices, $included;
|
global $topics, $logFh, $devices, $included;
|
||||||
$topicName = $topic[0];
|
$topicName = $topic[0];
|
||||||
@ -20,8 +21,9 @@ $topics["linky2mqtt"]->callback = function($topic, $message)
|
|||||||
$device["device"]->friendlyName = $payloadArray["friendly_name"];
|
$device["device"]->friendlyName = $payloadArray["friendly_name"];
|
||||||
$device["device"]->ieeeAddress = $payloadArray["ieeeAddress"];
|
$device["device"]->ieeeAddress = $payloadArray["ieeeAddress"];
|
||||||
$device["device"]->type = $payloadArray["type"];
|
$device["device"]->type = $payloadArray["type"];
|
||||||
$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
|
//$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
|
||||||
$indexFriendlyNames[$topicName][$fn] = & $device["device"];
|
//$indexFriendlyNames[$topicName][$fn] = & $device["device"];
|
||||||
|
mkIndexes();
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
$device = &$device[$fn];
|
$device = &$device[$fn];
|
||||||
@ -34,4 +36,5 @@ $topics["linky2mqtt"]->callback = function($topic, $message)
|
|||||||
changeDevice($topicName, $friendlyName, $device["device"], $payloadArray);
|
changeDevice($topicName, $friendlyName, $device["device"], $payloadArray);
|
||||||
//print_r($device["device"]);
|
//print_r($device["device"]);
|
||||||
}
|
}
|
||||||
|
$topics["linky2mqtt"]->callback = "linky2mqttCallback";
|
||||||
?>
|
?>
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
$topics["pws2mqtt"] = new topic;
|
if (!array_key_exists("pws2mqtt", $topics)) $topics["pws2mqtt"] = new topic;
|
||||||
$devices["pws2mqtt"] = array();
|
if (!array_key_exists("pws2mqtt", $devices)) $devices["pws2mqtt"] = array();
|
||||||
|
|
||||||
|
function pws2mqttCallback($topic, $message)
|
||||||
$topics["pws2mqtt"]->callback = function($topic, $message)
|
|
||||||
{
|
{
|
||||||
global $logFh, $devices, $included;
|
global $logFh, $devices, $included;
|
||||||
$topicName = $topic[0];
|
$topicName = $topic[0];
|
||||||
@ -21,8 +20,10 @@ $topics["pws2mqtt"]->callback = function($topic, $message)
|
|||||||
$device["device"]->ieeeAddress = $payloadArray["ieeeAddress"];
|
$device["device"]->ieeeAddress = $payloadArray["ieeeAddress"];
|
||||||
$device["device"]->type = $payloadArray["type"];
|
$device["device"]->type = $payloadArray["type"];
|
||||||
$device["device"]->topic = $topicName;
|
$device["device"]->topic = $topicName;
|
||||||
$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
|
//$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
|
||||||
$indexFriendlyNames[$topicName][$fn] = & $device["device"];
|
//$indexFriendlyNames[$topicName][$fn] = & $device["device"];
|
||||||
|
mkIndexes();
|
||||||
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
$device = &$device[$fn];
|
$device = &$device[$fn];
|
||||||
@ -54,5 +55,16 @@ $topics["pws2mqtt"]->callback = function($topic, $message)
|
|||||||
{
|
{
|
||||||
changeDevice($topicName, $fn, $device["device"], $payloadArray);
|
changeDevice($topicName, $fn, $device["device"], $payloadArray);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
$topics["pws2mqtt"]->callback = "pws2mqttCallback";
|
||||||
|
|
||||||
|
if (!is_callable("pws2mqttGetList"))
|
||||||
|
{
|
||||||
|
function pws2mqttGetList()
|
||||||
|
{
|
||||||
|
publish("pws2mqtt", array("",""), "get" );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pws2mqttGetList();
|
||||||
?>
|
?>
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$topics["zigbee2mqtt"] = new topic;
|
if (!array_key_exists("zigbee2mqtt", $topics)) $topics["zigbee2mqtt"] = new topic;
|
||||||
$devices["zigbee2mqtt"] = array();
|
if (!array_key_exists("zigbee2mqtt", $devices)) $devices["zigbee2mqtt"] = array();
|
||||||
|
|
||||||
$topics["zigbee2mqtt"]->callback = function($topic, $message)
|
function zigbee2mqttCallback($topic, $message)
|
||||||
{
|
{
|
||||||
global $topics, $devices, $included, $logFh, $indexFriendlyNames;
|
global $topics, $devices, $included, $logFh, $indexFriendlyNames;
|
||||||
|
|
||||||
@ -85,5 +85,6 @@ $topics["zigbee2mqtt"]->callback = function($topic, $message)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$topics["zigbee2mqtt"]->callback = "zigbee2mqttCallback";
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once "events.php";
|
require_once "events.php";
|
||||||
|
|
||||||
function webDashboard($socket, $n="Général", $page="/")
|
function webDashboard($socket, $n="Général")
|
||||||
{
|
{
|
||||||
global $dashboards, $indexDevices;
|
global $dashboards, $indexDevices;
|
||||||
require_once "webserver/javascript.php";
|
require_once "webserver/javascript.php";
|
||||||
@ -18,13 +18,8 @@ function webDashboard($socket, $n="Général", $page="/")
|
|||||||
$property = $array[1];
|
$property = $array[1];
|
||||||
if (array_key_exists($array[1], $device->properties))
|
if (array_key_exists($array[1], $device->properties))
|
||||||
{
|
{
|
||||||
|
|
||||||
$propertyObject = $device->properties[$property];
|
$propertyObject = $device->properties[$property];
|
||||||
$value = $propertyObject["value"];
|
$value = $propertyObject["value"];
|
||||||
if ($value === null)
|
|
||||||
{
|
|
||||||
$value = "null";
|
|
||||||
}
|
|
||||||
logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)));
|
logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)));
|
||||||
$response .= $device->friendlyName . aliases($device->friendlyName, $property) . " => " . bool2string(_($value)) . EOL;
|
$response .= $device->friendlyName . aliases($device->friendlyName, $property) . " => " . bool2string(_($value)) . EOL;
|
||||||
if (array_key_exists("access", $propertyObject))
|
if (array_key_exists("access", $propertyObject))
|
||||||
@ -33,17 +28,15 @@ function webDashboard($socket, $n="Général", $page="/")
|
|||||||
if(($propertyObject["access"] & 2))
|
if(($propertyObject["access"] & 2))
|
||||||
{
|
{
|
||||||
logger(DEBUG, _("Write Access OK ") . ($propertyObject["access"] & 2), __FILE__ . ":" . __LINE__);
|
logger(DEBUG, _("Write Access OK ") . ($propertyObject["access"] & 2), __FILE__ . ":" . __LINE__);
|
||||||
$response .= " " . displayChoice($device, $property) . EOL;
|
$response .= " " . displayChoice($device, $property);
|
||||||
}
|
}
|
||||||
if(($propertyObject["access"] & 4))
|
if(($propertyObject["access"] & 4))
|
||||||
{
|
{
|
||||||
logger(DEBUG, _("can get value") . ($propertyObject["access"] & 4), __FILE__ . ":" . __LINE__);
|
logger(DEBUG, _("can get value") . ($propertyObject["access"] & 4), __FILE__ . ":" . __LINE__);
|
||||||
$response .= ' <input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyObject["name"] . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "','" . $device->friendlyName . "','" . $propertyObject["name"] . "')\"><br>" . EOL;
|
$response .= ' <input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyObject["name"] . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "','" . $device->friendlyName . "','" . $propertyObject["name"] . "')\">";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else
|
|
||||||
{
|
|
||||||
$response .= EOLH;
|
$response .= EOLH;
|
||||||
}
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
logger(ERROR, _("Property do not exist"), __FILE__ . ":" . __LINE__);
|
logger(ERROR, _("Property do not exist"), __FILE__ . ":" . __LINE__);
|
||||||
@ -167,25 +160,7 @@ function webBrowse($socket, $argList, $page="/browse")
|
|||||||
$response .= insertJavascript();
|
$response .= insertJavascript();
|
||||||
foreach($device->properties as $key => $value)
|
foreach($device->properties as $key => $value)
|
||||||
{
|
{
|
||||||
$response .= $key . " ";
|
$response = displayProperty($device, $key, $value, $response);
|
||||||
if (array_key_exists("access", $value))
|
|
||||||
{
|
|
||||||
if(($value["access"] & 2))
|
|
||||||
{
|
|
||||||
logger(DEBUG, _("Write Access OK ") . ($value["access"] & 2), __FILE__ . ":" . __LINE__);
|
|
||||||
$response .= displayChoice($device, $key);
|
|
||||||
}
|
|
||||||
if(($value["access"] & 4))
|
|
||||||
{
|
|
||||||
logger(DEBUG, _("can get value") . ($value["access"] & 4), __FILE__ . ":" . __LINE__);
|
|
||||||
$response .= ' <input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $key . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', '" . $key . "')\">";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$response .= "<br>\n" . $tab . "[<br>\n";
|
|
||||||
//echo memory_get_usage();
|
|
||||||
//$response = value($key, $value, $response);
|
|
||||||
iterateProperty($device, $key, $value, $response, $tab);
|
|
||||||
$response .= $tab . "]<br>\n";
|
|
||||||
}
|
}
|
||||||
/*foreach($device->properties as $key => $value)
|
/*foreach($device->properties as $key => $value)
|
||||||
{
|
{
|
||||||
@ -228,6 +203,30 @@ function webBrowse($socket, $argList, $page="/browse")
|
|||||||
htmlSend($socket, $response);
|
htmlSend($socket, $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function displayProperty($device, $key, $value, $response)
|
||||||
|
{
|
||||||
|
$response .= $key . " ";
|
||||||
|
if (array_key_exists("access", $value))
|
||||||
|
{
|
||||||
|
if(($value["access"] & 2))
|
||||||
|
{
|
||||||
|
logger(DEBUG, _("Write Access OK ") . ($value["access"] & 2), __FILE__ . ":" . __LINE__);
|
||||||
|
$response .= displayChoice($device, $key);
|
||||||
|
}
|
||||||
|
if(($value["access"] & 4))
|
||||||
|
{
|
||||||
|
logger(DEBUG, _("can get value") . ($value["access"] & 4), __FILE__ . ":" . __LINE__);
|
||||||
|
$response .= ' <input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $key . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', '" . $key . "')\">";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$response .= "<br>\n" . $tab . "[<br>\n";
|
||||||
|
//echo memory_get_usage();
|
||||||
|
//$response = value($key, $value, $response);
|
||||||
|
iterateProperty($device, $key, $value, $response, $tab);
|
||||||
|
$response .= $tab . "]<br>\n";
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
function iterateProperty($device, $property, $value, &$response, $tab="")
|
function iterateProperty($device, $property, $value, &$response, $tab="")
|
||||||
{
|
{
|
||||||
$tab .= " ";
|
$tab .= " ";
|
||||||
@ -367,5 +366,21 @@ function webNotify($argList)
|
|||||||
$response = _("notify command have been set");
|
$response = _("notify command have been set");
|
||||||
$monitored[] = new watch($argList["topic"], $argList["fn"], $argList["property"], $argList["condition"], $argList["value"]);
|
$monitored[] = new watch($argList["topic"], $argList["fn"], $argList["property"], $argList["condition"], $argList["value"]);
|
||||||
}
|
}
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
function webDisplayByType($argList)
|
||||||
|
{
|
||||||
|
global $indexTypes, $config;
|
||||||
|
require_once $config . "porpertiesbytype.php";
|
||||||
|
require_once "webserver/javascript.php";
|
||||||
|
|
||||||
|
$response .= insertJavascript();
|
||||||
|
foreach($indexTypes[$argList["type"]] as $device)
|
||||||
|
{
|
||||||
|
foreach($)
|
||||||
|
displayProperty($device, $device->, $value, $response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
?>
|
?>
|
||||||
|
@ -28,7 +28,6 @@ function htmlSend($socket, $text, $meta="")
|
|||||||
"Connection: close" . EOLR .
|
"Connection: close" . EOLR .
|
||||||
"Content-Type: text/html; charset=UTF-8" . EOLR . EOLR;
|
"Content-Type: text/html; charset=UTF-8" . EOLR . EOLR;
|
||||||
$response = $httpHeader . '<!doctype html>' . EOL . '<html lang="fr">' . EOL . '<head>' . EOL . $meta . EOL . '<meta charset="utf-8">' . EOL . '<title>Moha</title>' . EOL . '</head><body>' . EOL . $text . "</body></html>";
|
$response = $httpHeader . '<!doctype html>' . EOL . '<html lang="fr">' . EOL . '<head>' . EOL . $meta . EOL . '<meta charset="utf-8">' . EOL . '<title>Moha</title>' . EOL . '</head><body>' . EOL . $text . "</body></html>";
|
||||||
|
|
||||||
stream_socket_sendto($socket, $response);
|
stream_socket_sendto($socket, $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,11 +61,13 @@ function askWebServer($read)
|
|||||||
$argList["cmd"] = trim($tmp);
|
$argList["cmd"] = trim($tmp);
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
$argList[trim(strchr($tmp, "=", true))] = trim(substr(strchr($tmp, "="), 1));
|
$key = trim(strchr($tmp, "=", true));
|
||||||
|
$argList[$key] = trim(substr(strchr($tmp, "="), 1));
|
||||||
|
if (count($argTmp) == 1) $argList["cmd"] = $key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger(DEBUG, print_r($argList, true), __FILE__ . ":" . __LINE__);
|
|
||||||
|
|
||||||
|
logger(DEBUG, print_r($argList, true), __FILE__ . ":" . __LINE__);
|
||||||
if(array_key_exists("cmd", $argList))
|
if(array_key_exists("cmd", $argList))
|
||||||
{
|
{
|
||||||
$command = strtolower($argList["cmd"]);
|
$command = strtolower($argList["cmd"]);
|
||||||
@ -74,11 +75,11 @@ function askWebServer($read)
|
|||||||
switch($command)
|
switch($command)
|
||||||
{
|
{
|
||||||
case "dashboard":
|
case "dashboard":
|
||||||
webDashboard($spawn, $argList["dashboard"], $argList["page"]);
|
webDashboard($spawn, $argList["dashboard"]);
|
||||||
break;
|
break;
|
||||||
case "browse":
|
case "browse":
|
||||||
logger(DEBUG, _("Browsing"), __FILE__ . ":" . __LINE__);
|
logger(DEBUG, _("Browsing"), __FILE__ . ":" . __LINE__);
|
||||||
webBrowse($spawn, $argList, $argList["page"]);
|
webBrowse($spawn, $argList);
|
||||||
//return true;
|
//return true;
|
||||||
break;
|
break;
|
||||||
case "get":
|
case "get":
|
||||||
@ -99,6 +100,9 @@ function askWebServer($read)
|
|||||||
htmlSend($spawn, webNotify($argList));
|
htmlSend($spawn, webNotify($argList));
|
||||||
logger(DEBUG, print_r($monitored, true), __FILE__ . ":" . __LINE__);
|
logger(DEBUG, print_r($monitored, true), __FILE__ . ":" . __LINE__);
|
||||||
break;
|
break;
|
||||||
|
case "type":
|
||||||
|
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||||
|
htmlSend($spawn, webDisplayByType($argList));
|
||||||
default:
|
default:
|
||||||
if (is_numeric(array_key_first($argList)))
|
if (is_numeric(array_key_first($argList)))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user