diff --git a/apiserver/cmd_functions.php b/apiserver/cmd_functions.php index 68c3eca..ad51782 100644 --- a/apiserver/cmd_functions.php +++ b/apiserver/cmd_functions.php @@ -129,11 +129,11 @@ function displayChoice($device, $propertyName, $value) return $formHTML; } -function displayMethod($device, $property) +function displayMethod($device, $propertyName) { - $html = 'friendlyName . "/" . $propertyName . "/" . strtolower($value) . '" method="' . IDLE . "\" onmouseup=\"setPropertyMethod('" . $device->topic . "', '" . $device->friendlyName . "', '" . IDLE . "', '" . $propertyName . "')\">"; - $html = 'friendlyName . "/" . $propertyName . "/" . strtolower($value) . '" method="' . AUTO . "\" onmouseup=\"setPropertyMethod('" . $device->topic . "', '" . $device->friendlyName . "', '" . AUTO . "', '" . $propertyName . "')\">"; - $html = 'friendlyName . "/" . $propertyName . "/" . strtolower($value) . '" method="' . MANUAL . "\" onmouseup=\"setPropertyMethod('" . $device->topic . "', '" . $device->friendlyName . "', '" . MANUAL . "', '" . $propertyName . "')\">"; + $html = 'friendlyName . "/" . $propertyName . '" method="' . IDLE . "\" onmouseup=\"setPropertyMethod('" . $device->topic . "', '" . $device->friendlyName . "', '" . IDLE . "', '" . $propertyName . "')\">"; + $html = 'friendlyName . "/" . $propertyName . "/" . '" method="' . AUTO . "\" onmouseup=\"setPropertyMethod('" . $device->topic . "', '" . $device->friendlyName . "', '" . AUTO . "', '" . $propertyName . "')\">"; + $html = 'friendlyName . "/" . $propertyName . "/" . '" method="' . MANUAL . "\" onmouseup=\"setPropertyMethod('" . $device->topic . "', '" . $device->friendlyName . "', '" . MANUAL . "', '" . $propertyName . "')\">"; } function mkHTML($device, $propertyName, $choice) { diff --git a/hooks/scripts/rdc_salon_eclairage.php b/hooks/scripts/rdc_salon_eclairage.php index b77c620..c87e69b 100644 --- a/hooks/scripts/rdc_salon_eclairage.php +++ b/hooks/scripts/rdc_salon_eclairage.php @@ -98,7 +98,7 @@ class rdc_salon_eclairage extends hook //{ logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__); $deviceTarget->payload = $msg; - $deviceTarget->set("state", "method"); + $deviceTarget->set("state", $method); //$deviceTarget->properties["state"]["method"] = $method; /*}else { diff --git a/hooks/scripts/rdc_sdb_eclairage.php b/hooks/scripts/rdc_sdb_eclairage.php index 84f271b..98899ee 100644 --- a/hooks/scripts/rdc_sdb_eclairage.php +++ b/hooks/scripts/rdc_sdb_eclairage.php @@ -9,7 +9,7 @@ class rdc_sdb_eclairage extends hook // public $active = true; //public $initlialized = false; - public $delay = 1; // amount of time in $timeunit + 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 // list of devices we are listening to diff --git a/hooks/scripts/rdc_store.php b/hooks/scripts/rdc_store.php index 3e741dc..d3d6347 100644 --- a/hooks/scripts/rdc_store.php +++ b/hooks/scripts/rdc_store.php @@ -78,37 +78,7 @@ class rdc_store extends hook $this->storeLevel = 0; //return true; } - if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties)) - { - $exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"]; - $exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5); - if ($exterieurLuxMoyen == 0) - { - $exterieurLuxMoyen = $exterieur_lux; - } - logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__); - } - if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties)) - { - $salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10); - if ($salon_lux == 0) - { - $salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"]; - } - logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__); - } - if ($exterieur_lux > 30000 or $salon_lux >600) - { - logger(DEBUG, "exterieur_lux > 30000 or salon_lux >600", __FILE__ . ":" . __LINE__); - if ($this->maxLevel != 0 and $salon_lux > 100) - { - $store2level = $this->storeLevel + 15; - } - }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 450) - { - logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 1000", __FILE__ . ":" . __LINE__); - $this->close("Luminosité faible"); - } + if (array_key_exists(METEO, $indexDevices)) { if (array_key_exists("rainin", $indexDevices[METEO]->properties)) @@ -150,10 +120,43 @@ class rdc_store extends hook } if (array_key_exists("solarradiation", $indexDevices[METEO]->properties)) { - $soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12); + $soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 6); logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__); } } + + if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties)) + { + $exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"]; + $exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5); + if ($exterieurLuxMoyen == 0) + { + $exterieurLuxMoyen = $exterieur_lux; + } + logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__); + } + if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties)) + { + $salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10); + if ($salon_lux == 0) + { + $salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"]; + } + logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__); + } + if ($exterieur_lux > 33000 or $salon_lux >600) + { + logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__); + if ($this->maxLevel != 0 and $salon_lux > 100) + { + $store2level = $this->storeLevel + 15; + } + }elseif ($exterieurLuxMoyen < 6000 and $salon_lux < 200 and $soleil < 100) + { + logger(DEBUG, "exterieurLuxMoyen < 6000 and salon_lux < 200 and soleil < 100", __FILE__ . ":" . __LINE__); + $this->close("Luminosité faible"); + } + logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__); if ($rafale >= 70 or $rain != 0) { diff --git a/hooks/scripts/rdc_store.php~ b/hooks/scripts/rdc_store.php~ index f4e8816..934648d 100644 --- a/hooks/scripts/rdc_store.php~ +++ b/hooks/scripts/rdc_store.php~ @@ -78,37 +78,7 @@ class rdc_store extends hook $this->storeLevel = 0; //return true; } - if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties)) - { - $exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"]; - $exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5); - if ($exterieurLuxMoyen == 0) - { - $exterieurLuxMoyen = $exterieur_lux; - } - logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__); - } - if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties)) - { - $salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10); - if ($salon_lux == 0) - { - $salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"]; - } - logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__); - } - if ($exterieur_lux > 30000 or $salon_lux >600) - { - logger(DEBUG, "exterieur_lux > 30000 or salon_lux >600", __FILE__ . ":" . __LINE__); - if ($this->maxLevel != 0 and $salon_lux > 100) - { - $store2level = $this->storeLevel + 15; - } - }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 450) - { - logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 1000", __FILE__ . ":" . __LINE__); - $this->close("Luminosité faible"); - } + if (array_key_exists(METEO, $indexDevices)) { if (array_key_exists("rainin", $indexDevices[METEO]->properties)) @@ -150,10 +120,43 @@ class rdc_store extends hook } if (array_key_exists("solarradiation", $indexDevices[METEO]->properties)) { - $soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12); + $soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 6); logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__); } } + + if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties)) + { + $exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"]; + $exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5); + if ($exterieurLuxMoyen == 0) + { + $exterieurLuxMoyen = $exterieur_lux; + } + logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__); + } + if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties)) + { + $salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10); + if ($salon_lux == 0) + { + $salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"]; + } + logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__); + } + if ($exterieur_lux > 33000 or $salon_lux >600) + { + logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__); + if ($this->maxLevel != 0 and $salon_lux > 100) + { + $store2level = $this->storeLevel + 15; + } + }elseif ($exterieurLuxMoyen < 6000 and $salon_lux < 200 and $soleil < 100) + { + logger(DEBUG, "exterieurLuxMoyen < 11000 and salon_lux < 1000", __FILE__ . ":" . __LINE__); + $this->close("Luminosité faible"); + } + logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__); if ($rafale >= 70 or $rain != 0) { @@ -191,17 +194,17 @@ class rdc_store extends hook logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); if ($this->storeLevel > $this->maxLevel) { - $this->setTo($this->maxLevel); + $this->setTo($this->maxLevel, AUTO); }elseif ($store2level !== false) //$store2level = false then no change on store position { if ( $store2level > $this->maxLevel ) { logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__); - $this->setTo($this->maxLevel); + $this->setTo($this->maxLevel, AUTO); }else { logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__); - $this->setTo($store2level); + $this->setTo($store2level, AUTO); } } }else @@ -211,13 +214,13 @@ class rdc_store extends hook } - private function setTo($level) + private function setTo($level, $method) { logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__); if ($level <= 100) { logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__); - $this->send(100 - $level, AUTO); + $this->send(100 - $level, $method); }//else /*{ logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__); diff --git a/hooks/scripts/rdc_wc_eclairage.php b/hooks/scripts/rdc_wc_eclairage.php index 094c152..1125ede 100644 --- a/hooks/scripts/rdc_wc_eclairage.php +++ b/hooks/scripts/rdc_wc_eclairage.php @@ -10,7 +10,7 @@ class rdc_wc_eclairage extends hook RDC_WC_MVMT => "occupancy" ); - public $delay = 1; // 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 $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year @@ -41,6 +41,7 @@ class rdc_wc_eclairage extends hook break; case "occupancy": logger(DEBUG, "CASE: occupancy", __FILE__ . ":" . __LINE__); + logger(DEBUG, "method =" . $targetDevice->properties["state_l2"]["method"], __FILE__ . ":" . __LINE__); if ($value === true and $targetDevice->properties["state_l2"]["method"] == IDLE) { //$targetDevice->properties["state_l2"]["method"] = AUTO; diff --git a/hooks/scripts/rdc_wc_eclairage.php~ b/hooks/scripts/rdc_wc_eclairage.php~ index 678832f..68d3e3b 100644 --- a/hooks/scripts/rdc_wc_eclairage.php~ +++ b/hooks/scripts/rdc_wc_eclairage.php~ @@ -41,10 +41,11 @@ class rdc_wc_eclairage extends hook break; case "occupancy": logger(DEBUG, "CASE: occupancy", __FILE__ . ":" . __LINE__); + logger(DEBUG, "method =" . $targetDevice->properties["state_l2"]["method"], __FILE__ . ":" . __LINE__); if ($value === true and $targetDevice->properties["state_l2"]["method"] == IDLE) { - $targetDevice->properties["state_l2"]["method"] = AUTO; - $this->send($targetDevice, "ON"); + //$targetDevice->properties["state_l2"]["method"] = AUTO; + $this->send($targetDevice, "ON", AUTO); }elseif ($value === false and $targetDevice->properties["state_l2"]["method"] == AUTO) { //$targetDevice->properties["state_l2"]["method"] = IDLE; @@ -54,14 +55,14 @@ class rdc_wc_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__); } - private function send($targetDevice, $state) + private function send($targetDevice, $state, $method = IDLE) { global $indexDevices; $msg = array("state_l2" => $state); logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $targetDevice->friendlyName), __FILE__ . ":" . __LINE__); $targetDevice->payload = $msg; - $targetDevice->set(null); + $targetDevice->set("state_l2", $method); } } diff --git a/moha.php b/moha.php index fdfa988..20b3b59 100644 --- a/moha.php +++ b/moha.php @@ -50,7 +50,7 @@ if ($testMode) $httpServerIp = "192.168.1.253"; }else { - $logLevel = DEBUG | INFO | NOTICE | WARNING | ERROR | ALERT; + $logLevel = INFO | NOTICE | WARNING | ERROR | ALERT; $mqttServerIp = "127.0.0.1"; // IP address of mqttserver in production mode $dataPath = "/usr/share/moha/"; $logFile = "/var/log/moha.log"; // Path of log file diff --git a/webserver/display_stats.php b/webserver/display_stats.php index 1a7668e..ff064eb 100644 --- a/webserver/display_stats.php +++ b/webserver/display_stats.php @@ -177,7 +177,13 @@ function diagramDisplay($datas) } $tmp = explode("|", $_GET["device"]); +if (!empty($tmp[0]) && !empty($tmp[1]) && !empty($tmp[2])) +{ + displayStats($tmp[0], $tmp[1], $tmp[2], $_GET["startDate"], $_GET["endDate"]); +}else +{ + logger(ERROR, "Your syntax is bad"); +} -displayStats($tmp[0], $tmp[1], $tmp[2], $_GET["startDate"], $_GET["endDate"]); ?> diff --git a/webserver/index.php b/webserver/index.php index 4fd0a1f..bd2d5dd 100644 --- a/webserver/index.php +++ b/webserver/index.php @@ -33,7 +33,7 @@ if (empty($indexIeeeAddress)) $devicesList[$value["device"]][] = $value["property"]; } } - array_multisort($devicesList); + ksort($devicesList, SORT_STRING ); //$devicesList = array_intersect_key($indexIeeeAddress, $tmp); //print_r($devicesList); diff --git a/www/index.php b/www/index.php deleted file mode 100644 index 9327cea..0000000 --- a/www/index.php +++ /dev/null @@ -1,9 +0,0 @@ -