debug
This commit is contained in:
		
							
								
								
									
										24
									
								
								class/db.php
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								class/db.php
									
									
									
									
									
								
							| @@ -40,8 +40,6 @@ class db extends mysqli | |||||||
| 		global $mohaDB, $properties2log, $testMode; | 		global $mohaDB, $properties2log, $testMode; | ||||||
| 		$precision = 0; | 		$precision = 0; | ||||||
| 		//echo "############## logProperty ################\nproperty => " . $propertyTree .EOL; | 		//echo "############## logProperty ################\nproperty => " . $propertyTree .EOL; | ||||||
| 		if (array_key_exists($property, $properties2log)) |  | ||||||
| 		{ |  | ||||||
| 		//echo "logging in database"; | 		//echo "logging in database"; | ||||||
| 		//var_dump($device); | 		//var_dump($device); | ||||||
| 		$ieeeAddress = $device->ieeeAddress; | 		$ieeeAddress = $device->ieeeAddress; | ||||||
| @@ -51,11 +49,15 @@ class db extends mysqli | |||||||
| 		if (is_numeric($value) and !empty($properties2log[$property])) | 		if (is_numeric($value) and !empty($properties2log[$property])) | ||||||
| 		{ | 		{ | ||||||
| 			// calculate a min/max value for storing data | 			// calculate a min/max value for storing data | ||||||
| 				$minMax = $properties2log[$property]; | 			$r = $properties2log[$property]; | ||||||
| 				if (is_callable($minMax)) | 			if (is_callable($r)) | ||||||
| 			{ | 			{ | ||||||
| 					$minMax = $minMax($value); | 				$minMax = $r($value); | ||||||
|  | 			}else | ||||||
|  | 			{ | ||||||
|  | 				$minMax = $r; | ||||||
| 			} | 			} | ||||||
|  | 			logger(DEBUG, _("minMax = " . $minMax), __FILE__ . ":" . __LINE__); | ||||||
| 			var_dump($value) . EOL; | 			var_dump($value) . EOL; | ||||||
| 			var_dump($minMax) . EOL; | 			var_dump($minMax) . EOL; | ||||||
| 			var_dump($oldValue) . EOL; | 			var_dump($oldValue) . EOL; | ||||||
| @@ -81,20 +83,26 @@ class db extends mysqli | |||||||
| 		} | 		} | ||||||
| 		logger(INFO, sprintf(_("New value (%s) of property: '%s' of device: %s stored in database"), bool2string($value), $property, $device->friendlyName), __FILE__ . ":" . __LINE__); | 		logger(INFO, sprintf(_("New value (%s) of property: '%s' of device: %s stored in database"), bool2string($value), $property, $device->friendlyName), __FILE__ . ":" . __LINE__); | ||||||
| 	} | 	} | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	function moyenne($deviceObject, $property, $time) | 	function moyenne($deviceObject, $property, $time) | ||||||
| 	{ | 	{ | ||||||
| 		$query = "SELECT AVG(value) as value FROM logs WHERE device='" . $deviceObject->ieeeAddress . "' AND property='" . $property . "' AND TIMEDIFF(NOW(), date) < '00:" . $time . "'"; | 		$query = "SELECT AVG(value) as value FROM logs WHERE device='" . $deviceObject->ieeeAddress . "' AND property='" . $property . "' AND TIMEDIFF(NOW(), date) < '00:" . $time . "'"; | ||||||
|  | 		logger(DEBUG, _("query is: ") . $query, __FILE__ . ":" . __LINE__); | ||||||
| 		if(!$this->result = $this->query($query)) | 		if(!$this->result = $this->query($query)) | ||||||
| 		{ | 		{ | ||||||
| 			logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__); | 			logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__); | ||||||
| 		} | 			return 1; | ||||||
|  | 		}else | ||||||
|  | 		{ | ||||||
| 			$value = $this->result->fetch_array(MYSQLI_NUM); | 			$value = $this->result->fetch_array(MYSQLI_NUM); | ||||||
| 			//var_dump($value); | 			//var_dump($value); | ||||||
|  | 			logger(DEBUG, _("result is: ") . print_r($value, true), __FILE__ . ":" . __LINE__); | ||||||
| 			return $value[0]; | 			return $value[0]; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| $mohaDB = new db(); | $mohaDB = new db(); | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| class hook | class hook | ||||||
| { | { | ||||||
| 	public $hookName = ""; | 	public $hookName = ""; | ||||||
| 	public $active = true; | 	public $active; | ||||||
| 	public $initialized = false; | 	public $initialized = false; | ||||||
| 	protected $devicelist; | 	protected $devicelist; | ||||||
| 	protected $propertyInitialized; | 	protected $propertyInitialized; | ||||||
|   | |||||||
| @@ -26,8 +26,8 @@ $properties2log = array( | |||||||
| 	"dewptc" => 0.5, | 	"dewptc" => 0.5, | ||||||
| 	"windchillc" => 0.5, | 	"windchillc" => 0.5, | ||||||
| 	"winddir" => 40, | 	"winddir" => 40, | ||||||
| 	"windspeedkmh" => 10, | 	"windspeedkmh" => 5, | ||||||
| 	"windgustkmh" => 10, | 	"windgustkmh" => 5, | ||||||
| 	"rainin" => 0.5, | 	"rainin" => 0.5, | ||||||
| 	//"dailyrainin" => null, | 	//"dailyrainin" => null, | ||||||
| 	//"weeklyrainin" => null, | 	//"weeklyrainin" => null, | ||||||
|   | |||||||
| @@ -275,12 +275,16 @@ function getDevicesValues($topic) | |||||||
|  |  | ||||||
| function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key) | function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key) | ||||||
| { | { | ||||||
| 	global $mohaDB; | 	global $mohaDB, $properties2log; | ||||||
| 	//$changed[$fn]["key"] = $key; | 	//$changed[$fn]["key"] = $key; | ||||||
| 	//$changed[$fn]["value"] = $value; | 	//$changed[$fn]["value"] = $value; | ||||||
|  |  | ||||||
|  | 	if (array_key_exists($key, $properties2log)) | ||||||
|  | 	{ | ||||||
| 		logger(INFO, sprintf(_("Logging Device property %s, %s"), $propertyTree . $key, bool2string($value)), __FILE__ . ":" . __LINE__); | 		logger(INFO, sprintf(_("Logging Device property %s, %s"), $propertyTree . $key, bool2string($value)), __FILE__ . ":" . __LINE__); | ||||||
| 		$mohaDB->logProperty($parentDevice, $key, $value, $property["value"]); | 		$mohaDB->logProperty($parentDevice, $key, $value, $property["value"]); | ||||||
| 		logger(DEBUG, sprintf(_("old value was %s, new is %s" ), bool2string($property["value"]), bool2string($value)), __FILE__ . ":" . __LINE__); | 		logger(DEBUG, sprintf(_("old value was %s, new is %s" ), bool2string($property["value"]), bool2string($value)), __FILE__ . ":" . __LINE__); | ||||||
|  | 	} | ||||||
| 	$property["value"] = $value; | 	$property["value"] = $value; | ||||||
| 	if (!empty($property["functions"])) | 	if (!empty($property["functions"])) | ||||||
| 	{ | 	{ | ||||||
| @@ -288,8 +292,16 @@ function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key) | |||||||
| 		foreach($property["functions"] as $function) | 		foreach($property["functions"] as $function) | ||||||
| 		{ | 		{ | ||||||
| 			try | 			try | ||||||
|  | 			{ | ||||||
|  | 				logger(INFO, print_r($function, true), __FILE__ . ":" . __LINE__); | ||||||
|  | 				if ( $function[0]->active === true ) | ||||||
| 				{ | 				{ | ||||||
| 					$function($parentDevice, $key, $value); | 					$function($parentDevice, $key, $value); | ||||||
|  | 				}else | ||||||
|  | 				{ | ||||||
|  | 					logger(INFO, $function . _(" is disabled"), __FILE__ . ":" . __LINE__ ); | ||||||
|  | 				} | ||||||
|  |  | ||||||
| 			}catch (Exception $e) | 			}catch (Exception $e) | ||||||
| 			{ | 			{ | ||||||
| 				$s = 'Exception reçue : ' .  $e->getMessage(); | 				$s = 'Exception reçue : ' .  $e->getMessage(); | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ class notificationFreemobile | |||||||
| 	{ | 	{ | ||||||
| 		global $curlErr; | 		global $curlErr; | ||||||
| 		$result = false; | 		$result = false; | ||||||
| 		if ($this->active == true) | 		if ($this->active === true) | ||||||
| 		{ | 		{ | ||||||
| 			$ch = curl_init(); | 			$ch = curl_init(); | ||||||
| 			// set url | 			// set url | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ | |||||||
| class rdc_store extends hook | class rdc_store extends hook | ||||||
| { | { | ||||||
| 	public $hookName = "rdc_store"; | 	public $hookName = "rdc_store"; | ||||||
| 	public $active = true;			//enable/disable hook (true => enabled) | 	public $active = false;			//enable/disable hook (true => enabled) | ||||||
| 	public $timer = 0; | 	public $timer = 0; | ||||||
| 	public $luminance_min = 60; | 	public $luminance_min = 60; | ||||||
| 	public $luminance_max = 3000; | 	public $luminance_max = 3000; | ||||||
| @@ -74,7 +74,7 @@ class rdc_store extends hook | |||||||
| 				$rainTmp = $indexDevices[METEO]->properties["rainin"]["value"]; | 				$rainTmp = $indexDevices[METEO]->properties["rainin"]["value"]; | ||||||
| 				$rain = $rainTmp - $rainS; | 				$rain = $rainTmp - $rainS; | ||||||
| 				$rainS = $rainTmp; | 				$rainS = $rainTmp; | ||||||
| 				logger(DEBUG, "rain=" . var_dump($rain), __FILE__ . ":" . __LINE__); | 				logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__); | ||||||
| 			} | 			} | ||||||
| 			if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties)) | 			if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties)) | ||||||
| 			{ | 			{ | ||||||
| @@ -82,7 +82,7 @@ class rdc_store extends hook | |||||||
| 				{ | 				{ | ||||||
| 					logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__); | 					logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__); | ||||||
| 				} | 				} | ||||||
| 				$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 7); | 				$rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"];  //$mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6); | ||||||
| 				logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); | 				logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); | ||||||
| 			} | 			} | ||||||
| 			if (array_key_exists("solarradiation", $indexDevices[METEO]->properties)) | 			if (array_key_exists("solarradiation", $indexDevices[METEO]->properties)) | ||||||
| @@ -92,7 +92,7 @@ class rdc_store extends hook | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__); | 		logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__); | ||||||
| 		if ($rafale >= 60 or $rain != 0) | 		if ($rafale >= 50 or $rain != 0) | ||||||
| 		{ | 		{ | ||||||
| 			$this->maxLevel = 0; | 			$this->maxLevel = 0; | ||||||
| 			logger(DEBUG, sprintf("rafale = %s  and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__); | 			logger(DEBUG, sprintf("rafale = %s  and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__); | ||||||
| @@ -100,7 +100,7 @@ class rdc_store extends hook | |||||||
| 			return 0; | 			return 0; | ||||||
| 		}elseif ($rafale != 0) | 		}elseif ($rafale != 0) | ||||||
| 		{ | 		{ | ||||||
| 			$this->maxLevel = ($r = 100 - round(($rafale-10)/5, 0, PHP_ROUND_HALF_UP)*20)<0 ? 0 : $r; | 			$this->maxLevel = ($r = 100 - round($rafale/5, 0, PHP_ROUND_HALF_UP)*10)<0 ? 0 : $r; | ||||||
| 			//$this->maxLevel = 100 / $rafale; | 			//$this->maxLevel = 100 / $rafale; | ||||||
| 			logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); | 			logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); | ||||||
| 		} | 		} | ||||||
| @@ -110,7 +110,7 @@ class rdc_store extends hook | |||||||
| 		{ | 		{ | ||||||
| 			case "illuminance_lux": | 			case "illuminance_lux": | ||||||
| 			logger(DEBUG, "CASE: illuminance_lux:" . $value, __FILE__ . ":" . __LINE__); | 			logger(DEBUG, "CASE: illuminance_lux:" . $value, __FILE__ . ":" . __LINE__); | ||||||
| 			if ($exterieur_lux > 30000) | 			if ($exterieur_lux > 30000 or $salon_lux >600) | ||||||
| 			{ | 			{ | ||||||
| 				logger(DEBUG, "exterieur_lux > 30000", __FILE__ . ":" . __LINE__); | 				logger(DEBUG, "exterieur_lux > 30000", __FILE__ . ":" . __LINE__); | ||||||
| 				if ($this->maxLevel != 0 and $salon_lux > 100) | 				if ($this->maxLevel != 0 and $salon_lux > 100) | ||||||
| @@ -126,7 +126,7 @@ class rdc_store extends hook | |||||||
| 						$this->set($store2level); | 						$this->set($store2level); | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			}elseif ($exterieur_lux < 15000 and $salon_lux < 110) | 			}elseif ($exterieur_lux < 12000 and $salon_lux < 150) | ||||||
| 			{ | 			{ | ||||||
| 				logger(DEBUG, "exterieur_lux < 15000", __FILE__ . ":" . __LINE__); | 				logger(DEBUG, "exterieur_lux < 15000", __FILE__ . ":" . __LINE__); | ||||||
| 				$this->close("Luminosité faible"); | 				$this->close("Luminosité faible"); | ||||||
| @@ -140,19 +140,14 @@ class rdc_store extends hook | |||||||
| 			logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__); | 			logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__); | ||||||
| 		//case "windspeedkmh": | 		//case "windspeedkmh": | ||||||
| 		//	logger(DEBUG, "CASE: windspeedkmh:" . $value, __FILE__ . ":" . __LINE__); | 		//	logger(DEBUG, "CASE: windspeedkmh:" . $value, __FILE__ . ":" . __LINE__); | ||||||
|  | 			break; | ||||||
|  | 		default: | ||||||
|  | 		} | ||||||
| 		logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); | 		logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); | ||||||
| 		if ($this->storeLevel > $this->maxLevel) | 		if ($this->storeLevel > $this->maxLevel) | ||||||
| 		{ | 		{ | ||||||
| 			$this->set($this->maxLevel); | 			$this->set($this->maxLevel); | ||||||
| 		} | 		} | ||||||
| 			break; |  | ||||||
| 		default: |  | ||||||
| 		} |  | ||||||
| 		/*if ($store2level <= $this->storeLevel) |  | ||||||
| 		{ |  | ||||||
| 			$this->set($store2level); |  | ||||||
| 		}*/ |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	private function set ($level) | 	private function set ($level) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user