diff --git a/hooks/scripts/etage_plan_travail_eclairage.php b/archives/etage_plan_travail_eclairage.php
similarity index 100%
rename from hooks/scripts/etage_plan_travail_eclairage.php
rename to archives/etage_plan_travail_eclairage.php
diff --git a/class/db.php b/class/db.php
index a584af2..9728805 100644
--- a/class/db.php
+++ b/class/db.php
@@ -47,7 +47,7 @@ class db extends mysqli
$ieeeAddress = $device->ieeeAddress;
//print_r($ieeeAddress);
$query = "INSERT INTO logs (device, property, value) VALUES('" . $this->protect($ieeeAddress) . "', '" . $this->protect($property) . "', '" . $this->protect(bool2string($value)) . "')";
- echo $query;
+ echo $query . EOL;
if (is_numeric($value) and !empty($properties2log[$property]))
{
// calculate a min/max value for storing data
@@ -56,6 +56,10 @@ class db extends mysqli
{
$minMax = $minMax($value);
}
+ var_dump($value) . EOL;
+ var_dump($minMax) . EOL;
+ var_dump($oldValue) . EOL;
+ if ( !is_numeric($oldValue)) $oldValue = 0;
//echo "minMax = " .$minMax . EOL;
//echo "oldValue = " . $oldValue . EOL;
//echo "Value = " . $value . EOL;
@@ -81,12 +85,15 @@ class db extends mysqli
function moyenne($deviceObject, $property, $time)
{
- $query = "SELECT AVG(value) FROM logs WHERE device='" . $deviceObject->ieeeAddress . "' AND property='" . $property . "' AND TIMEDIFF(NOW(), 'date') < " . $time;
+ $query = "SELECT AVG(value) as value FROM logs WHERE device='" . $deviceObject->ieeeAddress . "' AND property='" . $property . "' AND TIMEDIFF(NOW(), date) < '00:" . $time . "'";
if(!$this->result = $this->query($query))
{
logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__);
}
- var_dump($this->result);
+
+ $value = $this->result->fetch_array(MYSQLI_NUM);
+ //var_dump($value);
+ return $value[0];
}
}
diff --git a/config/dashboard_conf.php b/config/dashboard_conf.php
index 72146b5..553ebe4 100644
--- a/config/dashboard_conf.php
+++ b/config/dashboard_conf.php
@@ -17,4 +17,12 @@
array(METEO, "UV"),
array(METEO, "solarradiation")
);
-?>
+ $dashboards["etage"] = array(
+ array(ETAGE_SALON_RADIATEUR,"current_heating_setpoint"),
+ array(ETAGE_BUREAU_RADIATEUR,"current_heating_setpoint"),
+ array(ETAGE_BUREAU_PANNEAU, "state"),
+ array(ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE, "state"),
+ array(ETAGE_CUISINE_PLAN_TRAVAIL_SPOT, "state_l1")
+
+ );
+ ?>
diff --git a/config/devices_constants.php b/config/devices_constants.php
index 9531045..00142ed 100644
--- a/config/devices_constants.php
+++ b/config/devices_constants.php
@@ -31,11 +31,14 @@ $deviceTable = array(
// "" => "ETAGE_SDB_RADIATEUR",
"0x5c0272fffec4de9e" => "ETAGE_BUREAU_RADIATEUR",
"0x00158d0001a0028c" => "ETAGE_BUREAU_FENETRE",
+ "0x14b457fffe42a2c9" => "ETAGE_BUREAU_PANNEAU",
+ "0x842e14fffe8e3b67" => "ETAGE_BUREAU_ECLAIRAGE_INTER",
"0x00158d0001de080d" => "ETAGE_CHAMBRE_FENETRE",
- "0x842e14fffe8c53a5" => "ETAGE_CUISINE_PLAN_TRAVAIL_INTER",
+ "0x00124b00251ea4a7" => "ETAGE_CUISINE_PLAN_TRAVAIL_INTER",
"0x680ae2fffe403f22" => "ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE",
"0xbc33acfffe65621b" => "ETAGE_CUISINE_PLAN_TRAVAIL_SPOT",
- "0x00158d0001ddefe1" => "ETAGE_ENTREE_PORTE",
+ "1" => "ETAGE_CUISINE_PLAN_TRAVAIL_GROUPE_ECLAIRAGE",
+ "0x00158d00019f370e" => "ETAGE_PORTE_ENTREE",
"0x00158d00044fd579" => "ETAGE_SALON_FENETRE",
"0x00158d0004621e1f" => "ETAGE_CUISINE_FENETRE",
"0x00158d0001ddefe1" => "ETAGE_PORTE_FENETRE",
diff --git a/config/properties2log.php b/config/properties2log.php
index ac823fb..ba159d4 100644
--- a/config/properties2log.php
+++ b/config/properties2log.php
@@ -13,22 +13,22 @@ $properties2log = array(
"local_temperature" => 0.5,
"state_l1" => null,
"state_l2" => null,
- "humidity" => null,
+ "humidity" => 0.9,
"current_heating_setpoint" => null,
"position" => null,
"pressure" => 10,
"occupancy" => null,
- "illuminance_lux" => function($value) {($value < 500?50:$value*10/100); return $value;},
+ "illuminance_lux" => function($value) {$r = ($value < 500?50:$value*10/100); return $r;},
// "illuminance" => 8,
- "requested_brightness_level" => function($value) {($value < 500?50:$value*10/100);return $value;},
+ "requested_brightness_level" => function($value) {$r = ($value < 500?50:$value*10/100);return $r;},
"tempc" => 0.5,
- "humidity" => null,
+ "humidity" => 1,
"dewptc" => 0.5,
"windchillc" => 0.5,
"winddir" => 40,
"windspeedkmh" => 5,
"windgustkmh" => 5,
- "rainin" => null,
+ "rainin" => 0.5,
//"dailyrainin" => null,
//"weeklyrainin" => null,
//"monthlyrainin" => null,
@@ -36,7 +36,7 @@ $properties2log = array(
"solarradiation" => 10,
"UV" => null,
"indoortempc" => 0.5,
- "indoorhumidity" => null,
+ "indoorhumidity" => 0.5,
"baromin" => 10
);
diff --git a/config/propertiesbytype.php b/config/propertiesbytype.php
index 1d0dedc..1fd3365 100644
--- a/config/propertiesbytype.php
+++ b/config/propertiesbytype.php
@@ -6,7 +6,7 @@ $propertyByType = array(
"brightness",
"state_l1",
"state_l2"
- )
+ ),
"climate" => array(
"local_temperature",
"value",
diff --git a/config/types.php b/config/types.php
new file mode 100644
index 0000000..9195cef
--- /dev/null
+++ b/config/types.php
@@ -0,0 +1,31 @@
+ array(
+ "0xbc33acfffe6561e4",
+ "0xbc33acfffe65621b",
+ "0x086bd7fffe5aeab6",
+ "0x588e81fffe343e8f",
+ "0x680ae2fffe403f22",
+ "0x14b457fffe42a2c9"
+ ),
+ "switch" => array(
+ "0xbc33acfffe458c65",
+ "0xbc33acfffe4583f7",
+ "0x00158d0005c1a998",
+ "0x842e14fffe9be0fc",
+ "0x086bd7fffe40482d",
+ "0x5c0272fffec4de9"
+ ),
+ "climate" => array(
+ "0x00158d0001923c21",
+ "0xbc33acfffe458c65",
+ "0x5c0272fffec4de9e",
+ "0xbc33acfffe4583f7"
+ ),
+ "cover" => array(
+ "0x842e14fffe9be0fc"
+ ),
+ "hvac" =>
+ );
+?>
diff --git a/db_functions.php b/db_functions.php
index f7d2453..922161d 100644
--- a/db_functions.php
+++ b/db_functions.php
@@ -63,6 +63,7 @@ function mkDevicesDB($topic, $json, $group=false)
{
//print_r($device);
$device["device"]->groupID = $jsonDevice->id;
+ $device["device"]->ieeeAddress = $jsonDevice->id;
//$indexDevices[$device["device"]->groupID] = & $device["device"];
//$indexFriendlyNames[$topic][$fn] = & $device["device"];
}else
@@ -267,7 +268,14 @@ function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key)
logger(DEBUG,_("executing notifications functions"), __FILE__ . ":" . __LINE__);
foreach($property["functions"] as $function)
{
- $function($parentDevice, $key, $value);
+ try
+ {
+ $function($parentDevice, $key, $value);
+ }catch (Exception $e)
+ {
+ $s = 'Exception reçue : ' . $e->getMessage();
+ logger(ERROR, $parentDevice->friendlyName . "/" . $property .": " . $s);
+ }
}
}
}
diff --git a/events.php b/events.php
index 504516e..42a129b 100644
--- a/events.php
+++ b/events.php
@@ -10,6 +10,10 @@ function checkEvents()
$oldLevel = $logLevel;
$logLevel = DEBUG;
$exception = false;
+ if ($events === null)
+ {
+ $events = array();
+ }
foreach ($events as $key => &$event)
{
$now = now();
@@ -37,7 +41,7 @@ function checkEvents()
{
if (is_callable($this->function))
{
- $this->function(&$event);
+ $this->function($event);
}else
{
logger(DEBUG, sprintf(_("sending command set %s => %s for %s"), $event->param ,bool2string($event->value), $event->device->friendlyName), __FILE__ . ":" . __LINE__);
diff --git a/hooks/notifiers/notificationfreemobile.php b/hooks/notifiers/notificationfreemobile.php
index cc43b1d..ed6bb66 100644
--- a/hooks/notifiers/notificationfreemobile.php
+++ b/hooks/notifiers/notificationfreemobile.php
@@ -1,17 +1,20 @@
level = ALERT | ERROR;
}
- function send($message)
+ function send($message, $destinataire=0)
{
global $curlErr;
$result = false;
@@ -19,25 +22,22 @@ class notificationFreemobile
{
$ch = curl_init();
// set url
- curl_setopt($ch, CURLOPT_URL, $this->url . urlencode(trim($message)));
+ curl_setopt($ch, CURLOPT_URL, $this->url . $dest["destinataire"] . "&msg=" . urlencode(trim($message)));
echo $this->url . urlencode(trim($message)) . EOL;
//return the transfer as a string
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-
// $result contains the output string
- //echo "1 curlErr =>"; var_dump($curlErr); echo EOL;
if ($curlErr <= 10)
{
$result = curl_exec($ch);
- //echo "1 result => "; var_dump($result);echo EOL;
if ($result === false)
{
$curlErr += 1;
logger(ERROR, sprintf( _("Curl return error %d: %s when sending notification"), curl_errno($ch), curl_error($ch)), false, __FILE__ . ":" . __LINE__);
- }/*else
+ }else
{
- logger(INFO, sprintf(_("Curl return: %s when sending notification"), $result), false);
- }*/
+ logger(DEBUG, sprintf(_("Curl return: %s when sending notification"), $result), false);
+ }
} //TODO managing curl errors
// close curl resource to free up system resources
curl_close($ch);
diff --git a/hooks/scripts/radiateurs.php b/hooks/scripts/radiateurs.php
index 41c6617..ed6ba7f 100644
--- a/hooks/scripts/radiateurs.php
+++ b/hooks/scripts/radiateurs.php
@@ -11,33 +11,31 @@ class radiateurs extends hook
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
+ // list of devices we are listening to: ieeeAddress => property to watch
protected $devicelist = array(
RDC_CHAMBRE_BAIE => "contact",
- RDC_SALON_BAIE => "contact",
- RDC_ENTREE_PORTE => "contact",
- ETAGE_ENTREE_PORTE => "contact",
+// RDC_SALON_BAIE => "contact",
+// RDC_ENTREE_PORTE => "contact",
+ ETAGE_PORTE_ENTREE => "contact",
ETAGE_CUISINE_FENETRE => "contact",
ETAGE_SALON_FENETRE => "contact",
- ETAGE_SALON_PORTE_FENETRE => "contact",
- ETAGE_CHAMBRE_FENETRE => "contact",
- ETAGE_BUREAU_FENETRE => "contact"
+ ETAGE_PORTE_FENETRE => "contact",
+// ETAGE_CHAMBRE_FENETRE => "contact",
+// ETAGE_BUREAU_FENETRE => "contact"
);
- PROTECTED $hvac = array(
+ 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,
+ GARAGE_PORTE => RDC_SDB_RADIATEUR,
+ ETAGE_PORTE_ENTREE => ETAGE_SALON_RADIATEUR,
ETAGE_CUISINE_FENETRE => ETAGE_SALON_RADIATEUR,
ETAGE_SALON_FENETRE => ETAGE_SALON_RADIATEUR,
- ETAGE_SALON_PORTE_FENETRE => ETAGE_SALON_RADIATEUR,
+ ETAGE_PORTE_FENETRE => ETAGE_SALON_RADIATEUR,
// ETAGE_CHAMBRE_FENETRE => ETAGE_CHAMBRE_RADIATEUR,
- ETAGE_BUREAU_FENETRE => ETAGE_BUREAU_RADIATEUR,
+// ETAGE_BUREAU_FENETRE => ETAGE_BUREAU_RADIATEUR,
// ETAGE_SDB_FENETRE => ETAGE_SDB_RADIATEUR
);
@@ -55,38 +53,42 @@ class radiateurs extends hook
public function callBack(&$device, $property, $value)
{
global $indexDevices;
- $now = date("MM");
- if ($now <= 5 or $now >= 11)
+ logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
+ if ($this->active === true)
{
- if ($value === false)
+ $now = date("MM");
+ if ($now <= 5 or $now >= 11)
{
- send($indexDevices[$hvac[$device->ieeeAddress]], true);
- /* switch ($device->$ieeeAdress)
+ if ($value === false)
{
- 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:
+ $this->send($indexDevices[$this->hvac[$device->ieeeAddress]], true);
+ /* switch ($device->$ieeeAddress)
+ {
+ 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_CHAMBRE_FENETRE:
- break;
- case ETAGE_BUREAU_FENETRE:
+ break;
+ case ETAGE_BUREAU_FENETRE:
- break;
- }*/
- }else
- {
- send($indexDevices[$hvac[$device->ieeeAddress]], false);
+ break;
+ }*/
+ }else
+ {
+ $this->send($indexDevices[$this->hvac[$device->ieeeAddress]], false);
+ }
}
}
}
@@ -94,31 +96,33 @@ class radiateurs extends hook
function send($device, $state)
{
global $indexDevices;
+ $flag = false;
if ($state === false)
{
- $t = getValue($device, "current_heating_setpoint");
- if ($t != $minTemp)
+ $t = getValue($device->ieeeAddress, "current_heating_setpoint");
+ if ($t != $this->minTemp)
{
- $prevTemp[$device] = getValue($device, "current_heating_setpoint");
+ $this->prevTemp[$device->ieeeAddress] = getValue($device->ieeeAddress, "current_heating_setpoint");
}
}else
{
- $r = array_keys($hvac, $device->ieeeAddress);
+ $r = array_keys($this->hvac, $device->ieeeAddress);
foreach($r as $value)
{
- if (getValue($indexDevices[$value], "contact") === true)
+ logger(DEBUG, "Device to test for contact " . $value, __FILE__ . ":" . __LINE__);
+ if (getValue($device->ieeeAddress, "contact") === true)
{
- $flag = 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;
+ $msg = array("current_heating_setpoint" => (!empty($this->prevTemp[$device->ieeeAddress])?$this->prevTemp[$device->ieeeAddress]:19));
+ logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName), __FILE__ . ":" . __LINE__);
+ $device->payload = $msg;
+ $device->set();
+ $device->method = AUTO;
}
}
}
diff --git a/hooks/scripts/rdc_chambre_eclairage.php b/hooks/scripts/rdc_chambre_eclairage.php
index 22ba373..a103bf0 100644
--- a/hooks/scripts/rdc_chambre_eclairage.php
+++ b/hooks/scripts/rdc_chambre_eclairage.php
@@ -22,6 +22,7 @@ class rdc_chambre_eclairage extends hook
public function callBack($device, $property, $value)
{
global $devices, $indexDevices;
+ logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
$lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->properties["illuminance_lux"];
$targetAmbiance = $indexDevices[RDC_CHAMBRE_AMBIANCE];
$targetEclairage = $indexDevices[RDC_CHAMBRE_ECLAIRAGE];
@@ -32,12 +33,12 @@ class rdc_chambre_eclairage extends hook
$this->send($targetAmbiance, "state", "ON", "OFF", AUTO);
}elseif ($property == "contact")
{
- if ($value == false and getValue(RDC_CHAMBRE_ECLAIRAGE, "state_l1") == "OFF")
+ if ($value == false)
{
$this->send($targetEclairage, "state_l1", "ON", "OFF", AUTO);
- }elseif ($value == true and getValue(RDC_CHAMBRE_ECLAIRAGE, "state_l1") == "ON")
+ }elseif ($value == true)
{
- $this->send($targetEclairage, "state_l1", "OFF", null, null);
+ $this->send($targetEclairage, "state_l1", "OFF", false, null);
}
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
@@ -47,17 +48,17 @@ class rdc_chambre_eclairage extends hook
{
global $indexDevices;
$msg = array($property => $state);
- if ($deviceObject->properties[$property]["value"] != $state)
- {
+ //if ($deviceObject->properties[$property]["value"] != $state)
+ //{
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg;
$deviceObject->set();
$deviceObject->method = $method;
- }else
- {
+ ///}else
+ /*{
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
- }
+ }*/
//echo 'delaystate = ' . var_dump($delayState);
if ($delayState !== false) setDelay($deviceObject, $this->delay, $this->timeUnit, "state", $delayState, true);
}
diff --git a/hooks/scripts/rdc_portes_ouvertes.php b/hooks/scripts/rdc_portes_ouvertes.php
index 4a390c1..088ab63 100644
--- a/hooks/scripts/rdc_portes_ouvertes.php
+++ b/hooks/scripts/rdc_portes_ouvertes.php
@@ -18,7 +18,7 @@ class alerte_intrusion extends hook
// callback fonction. Is called with these 4 parameters
public function callBack($device, $property, $value)
{
-
+ logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
switch($property)
{
case "contact":
diff --git a/hooks/scripts/rdc_salon_eclairage.php b/hooks/scripts/rdc_salon_eclairage.php
index bab164c..7955040 100644
--- a/hooks/scripts/rdc_salon_eclairage.php
+++ b/hooks/scripts/rdc_salon_eclairage.php
@@ -21,7 +21,7 @@ class rdc_salon_eclairage extends hook
public function callBack($device, $param, $value)
{
global $indexDevices;
- logger(INFO, _("hook : rdc_salon_eclairage"), __FILE__ . ":" . __LINE__);
+ logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
$deviceTarget = &$indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU];
$lux = $indexDevices[RDC_SALON_LUMINOSITE];
$mvmt = $indexDevices[RDC_SALON_MVMT];
@@ -40,7 +40,7 @@ class rdc_salon_eclairage extends hook
if ($illuminance <= $this->luminance_min)
{
logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
- $this->send($deviceTarget, "ON", null, AUTO);
+ $this->send($deviceTarget, "ON", false, AUTO);
removeEvent($deviceTarget, "state", "OFF");
}
}else
@@ -61,7 +61,7 @@ class rdc_salon_eclairage extends hook
logger(INFO, _("Door is open and illumance < min"), __FILE__ . ":" . __LINE__);
if (getValue(RDC_SALON_MVMT, "occupancy") == ON or getValue(RDC_SALON_MVMT2, "occupancy") == ON)
{
- $this->send($deviceTarget, "ON", null, AUTO);
+ $this->send($deviceTarget, "ON", false, AUTO);
}else
{
$this->send($deviceTarget, "ON", "OFF", AUTO);
@@ -82,7 +82,7 @@ class rdc_salon_eclairage extends hook
}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__);
- $this->send($deviceTarget, "ON", null, AUTO);
+ $this->send($deviceTarget, "ON", false, AUTO);
}
break;
}
@@ -94,16 +94,16 @@ class rdc_salon_eclairage extends hook
global $indexDevices;
$msg = array("state" => $state);
- if ($deviceTarget->properties["state"]["value"] != $state)
- {
+ //if ($deviceTarget->properties["state"]["value"] != $state)
+ //{
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__);
$deviceTarget->payload = $msg;
$deviceTarget->set();
$deviceTarget->method = $method;
- }else
+ /*}else
{
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__);
- }
+ }*/
//echo 'delaystate = ' . var_dump($delayState);
if ($delayState !== false) setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", $delayState, true);
}
diff --git a/hooks/scripts/rdc_sdb_eclairage.php b/hooks/scripts/rdc_sdb_eclairage.php
index 8667f1c..e8b7856 100644
--- a/hooks/scripts/rdc_sdb_eclairage.php
+++ b/hooks/scripts/rdc_sdb_eclairage.php
@@ -29,18 +29,14 @@ class rdc_sdb_eclairage extends hook
global $indexDevices;
//var_dump($value);
$deviceTarget = $indexDevices[RDC_SDB_WC_ECLAIRAGE];
- logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
+ logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
switch($property)
{
case "occupancy":
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
- if ($value == ON)
+ if ($value == ON )
{
- if (getValue($deviceTarget->ieeeAddress, "state_l1") != "ON")
- {
- $this->send("ON");
- }
- //setDelay($indexDevices[RDC_SDB_WC_ECLAIRAGE], $this->delay, $this->timeUnit, "state_l1", "OFF", true);
+ $this->send("ON");
$device->method = AUTO;
}
break;
@@ -48,11 +44,20 @@ class rdc_sdb_eclairage extends hook
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
- setDelay($deviceTarget, $this->delay, $this->timeUnit, "state_l1", "OFF", true);
- $device->method = MANUAL;
- }elseif ($value = "OFF")
+ if ($device->method != MANUAL)
+ {
+ $delay = $this->delay;
+ $device->method = AUTO;
+ }else
+ {
+ $delay = $this->delayManual;
+ $device->method = MANUAL;
+ }
+ setDelay($deviceTarget, $delay, $this->timeUnit, "state_l1", "OFF", true);
+ }elseif ($value == "OFF")
{
removeEvent($deviceTarget, "state_l1", "OFF");
+ $device->method = null;
}
break;
}
diff --git a/hooks/scripts/rdc_store.php b/hooks/scripts/rdc_store.php
index 3317984..8e48859 100644
--- a/hooks/scripts/rdc_store.php
+++ b/hooks/scripts/rdc_store.php
@@ -9,12 +9,13 @@ class rdc_store extends hook
public $luminance_max = 3000;
public $storeDownTime = 38;
public $storeUpTime = 41;
+ public $maxLevel;
protected $storeLevel;
protected $propertyInitialized =array();
protected $devicelist = array(
- RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux", // "ON"/"OFF"
+ RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux",
METEO => "rainin",
- //METEO => array("solarradiation", false),
+ //METEO => "solarradiation",
METEO => "windspeedkmh",
METEO => "windgustkmh"
);
@@ -30,62 +31,86 @@ class rdc_store extends hook
logger(DEBUG, "Callback : RDC_STORE", __FILE__ . ":" . __LINE__);
$rain = 0;
$exterieur_lux = 0;
+ $salon_lux = 0;
$rafale = 0;
$soleil = 0;
$storeDevice = $indexDevices[RDC_STORE];
+
if (array_key_exists("position", $storeDevice->properties))
{
- $storeLevel = $storeDevice->properties["position"];
+ $this->storeLevel = 100 - $storeDevice->properties["position"]["value"];
+ logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__);
}else
{
- return true;
+ $this->storeLevel = 0;
+ //return true;
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
{
$exterieur_lux = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 15);
+ logger(DEBUG, "exterieur_lux=" . $exterieur_lux, __FILE__ . ":" . __LINE__);
}
- if (array_key_exists("rainin", $indexDevices[METEO]->properties))
+ if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties))
{
- $rain = $indexDevices[METEO]->properties["rainin"];
+ $salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10);
+ logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__);
}
- if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
+ if (array_key_exists(METEO, $indexDevices))
{
- $rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 12);
- }
- if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
- {
- $soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12);
- }
- logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
- if ($rafale >= 6 or $rain != 0)
- {
- $maxLevel = 0;
- }else
- {
- if ($rafale != 0)
+ if (array_key_exists("rainin", $indexDevices[METEO]->properties))
{
- $maxLevel = 100 / $rafale;
+ $rain = $indexDevices[METEO]->properties["rainin"]["value"];
+ logger(DEBUG, "rain=" . var_dump($rain), __FILE__ . ":" . __LINE__);
+ }
+ if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
+ {
+ $rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 12);
+ logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
+ }
+ if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
+ {
+ $soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12);
+ logger(DEBUG, "soleil=" . $exterieur_lux, __FILE__ . ":" . __LINE__);
}
}
+ logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
+ if ($rafale >= 60 or $rain != 0)
+ {
+ $this->maxLevel = 0;
+ logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__);
+ $this->close("vent trop fort ou pluie");
+ return 0;
+ }elseif ($rafale != 0)
+ {
+ $this->maxLevel = ($r = 100 - round(($rafale-10)/5, 0, PHP_ROUND_HALF_UP)*20)<0 ? 0 : $r;
+ //$this->maxLevel = 100 / $rafale;
+ logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
+ }
+ logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
+ //$store2level = $this->maxLevel;
switch ($property)
{
case "illuminance_lux":
logger(DEBUG, "CASE: illuminance_lux:" . $value, __FILE__ . ":" . __LINE__);
- if ($exterieur_lux > 3000)
+ if ($exterieur_lux > 40000)
{
- if ($rain == 0 and $maxLevel != 0)
+ logger(DEBUG, "exterieur_lux > 40000", __FILE__ . ":" . __LINE__);
+ if ($this->maxLevel != 0 and $salon_lux > 150)
{
- $store2level = storeLevel + 15;
- if ( $store2level > $maxLevel )
+ $store2level = $this->storeLevel + 15;
+ if ( $store2level > $this->maxLevel )
{
- $this->open($maxLevel);
+ logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
+ $this->set($this->maxLevel);
}else
{
- $this->open($max2level);
+ logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
+ $this->set($store2level);
}
}
- }elseif ($exterieur_lux < 25000)
+ }elseif ($exterieur_lux < 35000)
{
+ logger(DEBUG, "exterieur_lux < 35000", __FILE__ . ":" . __LINE__);
$this->close("Luminosité faible");
}
break;
@@ -94,40 +119,25 @@ class rdc_store extends hook
$this->close("Pluie");
break;
case "windgustkmh";
- logger(DEBUG, "CASE: windgustkmh:" . $value, __FILE__ . ":" . __LINE__);
- case "windspeedkmh":
- logger(DEBUG, "CASE: windspeedkmh:" . $value, __FILE__ . ":" . __LINE__);
- if($value > 50)
+ logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__);
+ //case "windspeedkmh":
+ // logger(DEBUG, "CASE: windspeedkmh:" . $value, __FILE__ . ":" . __LINE__);
+
+ logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
+ if ($this->storeLevel > $this->maxLevel)
{
- $this->close("Trop de vent");
- }elseif ($value > 40 and $this->storeLevel > 20)
- {
- $this->maxLevel = 20;
- $this->send(20);
- }elseif ($value > 30 and $this->storeLevel > 40)
- {
- $this->maxLevel = 40;
- $this->send(40);
- }elseif ($value >20 and $this->storeLevel > 60)
- {
- $this->maxLevel = 60;
- $this->send(60);
- }elseif ($value >10 and $this->storeLevel > 80)
- {
- $this->maxLevel = 80;
- $this->send(80);
- }else
- {
- $this->maxLevel = 100;
+ $this->set($this->maxLevel);
}
- $this->close("Fortes rafales de vent");
break;
default:
-
+ }
+ if ($store2level <= $this->storeLevel)
+ {
+ $this->set($store2level);
}
}
- private function open ($level)
+ private function set ($level)
{
if ($this->storeLevel < $level)
{
@@ -140,8 +150,7 @@ class rdc_store extends hook
{
if ($this->storeLevel != 0)
{
- logger(DEBUG, "Close store :" . $level, __FILE__ . ":" . __LINE__);
- print ( "store fermé " . $reason);
+ logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__);
$this->send(100);
}
}
diff --git a/hooks/scripts/rdc_wc_eclairage.php b/hooks/scripts/rdc_wc_eclairage.php
index bc467a5..b7d9290 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
);
public $delay = 3; // amount of time in $timeunit
- public $delayManual = 8; // amount of time in $timeunit for manual mode
+ 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
// callback fonction. Is called with these 4 parameters
@@ -18,23 +18,32 @@ class rdc_wc_eclairage extends hook
{
global $indexDevices;
//var_dump($value);
+ logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
switch($property)
{
case "state_l2":
- logger(DEBUG, _("CASE: state_l2"), __FILE__ . ":" . __LINE__);
+ logger(DEBUG, "CASE: state_l2", __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
- setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
- $device->method = MANUAL;
+ if ($device->method == AUTO)
+ {
+ setDelay($device, $this->delay, $this->timeUnit, "state_l2", "OFF", true);
+ }else
+ {
+ $device->method = MANUAL;
+ setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
+ }
}elseif ($value == "OFF")
{
- deleteEvent(searchEvent($device, "state_l2", "OFF"));
+ removeEvent($device, "state_l2", "OFF");
+ $device->method = null;
}
break;
case "occupancy":
- logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
+ logger(DEBUG, "CASE: occupancy", __FILE__ . ":" . __LINE__);
if ($value == true)
{
+ $device->method = AUTO;
$this->send("ON");
}
}
@@ -48,11 +57,6 @@ class rdc_wc_eclairage extends hook
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);
}
}
diff --git a/moha.php b/moha.php
index 0ca1fc1..d56ab19 100644
--- a/moha.php
+++ b/moha.php
@@ -132,7 +132,7 @@ function listHooks($dir, &$hookList)
function endMoha()
{
- global $testMode, $devices, $topics, $nSubscribed ,$client, $logFh, $connected, $dataPath;
+ global $testMode, $devices, $topics, $events, $nSubscribed ,$client, $logFh, $connected, $dataPath;
$x = 0;
logger(WARNING, _("moha is ending"), __FILE__ . ":" . __LINE__);
@@ -144,6 +144,10 @@ function endMoha()
{
logger(ERROR, _("Can not store topics db" ), __FILE__ . ":" . __LINE__);
}
+ if (storeDB($events, $dataPath . "events.db") === false)
+ {
+ logger(ERROR, _("Can not store events db" ), __FILE__ . ":" . __LINE__);
+ }
if($testMode) file_put_contents($dataPath . "moha.devices", var_export($devices, true));
if ($connected)
{
@@ -177,10 +181,10 @@ if (is_readable($configDir . "/devices_constants.php"))
{
include $configDir . "/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);
+ logger(INFO, sprintf(_("%s/devices_constants.php found, so it has been included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
}else
{
- logger(WARNING, sprintf(_("%s/devices_constants.define not found, so not included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
+ logger(WARNING, sprintf(_("%s/devices_constants.php not found, so not included :-)"), $configDir), __FILE__ . ":" . __LINE__, false);
}
logger(DEBUG, _("requiring php modules"), __FILE__ . ":" . __LINE__);
@@ -224,24 +228,42 @@ if (!empty($hooksList)) // some hooks to include if hooklist is not empty
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)
+ if (($db = loadDB($dataPath . "topics.db")) === false)
{
logger(ERROR, _("Can not load topics db"), __FILE__ . ":" . __LINE__);
+ }else
+ {
+ $topics = $db;
}
+
}
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)
+ if (($db = loadDB($dataPath . "devices.db")) === false)
{
logger(ERROR, _("Can not load devices db"), __FILE__ . ":" . __LINE__);
}else
{
+ $devices = $db;
mkIndexes();
}
}
+logger(DEBUG, _("Loading stored events datas from ") . $dataPath . "events.db", __FILE__ . ":" . __LINE__);
+if (file_exists($dataPath . "events.db"))
+{
+ if (($db = loadDB($dataPath . "events.db")) === false)
+ {
+ logger(ERROR, _("Can not load events db"), __FILE__ . ":" . __LINE__);
+ }else
+ {
+ $events = $db;
+ }
+
+}
+
// Program start
logger(DEBUG, _("Program start"), __FILE__ . ":" . __LINE__, false);
$client = new Mosquitto\Client();
diff --git a/topics_callbacks/zigbee2mqtt.php b/topics_callbacks/zigbee2mqtt.php
index 4a00781..4cdf4cb 100644
--- a/topics_callbacks/zigbee2mqtt.php
+++ b/topics_callbacks/zigbee2mqtt.php
@@ -54,9 +54,9 @@ function zigbee2mqttCallback($topic, $message)
$fnTreeEnd = end($fnTree);
switch($fnTreeEnd)
{
- case "l1":
+ /*case "l1":
case "l2":
- $fnTreeEnd = "state_" . $fnTreeEnd;
+ $fnTreeEnd = "state_" . $fnTreeEnd;*/
case "set":
case "mode":
case "contact":
@@ -77,6 +77,7 @@ function zigbee2mqttCallback($topic, $message)
logger(ERROR, sprintf(_("device with friendlyname %s not found"), $fn), __FILE__ . ":" . __LINE__);
}else
{
+ logger(DEBUG, "PayloadArray = " . print_r($payloadArray,true), __FILE__ . ":" . __LINE__);
changeDevice($topicName, $fn, $indexFriendlyNames[$topicName][$fn], $payloadArray);
}
diff --git a/utils.php b/utils.php
index 397e379..f7c637a 100644
--- a/utils.php
+++ b/utils.php
@@ -18,6 +18,12 @@ function bool2string($var)
}
}
+function validateDate($date, $format = 'Y-m-d H:i:s')
+{
+ $d = DateTime::createFromFormat($format, $date);
+ return $d && $d->format($format) == $date;
+}
+
function now()
{
$now = new datetime();
@@ -75,7 +81,10 @@ function getDevice($topic, $fn)
function getValue($ieeeAddress, $property)
{
global $indexDevices;
- return $indexDevices[$ieeeAddress]->properties[$property]["value"];
+ $r = $indexDevices[$ieeeAddress]->properties[$property]["value"];
+ logger(DEBUG, "device: " . $indexDevices[$ieeeAddress]->friendlyName . " value: " . $r, __FILE__ . ":" . __LINE__ );
+
+ return $r;
}
function setValue($fn, $property, $value)
diff --git a/webserver/cmd_functions.php b/webserver/cmd_functions.php
index c7064df..e0b42d4 100644
--- a/webserver/cmd_functions.php
+++ b/webserver/cmd_functions.php
@@ -21,42 +21,54 @@ function webDashboard($socket, $n="Général")
$propertyObject = $device->properties[$property];
$value = $propertyObject["value"];
logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)));
- $response .= $device->friendlyName . aliases($device->friendlyName, $property) . " => " . bool2string(_($value)) . EOL;
+ $response .= $device->friendlyName . aliases($device->friendlyName, $property) . ' => ';
if (array_key_exists("access", $propertyObject))
{
logger(DEBUG, _("Access = ") . $propertyObject["access"], __FILE__ . ":" . __LINE__);
if(($propertyObject["access"] & 2))
{
logger(DEBUG, _("Write Access OK ") . ($propertyObject["access"] & 2), __FILE__ . ":" . __LINE__);
- $response .= " " . displayChoice($device, $property);
+ $response .= " " . displayChoice($device, $property, $value);
}
if(($propertyObject["access"] & 4))
{
logger(DEBUG, _("can get value") . ($propertyObject["access"] & 4), __FILE__ . ":" . __LINE__);
- $response .= ' friendlyName . "/" . $propertyObject["name"] . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "','" . $device->friendlyName . "','" . $propertyObject["name"] . "')\">";
+ $response .= 'friendlyName . "/" . $propertyObject["name"] . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "','" . $device->friendlyName . "','" . $propertyObject["name"] . "')\">";
}
- }
$response .= EOLH;
+ }else
+ {
+ $response .= bool2string(_($value));
+ if(array_key_exists("unit", $propertyObject))
+ {
+ $response .= $propertyObject["unit"];
+ logger(DEBUG, _("unit = ") . $unit, __FILE__ . ":" . __LINE__);
+ }
+ $response .= EOLH;
+ }
+
}else
{
- logger(ERROR, _("Property do not exist"), __FILE__ . ":" . __LINE__);
+ logger(ERROR, _("Property does not exists"), __FILE__ . ":" . __LINE__);
}
}else
{
- logger(ERROR, _("Device do not exist"), __FILE__ . ":" . __LINE__);
+ logger(ERROR, _("Device does not exists"), __FILE__ . ":" . __LINE__);
}
}
}else
{
+ logger(ERROR, _("Dashboard does not exists"), __FILE__ . ":" . __LINE__);
$response = _("dashboard not found");
}
- htmlSend($socket, $response);
+ htmlSend($socket, $response, '');
}
-function displayChoice($device, $propertyName)
+function displayChoice($device, $propertyName, $value)
{
logger(INFO, _("function displayChoice"), __FILE__ . ":" . __LINE__);
$propertyObject = $device->properties[$propertyName];
+ $unit = '';
if(array_key_exists("unit", $propertyObject))
{
@@ -68,43 +80,54 @@ function displayChoice($device, $propertyName)
{
case "binary":
logger(DEBUG, _("type is binary"), __FILE__ . ":" . __LINE__);
+ $formHTML = bool2string($value);
$choice["on"] = $propertyObject["value_on"];
$choice["off"] = $propertyObject["value_off"];
if (array_key_exists("toggle", $propertyObject))
{
$choice["toggle"] = $propertyObject["toggle"];
}
- $formHTML = mkHTML($device, $propertyName, $choice);
+ $formHTML .= mkHTML($device, $propertyName, $choice);
break;
case "numeric":
- logger(DEBUG, _("type is numeric"), __FILE__ . ":" . __LINE__);
- $formHTML = 'friendlyName . aliases($device->friendlyName, $property) . ' => ';
+ $formHTML = 'friendlyName . "/"
+ . $propertyObject["name"] ."/value" . '"'
+ . ' min="' . $propertyObject["value_min"] . '"'
+ . ' max="' . $propertyObject["value_max"] . '"'
+ . $step
+ . ' value="' . $value . '">' . $unit . EOL;
+ $formHTML .= 'friendlyName . "/" . $propertyObject["name"] . '"';
$formHTML .= ' name="' . $propertyObject["name"] . '"';
$formHTML .= ' min="' . $propertyObject["value_min"] . '"';
$formHTML .= ' max="' . $propertyObject["value_max"] . '"';
$formHTML .= ' value="' . $propertyObject["value"] . '"';
-
- if (array_key_exists("value_step", $propertyObject))
- {
- $formHTML .= ' step="' . $propertyObject["value_step"] . '"';
- }
- $formHTML .= " onchange=\"setPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', this.value, '" . $propertyObject["name"] . "')\">";
-
+ $formHTML .= $step;
+ $formHTML .= " oninput=\"setPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', this.value, '" . $propertyObject["name"] . "')\">";
break;
case "enum":
logger(DEBUG, _("type is enum"), __FILE__ . ":" . __LINE__);
+ $formHTML = bool2string($value);
$choice = $propertyObject["values"];
- $formHTML = mkHTML($device, $propertyName, $choice);
+ $formHTML .= mkHTML($device, $propertyName, $choice);
break;
+ default:
+ logger(DEBUG, "type of property not recognized:" . $propertyObject["type"] , __FILE__ . ":" . __LINE__);
}
return $formHTML;
}
function mkHTML($device, $propertyName, $choice)
{
- global $listenPort, $httpServerIp;
$html = "";
- logger(DEBUG, _("function mkHTML"), __FILE__ . ":" . __LINE__);
+ logger(DEBUG, "function mkHTML", __FILE__ . ":" . __LINE__);
foreach ($choice as $key => $value)
{
$html .= 'friendlyName . "/" . $propertyName . "/" . $key . '" value="' . $value . "\" onmouseup=\"setPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', '" . $value . "', '" . $propertyName . "')\">";
@@ -205,13 +228,14 @@ function webBrowse($socket, $argList, $page="/browse")
function displayProperty($device, $key, $value, $response)
{
+ $tab="";
$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);
+ logger(DEBUG, _("Write Access OK: ") . ($value["access"] & 2) . "value:" . $value["value"], __FILE__ . ":" . __LINE__);
+ $response .= displayChoice($device, $key, $value["value"]);
}
if(($value["access"] & 4))
{
@@ -276,8 +300,11 @@ function webGet($argList)
$response = sprintf(_('"%s" or "%s" does not exists'), $argList["topic"], $argList["fn"]);
}else
{
+ logger(DEBUG, _("Getting "), __FILE__ . ":" . __LINE__ );
$property = $argList["property"];
- $response = "GET: " . bool2string($device->$property["value"]);
+ $response = "Sending GET command for: " . $argList["topic"] . $argList["fn"];
+ $payload = array($argList["property"] => "");
+ publish($argList["topic"] . "/" . $argList["fn"], $payload, "get");
}
}
return $response;
@@ -301,7 +328,7 @@ function webSet($argList)
{
$response = "setting property " . $argList["property"] . " of " . $argList["fn"] . " to value: " . $argList["value"];
$payload = array($argList["property"] => $argList["value"]);
- publish(Z2M . "/" . $argList["fn"], $payload);
+ publish($argList["topic"] . "/" . $argList["fn"], $payload);
//removeEvent($indexFriendlyName($argList["fn"]), $argList["property"], "OFF");
}
return $response;
diff --git a/webserver/display_stats.php b/webserver/display_stats.php
new file mode 100644
index 0000000..17bb62c
--- /dev/null
+++ b/webserver/display_stats.php
@@ -0,0 +1,125 @@
+device] . "' AND property='" . $$argList["property"] . "' AND '" . $argList["startDate"] . ">= date AND '" . $argList["finalDate"] . "' <= date";
+ if(!$this->result = $this->query($query))
+ {
+ logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__);
+ }
+ $datas = $this->result->fetch_all(MYSQLI_ASSOC);
+ diagramDisplay($datas);
+ }else
+ {
+ htmlSend($socket, _("Dates are not of the form: YYYY-MM-DD"));
+ }
+
+}
+
+/************************************************************/
+/* $datas => array of datas to display {date,value} */
+/* $ndata => n datas to display */
+/* $min => minimal value to display */
+/* $max => maximal value to dispaly */
+/************************************************************/
+
+function diagramDisplay($datas)
+{
+ global $months;
+
+ $ndata = count($datas);
+ $min = min($datas);
+ $max = max($datas);
+ //Type mime de l'image
+ //Chemin vers le police à utiliser
+ $font_file = '/usr/share/fonts/TTF/dejavu/DejaVuSans.ttf';
+ //Adapter la largeur de l'image avec le nombre de donnée
+ $largeur = $i * 50 + 90;
+ $hauteur = 400;
+ //Hauteur de l'abscisse par rapport au bas de l'image
+ $absis = 80;
+ //Création de l'image
+ $courbe = imagecreatetruecolor($largeur, $hauteur);
+ //Allouer les couleurs à utiliser
+ $bleu = imagecolorallocate($courbe, 0, 0, 255);
+ $ligne = imagecolorallocate($courbe, 220, 220, 220);
+ $fond = imagecolorallocate($courbe, 250, 250, 250);
+ $noir = imagecolorallocate($courbe, 0, 0, 0);
+ $rouge = imagecolorallocate($courbe, 255, 0, 0);
+ //Colorier le fond
+ imagefilledrectangle($courbe,0 , 0, $largeur, $hauteur, $fond);
+ //Tracer l'axe des abscisses
+ imageline($courbe, 50, $hauteur - $absis, $largeur - 10, $hauteur - $absis, $noir);
+ //Tracer l'axe des ordonnées
+ imageline($courbe, 50, $hauteur - $absis, 50, 20, $noir);
+ //Decaler 10px vers le haut le si le minimum est différent de 0
+ if($min != 0)
+ {
+ $absis += 10;
+ $a = 10;
+ }
+ //Nombres des grides verticales
+ $nbOrdonne = 10;
+ //Calcul de l'echelle des abscisses
+ $echelleX = ($largeur - 100) / $i;
+ //Calcul de l'echelle des ordonnees
+ $echelleY = ($hauteur - $absis - 20) / $nbOrdonne;
+ $i = $min;
+ //Calcul des ordonnees des grides
+ $py = ($max - $min) / $nbOrdonne;
+ $pasY = $absis;
+ while( $pasY < ($hauteur - 19))
+ {
+ //Affiche la valeur de l'ordonnee
+ imagestring($courbe, 2, 10 , $hauteur - $pasY - 6, round($i), $noir);
+ //Trace la gride
+ imageline($courbe, 50, $hauteur - $pasY, $largeur - 20, $hauteur - $pasY, $ligne);
+ //Decaller vers le haut pour la prochaine gride
+ $pasY += $echelleY;
+ //Valeur de l'ordonnee suivante
+ $i += $py;
+ }
+
+ $j = -1;
+ $pasX = 90;
+ //Parcourir le tableau pour le traçage de la diagramme
+ foreach ($datas as $mois => $quantite)
+ {
+ //calculer la hateur du point par rapport à sa valeur
+ $y = ($hauteur) - (($quantite - $min) * ($echelleY / $py)) - $absis;
+ //dessiner le point
+ imagefilledellipse($courbe, $pasX, $y, 6, 6, $rouge);
+ //Afficher le mois en français avec une inclinaison de 315°
+ imagefttext($courbe, 10, 315, $pasX, $hauteur - $absis + 20, $noir, $font_file, $months[$mois-1]);
+ //Tacer une ligne veticale de l'axe de l'abscisse vers le point
+ imageline($courbe, $pasX, $hauteur - $absis + $a, $pasX, $y, $noir);
+ if($j!==-1)
+ {
+ //liée le point actuel avec la précédente
+ imageline($courbe, ($pasX - $echelleX), $yprev, $pasX, $y, $noir);
+ }
+ //Afficher la valeur au dessus du point
+ imagestring($courbe, 2, $pasX - 15, $y - 14, $quantite, $bleu);
+ $j = $quantite;
+ //enregister la hauteur du point actuel pour la liaison avec la suivante
+ $yprev = $y;
+ //Decaller l'abscisse suivante par rapport à son echelle
+ $pasX +=$echelleX;
+ }
+ //Envoyer le flux de l'image
+ imagepng($courbe);
+ //Desallouer le memoire utiliser par l'image
+ imagedestroy($courbe);
+}
+?>
diff --git a/webserver/javascript.php b/webserver/javascript.php
index 64c93f8..3c131d4 100644
--- a/webserver/javascript.php
+++ b/webserver/javascript.php
@@ -6,6 +6,7 @@ return '