1
0

debugging

This commit is contained in:
daniel Tartavel 2022-01-29 19:58:01 +01:00
parent 425107cec7
commit 719a45fa4e
8 changed files with 41 additions and 29 deletions

View File

@ -75,7 +75,7 @@ class db extends mysqli
logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__); logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__);
} }
} }
logger(INFO, sprintf(_("New value of property: '%s' of device: %s stored in database"), $propertyTree, $device->friendlyName, $value), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("New value (%s) of property: '%s' of device: %s stored in database"), $value, $propertyTree, $device->friendlyName), __FILE__ . ":" . __LINE__);
} }
} }
} }

View File

@ -170,7 +170,7 @@ function removeEvent($device, $property , $value)
function searchEvent($device, $property , $value) function searchEvent($device, $property , $value)
{ {
global $events; global $events;
logger(DEBUG, _("searching event for device %s, property %s and value %s"), $device->friendlyName, $property, bool2string($value), __FILE__ . ":" . __LINE__); logger(DEBUG, sprintf(_("searching event for device %s, property %s and value %s"), $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
foreach($events as $key => $event) foreach($events as $key => $event)
{ {
//echo "Event : $event => $value" . EOL; //echo "Event : $event => $value" . EOL;

View File

@ -3,14 +3,14 @@
class rdc_chambre_eclairage extends hook class rdc_chambre_eclairage extends hook
{ {
public $hookName = "rdc_chambre_eclairage"; public $hookName = "rdc_chambre_eclairage";
public $active = false; //enable/disable hook (true => enabled) public $active = true; //enable/disable hook (true => enabled)
public $delay = 5; // amount of time in $timeunit public $delay = 5; // amount of time in $timeunit
public $timeUnit = "minute"; // unit of time for delay, second, minute, hour, day, week, month, year public $timeUnit = "minute"; // unit of time for delay, second, minute, hour, day, week, month, year
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), "RDC_CHAMBRE_AMBIANCE" => array("state", false), // "ON"/"OFF"
"RDC_CHAMBRE_ECLAIRAGE" => array("state_l1", false), "RDC_CHAMBRE_ECLAIRAGE" => array("state_l1", false), // "ON"/"OFF"
"RDC_CHAMBRE_MVMT" => array("occupancy", false), "RDC_CHAMBRE_MVMT" => array("occupancy", false),
"RDC_CHAMBRE_ARMOIRE_GAUCHE" => array("contact", false) "RDC_CHAMBRE_ARMOIRE_GAUCHE" => array("contact", false)
); );
@ -25,7 +25,10 @@ class rdc_chambre_eclairage extends hook
$lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->illuminance_lux; $lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->illuminance_lux;
if ($property == "occupancy" and $value == "ON") if ($property == "occupancy" and $value == "ON")
{ {
$this->send(RDC_CHAMBRE_LUMINOSITE, "ON", "OFF", AUTO); $this->send(RDC_CHAMBRE_AMBIANCE, "ON", "OFF", AUTO);
}elseif ($property == "contact" and $value = true and getValue(RDC_CHAMBRE_ECLAIRAGE) == "OFF")
{
$this->send(RDC_CHAMBRE_ECLAIRAGE, "ON", "OFF", AUTO);
} }
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, $value), __FILE__ . ":" . __LINE__); logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, $value), __FILE__ . ":" . __LINE__);
} }

View File

@ -13,7 +13,7 @@ class rdc_salon_eclairage extends hook
public $delay = 3; // amount of time in $timeunit public $delay = 3; // amount of time in $timeunit
public $timeUnit = "minute"; // unit of time for delay, second, minute, hour, day, week, month, year public $timeUnit = "minute"; // unit of time for delay, second, minute, hour, day, week, month, year
public $luminance_min = 60; public $luminance_min = 70;
public $luminance_max = 3000; public $luminance_max = 3000;
@ -26,7 +26,7 @@ class rdc_salon_eclairage extends hook
{ {
case "occupancy": case "occupancy":
logger(DEBUG, _("CASE: Occupancy => ") . bool2string($value), __FILE__ . ":" . __LINE__); logger(DEBUG, _("CASE: Occupancy => ") . bool2string($value), __FILE__ . ":" . __LINE__);
//print_r($indexDevices[RDC_SALON_LUMINOSITE]); //print_r(getValue(RDC_SALON_LUMINOSITE, "illuminance_lux"));
if ($value == ON and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min) if ($value == ON and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min)
{ {
logger(DEBUG, _("setting to ON"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("setting to ON"), __FILE__ . ":" . __LINE__);
@ -35,24 +35,27 @@ class rdc_salon_eclairage extends hook
}elseif ($value == OFF) }elseif ($value == OFF)
{ {
logger(DEBUG, _("Value is OFF"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("Value is OFF"), __FILE__ . ":" . __LINE__);
if (getValue(RDC_SALON_MVMT, "occupancy") == OFF) if (getValue(RDC_SALON_MVMT, "occupancy") == OFF and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF))
{
if (getValue(RDC_SALON_MVMT2, "occupancy") == OFF)
{ {
logger(DEBUG, _("Setting to OFF"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("Setting to OFF"), __FILE__ . ":" . __LINE__);
setDelay($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], $this->delay, $this->timeUnit, "state", "OFF", true); setDelay($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], $this->delay, $this->timeUnit, "state", "OFF", true);
//$this->send("ON", "OFF", AUTO); //$this->send("ON", "OFF", AUTO);
} }
} }
}
break; break;
case "contact": case "contact":
logger(DEBUG, _("CASE: Contact Door"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("CASE: Contact Door"), __FILE__ . ":" . __LINE__);
if ($value == false and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min) if ($value == false and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min and getValue(RDC_SALON_ECLAIRAGE_PANNEAU, "state") == "OFF")
{ {
logger(DEBUG, _("Door is open and illumance < min"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("Door is open and illumance < min"), __FILE__ . ":" . __LINE__);
if (getValue(RDC_SALON_MVMT, "occupancy") == ON or getValue(RDC_SALON_MVMT2, "occupancy") == ON)
{
$this->send("ON", null, AUTO);
}else
{
$this->send("ON", "OFF", AUTO); $this->send("ON", "OFF", AUTO);
} }
}
break; break;
case "illuminance_lux": case "illuminance_lux":
logger(DEBUG, _("CASE : Illuminance"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("CASE : Illuminance"), __FILE__ . ":" . __LINE__);
@ -60,7 +63,8 @@ class rdc_salon_eclairage extends hook
{ {
logger(DEBUG, _("illuminace is > to max"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("illuminace is > to max"), __FILE__ . ":" . __LINE__);
//$this->send("OFF", null, AUTO); //$this->send("OFF", null, AUTO);
removeEvent($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], "state", "OFF"); //removeEvent($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], "state", "OFF");
setDelay($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], $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 OR getValue(RDC_SALON_MVMT2,"occupancy") == ON))
{ {
logger(DEBUG, _("illuminance < min and movement detected"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("illuminance < min and movement detected"), __FILE__ . ":" . __LINE__);

View File

@ -23,7 +23,7 @@ class rdc_sdb_eclairage extends hook
RDC_SDB_WC_ECLAIRAGE => array("state_l1", false) RDC_SDB_WC_ECLAIRAGE => array("state_l1", false)
); );
// callback fonction. Is called with these 4 parameters // callback fonction. Is called with these 3 parameters
public function callBack(&$device, $property, $value) public function callBack(&$device, $property, $value)
{ {
global $devices, $indexDevices; global $devices, $indexDevices;
@ -32,20 +32,23 @@ class rdc_sdb_eclairage extends hook
{ {
case "occupancy": case "occupancy":
if ($value == ON) if ($value == ON)
{
if (getValue(RDC_SDB_WC_ECLAIRAGE, "state_l1") != "ON")
{ {
$this->send("ON"); $this->send("ON");
setDelay($device, $this->delay, $this->timeUnit, "state_l1", "OFF", true); }
//setDelay($indexDevices[RDC_SDB_WC_ECLAIRAGE], $this->delay, $this->timeUnit, "state_l1", "OFF", true);
$device->method = AUTO; $device->method = AUTO;
} }
break; break;
case "state_l1": case "state_l1":
if ($value == ON) if ($value == ON)
{ {
setDelay($device, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true); setDelay($indexDevices[RDC_SDB_WC_ECLAIRAGE], $this->delayManual, $this->timeUnit, "state_l1", "OFF", true);
$device->method = MANUAL; $device->method = MANUAL;
}elseif ($value = OFF) }elseif ($value = OFF)
{ {
deleteEvent(searchEvent($device, "state_l1", "OFF")); removeEvent($indexDevices[RDC_SDB_WC_ECLAIRAGE], "state_l1", "OFF");
} }
break; break;
} }

View File

@ -33,6 +33,7 @@ $logFh = null; // filehandle of log file
$curlErr = 0; // Number of errors returned by curl $curlErr = 0; // Number of errors returned by curl
$configDir = "./config"; // default config dir (production value is /etc/moha/) $configDir = "./config"; // default config dir (production value is /etc/moha/)
$hooksInitialized = 0; // are all hooks initialized ? false/true $hooksInitialized = 0; // are all hooks initialized ? false/true
$flagHooks = false;
$mqttServerIp = "127.0.0.1"; // IP address of mqttserver in production mode $mqttServerIp = "127.0.0.1"; // IP address of mqttserver in production mode
if ($testMode) if ($testMode)
{ {
@ -264,9 +265,10 @@ while (true)
} }
} }
$hooksInitialized = $i; $hooksInitialized = $i;
}else }elseif($flagHooks === false)
{ {
logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__); logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__);
$flagHooks = true;
} }
checkEvents(); checkEvents();
askWebServer($read); askWebServer($read);

View File

@ -42,11 +42,11 @@ $callback = function($topic, $message)
$fnTree = explode ("/" , $topic[1]); // get friendlyname $fnTree = explode ("/" , $topic[1]); // get friendlyname
echo $topic[0] . " => " . $topic[1] . EOL; echo $topic[0] . " => " . $topic[1] . EOL;
//$devices[$topic[0]][$fnTree[0]]->json = json_decode($message->payload); //$devices[$topic[0]][$fnTree[0]]->json = json_decode($message->payload);
if ($fnTree[array_key_last($fnTree)] == "availability" and is_string($message->payload)) if ($fnTree[array_key_last($fnTree)] == "availability")
{ {
unset ($fnTree[array_key_last($fnTree)]); unset ($fnTree[array_key_last($fnTree)]);
$payloadArray = array("availability" => $message->payload); $payloadArray = array("availability" => $message->payload);
//print_r($payloadArray); //TODO payload can be a json object
}else }else
{ {
$payloadArray = json_decode($message->payload); $payloadArray = json_decode($message->payload);

View File

@ -41,10 +41,10 @@ function mktopic($device)
return $device->topic . "/" . $device->friendlyName; return $device->topic . "/" . $device->friendlyName;
} }
function getValue($fn, $property) function getValue($ieeeAddress, $property)
{ {
global $indexDevices; global $indexDevices;
return $indexDevices[$fn]->$property["value"]; return $indexDevices[$ieeeAddress]->$property["value"];
} }
function setValue($fn, $property, $value) function setValue($fn, $property, $value)