diff --git a/apiserver/apiserver.php b/apiserver/apiserver.php
index 39e89d0..e6c6787 100644
--- a/apiserver/apiserver.php
+++ b/apiserver/apiserver.php
@@ -47,8 +47,11 @@ function htmlSend($socket, $text, $meta="")
function apiServer($read)
{
global $topics, $indexDevices, $devices;
+
+ logger(DEBUG, "Function apiServer", __FILE__ . ":" . __LINE__);
$array = array();
$argList =array();
+
//logger(DEBUG, _("askWebserver function starting"), __FILE__ . ":" . __LINE__);
if ( stream_select( $read, $array, $array, 0 ))
{
@@ -88,50 +91,63 @@ function apiServer($read)
switch($command)
{
case "dashboard":
- webDashboard($spawn, $argList["dashboard"]);
+ apiDashboard($spawn, $argList["dashboard"]);
break;
case "browse":
logger(DEBUG, _("Browsing"), __FILE__ . ":" . __LINE__);
- webBrowse($spawn, $argList);
+ apiBrowse($spawn, $argList);
//return true;
break;
case "get":
logger(DEBUG, _("GET reached"), __FILE__ . ":" . __LINE__);
- htmlSend($spawn, webGet($argList));
+ htmlSend($spawn, apiGet($argList));
break;
case "set":
logger(DEBUG, _("SET reached"), __FILE__ . ":" . __LINE__);
- htmlSend($spawn, webSet($argList));
+ htmlSend($spawn, apiSet($argList));
break;
case "dump":
case "print":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
- htmlSend($spawn, webPrint($argList, $command));
+ htmlSend($spawn, apiPrint($argList, $command));
break;
case "notify":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
- htmlSend($spawn, webNotify($argList));
+ htmlSend($spawn, apiNotify($argList));
logger(DEBUG, print_r($monitored, true), __FILE__ . ":" . __LINE__);
break;
case "type":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
- //htmlSend($spawn, webDisplayByType($argList));
+ //htmlSend($spawn, apiDisplayByType($argList));
/*case "stats":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
displayStats($spawn, $argList);*/
+ break;
+ case "verbose":
+ logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
+ htmlSend($spawn, apiVerbose($argList));
+ break;
+ case "friendlyname":
+ logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
+ htmlSend($spawn, getFn($argList));
+ break;
+ case "property":
+ logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
+ htmlSend($spawn, PropertiesDashboard($argList));
+ break;
default:
- if (is_numeric(array_key_first($argList)))
- {
- webDashboard($spawn, $argList[0]);
- }else
- {
- logger(DEBUG, $command . _(" so default action"), __FILE__ . ":" . __LINE__);
- if (file_exists("php://temp/". $command))
+ if (is_numeric(array_key_first($argList)))
{
- logger(DEBUG, $command . _(" is a file"), __FILE__ . ":" . __LINE__);
- htmlSend($spawn, file_get_contents("php://temp/". $command), 'Content-Type: image/png');
+ apiDashboard($spawn, $argList[0]);
+ }else
+ {
+ logger(DEBUG, $command . _(" so default action"), __FILE__ . ":" . __LINE__);
+ if (file_exists("php://temp/". $command))
+ {
+ logger(DEBUG, $command . _(" is a file"), __FILE__ . ":" . __LINE__);
+ htmlSend($spawn, file_get_contents("php://temp/". $command), 'Content-Type: image/png');
+ }
}
- }
}
if (array_key_exists("page", $argList))
@@ -141,11 +157,11 @@ function apiServer($read)
}
}else
{
- webDashboard($spawn);
+ apiDashboard($spawn);
}
}else
{
- webDashboard($spawn);
+ apiDashboard($spawn);
}
}
}
diff --git a/apiserver/cmd_functions.php b/apiserver/cmd_functions.php
index 433a371..109f583 100644
--- a/apiserver/cmd_functions.php
+++ b/apiserver/cmd_functions.php
@@ -1,11 +1,11 @@
properties[$property];
$value = $propertyObject["value"];
- logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)));
+ logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)), __FILE__ . ":" . __LINE__);
$response .= $device->friendlyName . aliases($device->friendlyName, $property) . ' => ';
if (array_key_exists("access", $propertyObject))
{
@@ -130,7 +130,7 @@ function displayChoice($device, $propertyName, $value)
function mkHTML($device, $propertyName, $choice)
{
$html = "";
- logger(DEBUG, "function mkHTML", __FILE__ . ":" . __LINE__);
+ logger(INFO, "function mkHTML", __FILE__ . ":" . __LINE__);
foreach ($choice as $key => $value)
{
$html .= 'friendlyName . "/" . $propertyName . "/" . strtolower($value) . '" value="' . $value . "\" onmouseup=\"setPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', '" . $value . "', '" . $propertyName . "')\">";
@@ -138,10 +138,10 @@ function mkHTML($device, $propertyName, $choice)
return $html;
}
-function webBrowse($socket, $argList, $page="/browse")
+function apiBrowse($socket, $argList, $page="/browse")
{
global $topics, $devices, $listenPort,$indexDevices;
- logger(DEBUG, _("Generic response to choose device and property"), __FILE__ . ":" . __LINE__);
+ logger(INFO, _("Generic response to choose device and property"), __FILE__ . ":" . __LINE__);
//$response = "
" . _("unknown command") . "";
$response = "";
$flag = false;
@@ -220,11 +220,11 @@ function webBrowse($socket, $argList, $page="/browse")
}
}else
{
- $response = webListTopics();
+ $response = apiListTopics();
}
}else
{
- $response = webListTopics();
+ $response = apiListTopics();
}
htmlSend($socket, $response);
}
@@ -279,10 +279,10 @@ function iterateProperty($device, $property, $value, &$response, $tab="")
}
}
-function webListTopics()
+function apiListTopics()
{
global $topics;
- logger(DEBUG, _("webListTopics function"));
+ logger(INFO, _("apiListTopics function"), __FILE__ . ":" . __LINE__);
$response = "";
foreach ($topics as $name => $topic)
{
@@ -291,7 +291,7 @@ function webListTopics()
return $response;
}
-function webGet($argList)
+function apiGet($argList)
{
if(!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList))
{
@@ -313,7 +313,7 @@ function webGet($argList)
return $response;
}
-function webSet($argList)
+function apiSet($argList)
{
global $indexFriendlyName;
if(!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList) or !array_key_exists("value", $argList))
@@ -331,13 +331,13 @@ function webSet($argList)
{
$response = "setting property " . $argList["property"] . " of " . $argList["fn"] . " to value: " . $argList["value"];
$payload = array($argList["property"] => $argList["value"]);
- publish($argList["topic"] . "/" . $argList["fn"], $payload);
+ publish($argList["topic"] . "/" . $argList["fn"], $payload, "set");
//removeEvent($indexFriendlyName($argList["fn"]), $argList["property"], "OFF");
}
return $response;
}
-function webPrint($argList, $command)
+function apiPrint($argList, $command)
{
global $GLOBALS, $topics;
if (array_key_exists($argList["object"], $GLOBALS))
@@ -386,7 +386,7 @@ function webPrint($argList, $command)
return $response;
}
-function webNotify($argList)
+function apiNotify($argList)
{
if (!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList) or !array_key_exists("condition", $argList) or !array_key_exists("value", $argList))
{
@@ -398,8 +398,118 @@ function webNotify($argList)
}
return $response;
}
+
+function apiVerbose($argList)
+{
+ global $logLevel, $logLevels;
+ logger(INFO, _("apiVerbose function"), __FILE__ . ":" . __LINE__);
+ $response = "";
+ //print_r($argList);
+ foreach ($logLevels as $value => $level)
+ {
+ //print $level . " => " . $value . " ==>" . strtoupper(trim($argList["cmd"])) . EOL;
+ if (strtoupper(trim($argList["verbose"])) == $level)
+ {
+ print "change of " . $level . EOL;
+ $logLevel ^= $value;
+ }
+ if ($logLevel & $value)
+ {
+ $response .= $level . _(" is active") . EOLH;
+ }else
+ {
+ $response .= $level . _(" is inactive") . EOLH;
+ }
+ }
+ return $response;
+}
+
+function getFn($argList)
+{
+ global $indexDevices;
+ $jsonArray = array();
+ logger(INFO, _("getFn function"), __FILE__ . ":" . __LINE__);
+
+
+ if (array_key_exists("ieeeAddress", $argList))
+ {
+ logger(DEBUG, "ieeeAddress = " . $argList["ieeeAddress"], __FILE__ . ":" . __LINE__);
+ if (array_key_exists($argList["ieeeAddress"], $indexDevices))
+ {
+ logger(DEBUG, "FriendlyName is " . $indexDevices[$argList["ieeeAddress"]]->friendlyName, __FILE__ . ":" . __LINE__);
+ $response = '["' . $argList["ieeeAddress"] . '":"' . $indexDevices[$argList["ieeeAddress"]]->friendlyName . '"]';
+ }
+ }else
+ {
+ $flag = false;
+ //$response = "{";
+ foreach($indexDevices as $ieeeAddress => $device)
+ {
+ /*if ($flag == false)
+ {
+ $flag = true;
+ }else
+ {
+ $response .= ', ';
+ }
+ */
+ //$response .= '"' . $ieeeAddress . '" : "' . $indexDevices[$ieeeAddress]->friendlyName . '"';
+ $jsonArray[$ieeeAddress] = $indexDevices[$ieeeAddress]->friendlyName;
+ array_multisort($jsonArray);
+ }
+ $response = json_encode($jsonArray, JSON_UNESCAPED_SLASHES);
+ print $response;
+ //print_r(json_decode($response));
+ }
+ logger(DEBUG, "response = " . $response, __FILE__ . ":" . __LINE__);
+ return $response;
+}
+
+function PropertiesDashboard($argList)
+{
+ global $indexProperties;
+ require_once "apiserver/javascript.php";
+ logger(INFO, _("propertiesDashboard function"), __FILE__ . ":" . __LINE__);
+ $response = insertJavascript();
+ $property = $argList["property"];
+ foreach ($indexProperties[$property] as $device)
+ {
+ $propertyObject = $device->properties[$property];
+ $value = $propertyObject["value"];
+ logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)), __FILE__ . ":" . __LINE__);
+ $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, $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"] . "')\">";
+ }else
+ {
+ $response .= $value;
+ }
+ $response .= EOLH;
+ }else
+ {
+ $response .= bool2string(_($value));
+ if(array_key_exists("unit", $propertyObject))
+ {
+ $response .= $propertyObject["unit"];
+ logger(DEBUG, _("unit = ") . $unit, __FILE__ . ":" . __LINE__);
+ }
+ $response .= EOLH;
+ }
+ }
+ return "json=" . $response;
+}
/*
-function webDisplayByType($argList)
+function apiDisplayByType($argList)
{
global $indexTypes, $config;
require_once $config . "porpertiesbytype.php";
diff --git a/class/hook_class.php b/class/hook_class.php
index 82ba8c8..9838a70 100644
--- a/class/hook_class.php
+++ b/class/hook_class.php
@@ -24,28 +24,35 @@ class hook
function installHooks(&$indexDevices)
{
- global $devices;
+ global $devices, $devicesRequest;
+ static $requestflag = 0;
$result = true;
// assigne the function to the sensors devices
if ($this->active === true)
{
foreach ($this->devicelist as $ieeeAddress => $property)
{
- if (array_key_exists($ieeeAddress, $devices))
+ if (array_key_exists($ieeeAddress, $indexDevices))
{
logger(DEBUG, _("Device: ") . $ieeeAddress, __FILE__ . ":" . __LINE__);
- if ($this->propertyInitialized[$ieeeAddress][$property] === false)
+ if (!array_key_exists($this->hookName, $indexDevices[$ieeeAddress]->properties[$property]["functions"]))
{
- logger(DEBUG, _("Trying to store callback"), __FILE__ . ":" . __LINE__);
- if (array_key_exists("functions", $indexDevices[$ieeeAddress]->properties[$property]))
+ if (array_key_exists($property, $indexDevices[$ieeeAddress]->properties))
{
- $indexDevices[$ieeeAddress]->properties[$property]["functions"][$this->hookName] = array($this,"callback");
- $this->propertyInitialized[$ieeeAddress][$property] = true;
- logger(DEBUG, sprintf(_("Property '%s' of %s is initialized with callback"), $property, $indexDevices[$ieeeAddress]->friendlyName), __FILE__ . ":" . __LINE__);
+ logger(DEBUG, _("Trying to store callback"), __FILE__ . ":" . __LINE__);
+ if (array_key_exists("functions", $indexDevices[$ieeeAddress]->properties[$property]))
+ {
+ $indexDevices[$ieeeAddress]->properties[$property]["functions"][$this->hookName] = array($this,"callback");
+ logger(DEBUG, sprintf(_("Property '%s' of %s is initialized with callback"), $property, $indexDevices[$ieeeAddress]->friendlyName), __FILE__ . ":" . __LINE__);
+ }else
+ {
+ logger(WARNING, sprintf(_("Hook %s can not initialize Property '%s' of device %s"), $this->hookName, $property, $ieeeAddress), __FILE__ . ":" . __LINE__);
+ $result = false;
+ }
}else
{
- logger(WARNING, sprintf(_("Hook %s can not initialize Property '%s' of device %s"), $this->hookName, $property, $ieeeAddress), __FILE__ . ":" . __LINE__);
+ logger(WARNING, sprintf(_("Hook %s can not initialize Property '%s' of device %s : property does not exists"), $this->hookName, $property, $indexDevices[$ieeeAddress]->friendlyName), __FILE__ . ":" . __LINE__);
$result = false;
}
}else
@@ -55,6 +62,16 @@ class hook
}else
{
logger(ERROR, $ieeeAddress . (" does not exists"), __FILE__ . ":" . __LINE__);
+ if ($devicesRequest === false)
+ {
+ publish("zigbee2mqtt", array("bridge/devices" => ""), "get");
+ $devicesRequest = true;
+ }elseif ($requestflag++ > 30)
+ {
+ $requestflag = 0;
+ }
+
+ $result = false;
mkIndexes();
}
diff --git a/config/dashboard_conf.php b/config/dashboard_conf.php
index 553ebe4..e437a3d 100644
--- a/config/dashboard_conf.php
+++ b/config/dashboard_conf.php
@@ -15,7 +15,8 @@
array(METEO, "rainin"),
array(METEO, "barominmb"),
array(METEO, "UV"),
- array(METEO, "solarradiation")
+ array(METEO, "solarradiation"),
+ array(RDC_STORE, "position")
);
$dashboards["etage"] = array(
array(ETAGE_SALON_RADIATEUR,"current_heating_setpoint"),
diff --git a/constants.php b/constants.php
index 970af3d..eae6b53 100644
--- a/constants.php
+++ b/constants.php
@@ -27,4 +27,5 @@ foreach ($logLevels as $key => $string)
$logLevels[6] = "NOTICE & WARNING";
define( "ALL", DEBUG | INFO | NOTICE | WARNING | ERROR | ALERT);
+define("NOTIF_DEFAULT_DEST", "daniel");
?>
diff --git a/db_functions.php b/db_functions.php
index 7794e18..3a85bf3 100644
--- a/db_functions.php
+++ b/db_functions.php
@@ -9,7 +9,7 @@ function storeDB($db, $filepath)
$data = serialize($db);
if (file_put_contents($filepath, $data) === false)
{
- logger(DEBUG,_("Failed storing database ") . $filepath , __FILE__ . ":" . __LINE__);
+ logger(ALERT,_("Failed storing database ") . $filepath , __FILE__ . ":" . __LINE__);
return false;
}else
{
@@ -23,20 +23,24 @@ function loadDB($filepath)
$data = file_get_contents($filepath);
if ($data === false)
{
- logger(DEBUG,_("Failed loading database ") . $filepath , __FILE__ . ":" . __LINE__);
+ logger(ALERT,_("Failed loading database ") . $filepath , __FILE__ . ":" . __LINE__);
return false;
}
- $db = unserialize($data);
+ if (($db = unserialize($data)) === false)
+ {
+ logger(ALERT,_("Failed unserializing database ") . $filepath , __FILE__ . ":" . __LINE__);
+ }
return $db;
}
function mkDevicesDB($topic, $json, $group=false)
{
global $devices, $listProperties, $listPropertiesKeys, $indexDevices, $dbInit, $logFh, $hooks, $indexFriendlyNames;
- if (!isset($devices[$topic]))
+ if (!array_key_exists($topic, $devices))
{
$devices[$topic]= array();
}
+ //fwrite($logFh, var_export($json, true));
//print_r($json);
foreach ($json as $jsonDevice)
{
@@ -57,7 +61,7 @@ function addDevice($topic, $fn, $jsonDevice, $group=false )
global $devices, $listProperties, $listPropertiesKeys, $hooks, $indexDevices, $indexFriendlyNames;
$fnTree = explode("/", $fn);
$device = & $devices[$topic];
- print_r($jsonDevice);
+ //print_r($jsonDevice);
foreach($fnTree as $fnPart)
{
if (!array_key_exists($fnPart, $device))
@@ -108,13 +112,13 @@ function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
{
//foreach($listPropertiesKeys as $propertyKey)
//{
- logger(DEBUG, _("searching for property"), __FILE__ . ":" . __LINE__ );
+ //logger(DEBUG, _("searching for property"), __FILE__ . ":" . __LINE__ );
//if (is_object($inputObject))
//{
//print_r($inputObject);
if (array_key_exists("property", $inputObject))
{
- logger(DEBUG, _("property Key exists filling properties"), __FILE__ . ":" . __LINE__ );
+ //logger(DEBUG, _("property Key exists filling properties"), __FILE__ . ":" . __LINE__ );
$string = $inputObject["property"];
if (!array_key_exists($string, $device->properties))
{
@@ -136,11 +140,14 @@ function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
{
$device->type = $inputObject["type"];
}
- /*foreach($inputObject as $key => $value)
+ foreach($inputObject as $key => $value)
{
- logger(DEBUG, sprintf(_("key = %s"), $key), __FILE__ . ":" . __LINE__ );
- searchPropertyKey($fn, $device, $value, $listPropertiesKeys);
- }*/
+ //logger(DEBUG, sprintf(_("key = %s"), $key), __FILE__ . ":" . __LINE__ );
+ if (is_array($value))
+ {
+ searchPropertyKey($fn, $device, $value, $listPropertiesKeys);
+ }
+ }
}
//print_r($device);
//}
@@ -247,12 +254,16 @@ function getDevicesValues($topic)
if ($value["access"] & 4)
{
$device->payload[$property] = "";
+ $flag = true;
break;
}
}
}
//logger(DEBUG, print_r($device->payload, true), __FILE__ . ":" . __LINE__ );
- $device->get();
+ if ($flag === true)
+ {
+ $device->get();
+ }
}else
{
logger(DEBUG, _("no properties to get for device: " . $device->friendlyName ), __FILE__ . ":" . __LINE__ );
@@ -302,24 +313,32 @@ function mkIndexes()
function iterate2device(&$object)
{
- global $indexDevices, $indexFriendlyNames, $indexTypes;
+ global $indexDevices, $indexFriendlyNames, $indexTypes, $indexProperties;
foreach ($object as $key => &$device)
{
if (is_a($device, "device"))
{
- $object = &$device;
+ //$object = &$device;
//print("=============" . $device->friendlyName);
//if (!array_key_exists($object->ieeeAddress, $indexDevices))
//{
//print("============>");
- $indexDevices[$object->ieeeAddress] = &$object;
- $indexFriendlyNames[$object->friendlyName] = &$object;
- if (property_exists($object, "type"))
+ $indexDevices[$device->ieeeAddress] = &$device;
+ $indexFriendlyNames[$device->friendlyName] = &$device;
+ if (property_exists($device, "type"))
{
- $indexTypes[$object->type][] = &$object;
+ $indexTypes[$device->type][] = &$object;
+ }
+ $properties = array_keys($device->properties);
+ foreach($properties as $property)
+ {
+ $indexProperties[$property][$device->ieeeAddress] = &$device;
}
//}
+ //return true;
+ }elseif (empty($device))
+ {
return true;
}else
{
diff --git a/events.php b/events.php
index ea0b119..39409f6 100644
--- a/events.php
+++ b/events.php
@@ -8,7 +8,7 @@ function checkEvents()
{
global $logLevel, $events;
$oldLevel = $logLevel;
- $logLevel = DEBUG;
+ //$logLevel = DEBUG;
$exception = false;
if ($events === null)
{
@@ -68,10 +68,12 @@ function checkEvents()
}
}
//print_r($events);
- $logLevel = $oldLevel;
+ //$logLevel = $oldLevel;
}
-function setOneshotEvent(&$deviceObject, $datetime, $property, $value, $replace=false, $method=null)
+// datetime format : "yyyy-mm-dd hh:mm:ss"
+
+function setOneshotEvent(device &$deviceObject, string $datetime, $property, $value, $replace=false, $method=null)
{
global $events;
$events[] = new event;
@@ -85,18 +87,20 @@ function setOneshotEvent(&$deviceObject, $datetime, $property, $value, $replace=
if ($method !==null) $events[$key]->method =$method;
}
-function setRecurrentEvent(&$deviceObject, $property, $value, $startDatetime, $stopDatetime, $hours, $minutes, $seconds, $days, $weeks, $months, $years, $method = null)
+// startDatetime and stopDatetime format : "yyyy-mm-dd hh:mm:ss"
+
+function setRecurrentEvent(device &$deviceObject, string $property, $value, string $startDatetime, string $stopDatetime, int $hours, int $minutes, int $seconds, int $days, int $weeks, int $months, int $years, int $method = null)
{
global $events;
$string = "P";
- if (!empty($years)) $string .= $days . "Y";
- if (!empty($months)) $string .= $days . "M";
+ if (!empty($years)) $string .= $years . "Y";
+ if (!empty($months)) $string .= $months . "M";
if (!empty($week)) $string .= $week . "W";
if (!empty($days)) $string .= $days . "D";
$string .= "T";
- if (!empty($hours)) $string .= $days . "H";
- if (!empty($months)) $string .= $days . "M";
- if (!empty($seconds)) $string .= $days . "S";
+ if (!empty($hours)) $string .= $hours . "H";
+ if (!empty($months)) $string .= $months . "M";
+ if (!empty($seconds)) $string .= $seconds . "S";
$event = new event;
@@ -117,7 +121,7 @@ function setRecurrentEvent(&$deviceObject, $property, $value, $startDatetime, $s
if ($method !== null) $event->method = $method;
}
-function setDelay(&$deviceObject, $delay, $unit, $property, $value, $replace=false, $method = null)
+function setDelay(device &$deviceObject, float $delay, string $unit, string $property, $value, bool $replace=false, int $method = null)
{
global $events, $logLevel;
$oldLevel = $logLevel;
@@ -160,7 +164,7 @@ function setDelay(&$deviceObject, $delay, $unit, $property, $value, $replace=fal
if ($replace)
{
$eventKey = searchEvent($deviceObject, $property, $value);
- if ($eventKey !== false) deleteEvent($events[$eventKey]);
+ if ($eventKey !== false) deleteEvent($eventKey);
}
//$dt = $datetime->format("Y-m-d\TH:i:s\Z");
$events[] = new event;
@@ -177,7 +181,7 @@ function setDelay(&$deviceObject, $delay, $unit, $property, $value, $replace=fal
$logLevel = $oldLevel;
}
-function removeEvent($deviceObject, $property , $value, $method = null)
+function removeEvent(device $deviceObject, string $property , $value, int $method = null)
{
global $events;
$eventKey = searchEvent($deviceObject, $property , $value);
@@ -188,7 +192,7 @@ function removeEvent($deviceObject, $property , $value, $method = null)
}
}
-function searchEvent($deviceObject, $property , $value)
+function searchEvent(device $deviceObject, string $property , $value)
{
global $events;
logger(DEBUG, sprintf(_("searching event for device %s, property %s and value %s"), $deviceObject->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
@@ -205,7 +209,7 @@ function searchEvent($deviceObject, $property , $value)
}
// warning delete event does not manage method of the device (IDLE, )
-function deleteEvent($eventKey)
+function deleteEvent(int $eventKey)
{
global $events;
if ($eventKey !== false)
diff --git a/hooks/notifiers/notificationfreemobile.php b/hooks/notifiers/notificationfreemobile.php
index df70608..50ddc25 100644
--- a/hooks/notifiers/notificationfreemobile.php
+++ b/hooks/notifiers/notificationfreemobile.php
@@ -6,7 +6,7 @@ class notificationFreemobile
public $active = true;
public $level;
private $dest = array(
- "32886706&pass=JTGUY6l5OG73zX", //daniel
+ "daniel" => "32886706&pass=JTGUY6l5OG73zX",
);
function __construct()
@@ -14,7 +14,7 @@ class notificationFreemobile
$this->level = ALERT | ERROR;
}
- function send($message, $destinataire=0)
+ function send($message, $destinataire=NOTIF_DEFAULT_DEST)
{
global $curlErr;
$result = false;
@@ -22,7 +22,7 @@ class notificationFreemobile
{
$ch = curl_init();
// set url
- curl_setopt($ch, CURLOPT_URL, $this->url . $this->dest["destinataire"] . "&msg=" . urlencode(trim($message)));
+ curl_setopt($ch, CURLOPT_URL, $this->url . $this->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);
diff --git a/hooks/scripts/rdc_salon_eclairage.php b/hooks/scripts/rdc_salon_eclairage.php
index 32e6bc2..4a26b56 100644
--- a/hooks/scripts/rdc_salon_eclairage.php
+++ b/hooks/scripts/rdc_salon_eclairage.php
@@ -26,8 +26,9 @@ class rdc_salon_eclairage extends hook
$lux = $indexDevices[RDC_SALON_LUMINOSITE];
$mvmt = $indexDevices[RDC_SALON_MVMT];
$mvmt2 = $indexDevices[RDC_SALON_MVMT2];
- logger (INFO, _("property => ") . $param . _("value =>") . bool2string($value), __FILE__ . ":" . __LINE__);
+ $illuminance = getValue(RDC_SALON_LUMINOSITE, "illuminance_lux");
+ logger (INFO, _("property => ") . $param . _("value =>") . bool2string($value), __FILE__ . ":" . __LINE__);
switch($param)
{
case "occupancy":
@@ -35,7 +36,6 @@ class rdc_salon_eclairage extends hook
//print_r(getValue(RDC_SALON_LUMINOSITE, "illuminance_lux"));
if ($value == ON)
{
- $illuminance = getValue(RDC_SALON_LUMINOSITE, "illuminance_lux");
logger(INFO, _("illuminance value : ") . $illuminance, __FILE__ . ":" . __LINE__);
if ($illuminance <= $this->luminance_min)
{
@@ -49,14 +49,14 @@ class rdc_salon_eclairage extends hook
if (getValue(RDC_SALON_MVMT, "occupancy") == OFF and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF))
{
logger(INFO, _("Setting to OFF"), __FILE__ . ":" . __LINE__);
- //setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", "OFF", true);
- $this->send($deviceTarget, "OFF", false, IDLE);
+ setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", "OFF", true);
+ //$this->send($deviceTarget, "OFF", false, IDLE);
}
}
break;
case "contact":
logger(INFO, _("CASE: Contact Door"), __FILE__ . ":" . __LINE__);
- if ($value == false and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min)
+ if ($value == false and $illuminance <= $this->luminance_min)
{
logger(INFO, _("Door is open and illumance < min"), __FILE__ . ":" . __LINE__);
if ($deviceTarget->properties["state"]["method"] !== MANUAL)
diff --git a/hooks/scripts/rdc_store.php b/hooks/scripts/rdc_store.php
index 4e774da..9b2c1e9 100644
--- a/hooks/scripts/rdc_store.php
+++ b/hooks/scripts/rdc_store.php
@@ -14,8 +14,9 @@ class rdc_store extends hook
protected $propertyInitialized =array();
protected $devicelist = array(
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux",
+ RDC_SALON_LUMINOSITE => "illuminance_lux",
METEO => "rainin",
- //METEO => "solarradiation",
+ METEO => "solarradiation",
METEO => "windspeedkmh",
METEO => "windgustkmh"
);
@@ -35,7 +36,7 @@ class rdc_store extends hook
$rafale = 0;
$soleil = 0;
$storeDevice = $indexDevices[RDC_STORE];
- $maxLevel = 100;
+ $this->maxLevel = 100;
$r = 100;
if (array_key_exists("position", $storeDevice->properties))
@@ -50,11 +51,19 @@ class rdc_store extends hook
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
{
$exterieur_lux = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 15);
+ if ($exterieur_lux == 0)
+ {
+ $exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"];
+ }
logger(DEBUG, "exterieur_lux=" . $exterieur_lux, __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 (array_key_exists(METEO, $indexDevices))
@@ -66,13 +75,17 @@ class rdc_store extends hook
}
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
{
- $rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 12);
+ if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50)
+ {
+ logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__);
+ }
+ $rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 7);
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, "soleil=" . $soleil, __FILE__ . ":" . __LINE__);
}
}
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
@@ -94,10 +107,10 @@ class rdc_store extends hook
{
case "illuminance_lux":
logger(DEBUG, "CASE: illuminance_lux:" . $value, __FILE__ . ":" . __LINE__);
- if ($exterieur_lux > 40000)
+ if ($exterieur_lux > 30000)
{
- logger(DEBUG, "exterieur_lux > 40000", __FILE__ . ":" . __LINE__);
- if ($this->maxLevel != 0 and $salon_lux > 150)
+ logger(DEBUG, "exterieur_lux > 30000", __FILE__ . ":" . __LINE__);
+ if ($this->maxLevel != 0 and $salon_lux > 100)
{
$store2level = $this->storeLevel + 15;
if ( $store2level > $this->maxLevel )
@@ -110,9 +123,9 @@ class rdc_store extends hook
$this->set($store2level);
}
}
- }elseif ($exterieur_lux < 35000)
+ }elseif ($exterieur_lux < 15000 and $salon_lux < 300)
{
- logger(DEBUG, "exterieur_lux < 35000", __FILE__ . ":" . __LINE__);
+ logger(DEBUG, "exterieur_lux < 15000", __FILE__ . ":" . __LINE__);
$this->close("Luminosité faible");
}
break;
@@ -141,11 +154,16 @@ class rdc_store extends hook
private function set ($level)
{
- if ($this->storeLevel < $level)
- {
+ logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__);
+ //if ($this->storeLevel < $level)
+ //{
logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
$this->send(100 - $level);
- }
+ //}else
+ /*{
+ logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__);
+ }*/
+
}
private function close ($reason)
diff --git a/moha.php b/moha.php
index 1b928c8..fd413ea 100644
--- a/moha.php
+++ b/moha.php
@@ -4,7 +4,7 @@ cli_set_process_title($title);
file_put_contents("/proc/".getmypid()."/comm",$title);
declare(ticks = 1);
-$testMode = true;
+$testMode = false;
$webServerIsActive = true;
require "constants.php";
@@ -14,15 +14,17 @@ $listPropertiesKeys = array("expose");
//global variables
-$notificationLevel = ALERT | ERROR;
+$notificationLevel = ALERT;
$topics = array(); // list of topics
$mids = array(); // list of message IDs
$devices = array(); // array of device objetcs
$indexDevices = array(); // index of devices by ieee_address
-$indexFriendlyNames = array(); // index of devices by freindly name
-$indexTypes = array(); // index of devices by type
+$indexFriendlyNames = array(); // index of devices by friendly name
+$indexTypes = array();
+$indexProperties = array(); // index of properties
$hooksList = array(); // list of hooks to be included
$hooks = array(); // array of hooks
+$topicsCallbacks = array(); // array of topics's callbacks
$notificationMethods = array(); // array of notification methods objects
$events = array(); // list of event objects
$monitored = array(); // list of device to watch
@@ -36,7 +38,7 @@ $curlErr = 0; // Number of errors returned by curl
$configDir = "./config"; // default config dir (production value is /etc/moha/)
$hooksInitialized = 0; // are all hooks initialized ? false/true
$flagHooks = false;
-
+$devicesRequest = false; //say to true when publishing device request to zigbee2mqtt
if ($testMode)
{
@@ -199,10 +201,10 @@ require "db_functions.php";
require "apiserver/apiserver.php";
// topics definition
-listHooks("./topics_callbacks", $hooksList);
-if (!empty($hooksList))
+listHooks("./topics_callbacks", $topicsCallbacks);
+if (!empty($topicsCallbacks))
{
- foreach ($hooksList as $callback)
+ foreach ($topicsCallbacks as $callback)
{
logger(INFO, _("Including ") . $callback, __FILE__ . ":" . __LINE__);
include $callback;
@@ -211,7 +213,7 @@ if (!empty($hooksList))
// making the list of hooks to include
listHooks("./hooks", $hooksList);
-if (!empty($hooksList)) // some hooks to include if hooklist is not empty
+if (!empty($hooksList)) // hooks to include if hooklist is not empty
{
foreach ($hooksList as $hookFile) // loop to include hooks in hookslist
{
@@ -268,7 +270,6 @@ if (file_exists($dataPath . "events.db"))
logger(DEBUG, _("Program start"), __FILE__ . ":" . __LINE__, false);
$client = new Mosquitto\Client();
-// defining callback functions
try
{
@@ -298,6 +299,8 @@ foreach($topics as $name => &$topic)
$topic->status = false;
}
+
+
// starting main loop
logger(INFO, _("Starting loop"), __FILE__ . ":" . __LINE__, false);
$oneshot = false;
@@ -305,56 +308,37 @@ $oneshot = false;
while (true)
{
$client->loop(); // mqtt server loop()
- /*if (! $included) // hooks not already included
+
+ if ($oneshot === false) // execute while the first loop :WARNING hooks can to be not initialized
{
- logger(DEBUG, _("Loading hooks list"), __FILE__ . ":" . __LINE__, false);
- 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;
- }
- }else
- {*/
+ logger(DEBUG, _("Oneshot part of loop"), __FILE__ . ":" . __LINE__, false);
+ pws2mqttGetList();
- if ($oneshot === false) // execute while the first loop :WARNING hooks can to be not initialized
+ $oneshot = true;
+ }
+ $nn = 0;
+ if($hooksInitialized == 0) // all hooks are not initialized
+ {
+ $i = 1;
+ foreach($hooks as $hookName => &$hook)
{
- logger(DEBUG, _("Oneshot part of loop"), __FILE__ . ":" . __LINE__, false);
-
- $oneshot = true;
- }
- $nn = 0;
- if($hooksInitialized == 0) // all hooks are not initialized
- {
- $i = 1;
- foreach($hooks as $hookName => &$hook)
+ if ($hook->initialized === false and $hook->active === true)
{
- if ($hook->initialized === false and $hook->active === true)
- {
- logger(WARNING, _("Initializing Hook not completely initialized :") . $hookName, __FILE__ . ":" . __LINE__);
- $i &= $hook->installHooks($indexDevices);
- }
+ logger(WARNING, _("Initializing Hook not completely initialized :") . $hookName, __FILE__ . ":" . __LINE__);
+ $i &= $hook->installHooks($indexDevices);
}
- $hooksInitialized = $i;
- }elseif($flagHooks === false)
- {
- logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__);
- $flagHooks = true;
- }else // executed when hooks initialization finished but database init not finished
- {
- //logger(DEBUG, _("looping"), __FILE__ . ":" . __LINE__);
-
}
- checkEvents();
- apiServer($read);
- //}
+ $hooksInitialized = $i;
+ }elseif($flagHooks === false)
+ {
+ logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__);
+ $flagHooks = true;
+ }else // executed when hooks initialization finished but database init not finished
+ {
+ //logger(DEBUG, _("looping"), __FILE__ . ":" . __LINE__);
+ }
+ checkEvents();
+ apiServer($read);
}
endMoha();
diff --git a/tools/install.sh b/tools/install.sh
index 421e1bb..0d801fd 100755
--- a/tools/install.sh
+++ b/tools/install.sh
@@ -1,9 +1,7 @@
#!/usr/bin/bash
rsync -aP --exclude "*~" --exclude *kate-swp $1/config/ /etc/moha/
-chmod 0500 /etc/moha
-chmod 0400 /etc/moha/*
+chmod a+rX -R /etc/moha
chown domotique:domotique -R /etc/moha
rsync -aP --exclude "*~" --exclude *kate-swp $1/webserver/ /var/www/html/moha/
-chmod 0400 -R /var/www/html/moha/
-chmod 0500 /var/www/html/moha
+chmod u+rX -R /var/www/html/moha/
chown apache:apache -R /var/www/html/moha
diff --git a/topics_callbacks/linky2mqtt.php b/topics_callbacks/linky2mqtt.php
index df803ef..6926001 100644
--- a/topics_callbacks/linky2mqtt.php
+++ b/topics_callbacks/linky2mqtt.php
@@ -1,6 +1,5 @@
payload, true);
// friendlyname
- if (!array_key_exists($fn, $device))
+ if ( $fn != "get")
{
- echo "initializing $fn";
- $device[$fn] = array("device" => new device);
- $device = &$device[$fn];
- $device["device"]->friendlyName = $payloadArray["friendly_name"];
- $device["device"]->ieeeAddress = $payloadArray["ieeeAddress"];
- $device["device"]->type = $payloadArray["type"];
- $device["device"]->topic = $topicName;
- //$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
- //$indexFriendlyNames[$topicName][$fn] = & $device["device"];
- mkIndexes();
+ if (!array_key_exists($fn, $device))
+ {
+ echo "initializing $fn";
+ $device[$fn] = array("device" => new device);
+ $device = &$device[$fn];
+ $device["device"]->friendlyName = $payloadArray["friendly_name"];
+ $device["device"]->ieeeAddress = $payloadArray["ieeeAddress"];
+ $device["device"]->type = $payloadArray["type"];
+ $device["device"]->topic = $topicName;
+ //$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
+ //$indexFriendlyNames[$topicName][$fn] = & $device["device"];
+ mkIndexes();
- }else
- {
- $device = &$device[$fn];
- }
- unset($payloadArray["friendly_name"]);
- unset($payloadArray["ieeeAddress"]);
- unset($payloadArray["type"]);
+ }else
+ {
+ $device = &$device[$fn];
+ }
+ unset($payloadArray["friendly_name"]);
+ unset($payloadArray["ieeeAddress"]);
+ unset($payloadArray["type"]);
- foreach ($payloadArray as $property => $value)
- {
- $str = substr($property, -1);
- if ($str == "f")
+ foreach ($payloadArray as $property => $value)
{
- $newProperty = rtrim($property, "f") . "c";
- $payloadArray[$newProperty] = farenheit2celsius($value);
- }elseif ($str == "h")
- {
- $newProperty = substr($property, 0, -3) . "kmh";
- $payloadArray[$newProperty] = mph2kmh($value);
+ $str = substr($property, -1);
+ if ($str == "f")
+ {
+ $newProperty = rtrim($property, "f") . "c";
+ $payloadArray[$newProperty] = farenheit2celsius($value);
+ }elseif ($str == "h")
+ {
+ $newProperty = substr($property, 0, -3) . "kmh";
+ $payloadArray[$newProperty] = mph2kmh($value);
+ }
+ if ($property == "baromin")
+ {
+ $newProperty = "barominmb";
+ $payloadArray["barominmb"] = millibars($value);
+ }
}
- if ($property == "baromin")
+ //$device = getDeviceByFriendlyname($topicName, $fn, $payloadArray, true);
+ if (!empty($payloadArray))
{
- $newProperty = "barominmb";
- $payloadArray["barominmb"] = millibars($value);
+ changeDevice($topicName, $fn, $device["device"], $payloadArray);
}
}
- //$device = getDeviceByFriendlyname($topicName, $fn, $payloadArray, true);
- if (!empty($payloadArray))
- {
- changeDevice($topicName, $fn, $device["device"], $payloadArray);
- }
};
$topics["pws2mqtt"]->callback = "pws2mqttCallback";
@@ -66,5 +69,4 @@ if (!is_callable("pws2mqttGetList"))
}
}
-pws2mqttGetList();
?>
diff --git a/topics_callbacks/zigbee2mqtt.php b/topics_callbacks/zigbee2mqtt.php
index 9868334..64bd0be 100644
--- a/topics_callbacks/zigbee2mqtt.php
+++ b/topics_callbacks/zigbee2mqtt.php
@@ -5,7 +5,7 @@ if (!array_key_exists("zigbee2mqtt", $devices)) $devices["zigbee2mqtt"] = array
function zigbee2mqttCallback($topic, $message)
{
- global $topics, $devices, $included, $logFh, $indexFriendlyNames;
+ global $topics, $devices, $included, $logFh, $indexFriendlyNames, $devicesRequest;
if ($topic[1] == "bridge")
{
@@ -20,6 +20,7 @@ function zigbee2mqttCallback($topic, $message)
//fwrite($logFh, var_export($topics[$topic[0]]->devices, true));
mkDevicesDB($topic[0], $topics[$topic[0]]->devices);
getDevicesValues($topic[0]);
+ $devicesRequest = false;
break;
case "groups":
logger(DEBUG,_("Inserting zigbee groups in DB"), __FILE__ . ":" . __LINE__);
@@ -77,7 +78,7 @@ function zigbee2mqttCallback($topic, $message)
$alert = 0;
while (!array_key_exists($fn, $indexFriendlyNames))
{
- logger(INFO, _("device does not exists in IndexFriendlyNames: ") . print_r($payloadArray,true), __FILE__ . ":" . __LINE__);
+ logger(ERROR, $fn . _(" device does not exists in IndexFriendlyNames: ") . print_r($payloadArray,true), __FILE__ . ":" . __LINE__);
if ($flag == 0)
{
logger(INFO, "Reindexing all indexes", __FILE__ . ":" . __LINE__);
@@ -86,26 +87,32 @@ function zigbee2mqttCallback($topic, $message)
}elseif($flag == 1)
{
logger(INFO, "getting device list from zigbee2mqtt", __FILE__ . ":" . __LINE__);
- publish("zigbee2mqtt", array("bridge/devices" => ""), "get");
+ if ($devicesRequest === false)
+ {
+ publish("zigbee2mqtt", array("bridge/devices" => ""), "get");
+ }
$flag += 1;
- }elseif($flag >= 2)
+ }elseif($flag++ >= 5)
{
$flage = 0;
- if ($alert++ > 4)
- {
- logger(ALERT, _("device does not exists in IndexFriendlyNames: ") . $fn, __FILE__ . ":" . __LINE__);
- break;
- }
+ //if ($alert++ > 4)
+ //{
+ logger(ERROR, _(" stopping searching for ") . $fn . " payloadArray =>" . print_r($payloadArray, true), __FILE__ . ":" . __LINE__);
+ break;
+ //}
}
}
//logger(DEBUG, "PayloadArray = " . print_r($payloadArray,true), __FILE__ . ":" . __LINE__);
- if ($alert <= 4)
+ if ($flag <= 4)
{
changeDevice($topicName, $fn, $indexFriendlyNames[$fn], $payloadArray);
+ }else
+ {
+ logger(ERROR, $fn . _(" not changed"), __FILE__ . ":" . __LINE__);
}
}else
{
- logger(DEBUG, _("Zigbee2mqtt doing get or set !?"));
+ logger(DEBUG, _("Zigbee2mqtt doing get or hooks not included !?"), __FILE__ . ":" . __LINE__);
}
};
diff --git a/utils.php b/utils.php
index 82b710e..edf49fa 100644
--- a/utils.php
+++ b/utils.php
@@ -1,5 +1,5 @@
properties))
{
$r = $indexDevices[$ieeeAddress]->properties[$property]["value"];
- logger(DEBUG, "device: " . $indexDevices[$ieeeAddress]->friendlyName . " value: " . $r, __FILE__ . ":" . __LINE__ );
+ //logger(DEBUG, "device: " . $indexDevices[$ieeeAddress]->friendlyName . " value: " . $r, __FILE__ . ":" . __LINE__ );
}else
{
$r = false;
- logger(ERROR, "device: " . $indexDevices[$ieeeAddress]->friendlyName . "property " . $property . "does not exists", __FILE__ . ":" . __LINE__ );
+ //logger(ERROR, "device: " . $indexDevices[$ieeeAddress]->friendlyName . "property " . $property . "does not exists", __FILE__ . ":" . __LINE__ );
}
return $r;
}
@@ -99,7 +99,7 @@ function setValue($fn, $property, $value)
$indexDevices[$ieeeAddress]->properties[$property]["value"] = $value;
}
-logger(DEBUG, _("signal handling"), __FILE__ . ":" . __LINE__, false);
+//logger(DEBUG, _("signal handling"), __FILE__ . ":" . __LINE__, false);
//signal handling
function signalHandler($signal)
{
diff --git a/webserver/class/db.class.php b/webserver/class/db.class.php
new file mode 100644
index 0000000..68a6af9
--- /dev/null
+++ b/webserver/class/db.class.php
@@ -0,0 +1,38 @@
+mysqlServer = "192.168.1.253"; // Your test server
+ }
+ while ($this->connect($this->mysqlServer, $this->username, $this->passwd, $this->database) === false)
+ {
+ //logger(ERROR,_("Connection to sql server error :") . $this->connect_error, __FILE__ . ":" . __LINE__);
+ sleep(5);
+ $flagError = true;
+ }
+ if ($flagError === true)
+ {
+ //logger(ERROR, _("Connection to sql server ready"), __FILE__ . ":" . __LINE__);
+ }
+ $result = new mysqli_result($this);
+ }
+
+ function protect($string)
+ {
+ return $this->real_escape_string($string);
+ }
+}
+?>
diff --git a/webserver/config.php b/webserver/config.php
new file mode 100644
index 0000000..f499e55
--- /dev/null
+++ b/webserver/config.php
@@ -0,0 +1,5 @@
+
diff --git a/webserver/display_stats.php b/webserver/display_stats.php
index 191b50b..4f938d4 100644
--- a/webserver/display_stats.php
+++ b/webserver/display_stats.php
@@ -2,14 +2,19 @@
/****************************************************************/
/* */
-/*need device ieeeAddress, property, startDate and finalDate */
+/*need device ieeeAddress, property, startDate and endDate */
/* */
/****************************************************************/
-function displayStats($socket, $argList)
+require_once "config.php";
+require_once "utils.php";
+require_once "header.php";
+
+
+function displayStats($ieeeAddress, $fn, $property, $startDate, $endDate)
{
global $indexFriendlyNames, $mohaDB;
- logger(INFO, "Function displayStats", __FILE__ . ":" . __LINE__);
+ //logger(INFO, "Function displayStats", __FILE__ . ":" . __LINE__);
// Validation of the dates
if (validateDate($argList["startDate"]) && validateDate($argList["finalDate"]))
@@ -23,10 +28,10 @@ function displayStats($socket, $argList)
}else
{
$query = "SELECT date, value FROM logs WHERE device='" . $indexFriendlyNames[$argList["fn"]]->ieeeAddress . "' AND property='" . $argList["property"] . "' AND '" . $argList["startDate"] . "'>= date AND '" . $argList["finalDate"] . "' <= date ORDER BY date";
- logger(DEBUG, _("query : ") . $query, __FILE__ . ":" . __LINE__);
+ //logger(DEBUG, _("query : ") . $query, __FILE__ . ":" . __LINE__);
if(!($mohaDB->result = $mohaDB->query($query)))
{
- logger(ERROR, _("mysql query error: ") . $mohaDB->error, __FILE__ . ":" . __LINE__);
+ //logger(ERROR, _("mysql query error: ") . $mohaDB->error, __FILE__ . ":" . __LINE__);
}
$datas = $mohaDB->result->fetch_all(MYSQLI_ASSOC);
htmlSend($socket, diagramDisplay($datas));
@@ -144,4 +149,9 @@ function diagramDisplay($datas)
//Desallouer la mémoire utiliser par l'image
imagedestroy($courbe);
}
+
+$tmp = explode("|", $_GET["device"]);
+
+displayStats($tmp[0], $tmp[1], $tmp[2]);
+
?>
diff --git a/webserver/index.php b/webserver/index.php
index 0719f3f..127ebbc 100644
--- a/webserver/index.php
+++ b/webserver/index.php
@@ -1,10 +1,92 @@
") . json_last_error_msg() .EOLH;
+}else
+{
+ $query = "SELECT DISTINCT device, property FROM logs";
+ $result = $mohaDB->query($query);
+ $devices = mysqli_fetch_all($result, MYSQLI_ASSOC);
+ $devicesList = array();
+// print_r($devices);
+ print '" . EOL;
+}
require_once "footer.php";
?>
diff --git a/webserver/utils.php b/webserver/utils.php
new file mode 100644
index 0000000..b0f76e9
--- /dev/null
+++ b/webserver/utils.php
@@ -0,0 +1,16 @@
+