debugging
This commit is contained in:
		@@ -75,7 +75,7 @@ class db extends mysqli
 | 
			
		||||
					logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			logger(INFO, sprintf(_("New value of property: '%s' of device: %s stored in database"), $propertyTree, $device->friendlyName, $value), __FILE__ . ":" . __LINE__);
 | 
			
		||||
			logger(INFO, sprintf(_("New value (%s) of property: '%s' of device: %s stored in database"), $value, $propertyTree, $device->friendlyName), __FILE__ . ":" . __LINE__);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -170,7 +170,7 @@ function removeEvent($device, $property , $value)
 | 
			
		||||
function searchEvent($device, $property , $value)
 | 
			
		||||
{
 | 
			
		||||
	global $events;
 | 
			
		||||
	logger(DEBUG, _("searching event for device %s, property %s and value %s"), $device->friendlyName, $property, bool2string($value), __FILE__ . ":" . __LINE__);
 | 
			
		||||
	logger(DEBUG, sprintf(_("searching event for device %s, property %s and value %s"), $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
 | 
			
		||||
	foreach($events as $key => $event)
 | 
			
		||||
	{
 | 
			
		||||
		//echo "Event : $event => $value" . EOL;
 | 
			
		||||
 
 | 
			
		||||
@@ -3,14 +3,14 @@
 | 
			
		||||
class rdc_chambre_eclairage extends hook
 | 
			
		||||
{
 | 
			
		||||
	public $hookName = "rdc_chambre_eclairage";
 | 
			
		||||
	public $active = false;			//enable/disable hook (true => enabled)
 | 
			
		||||
	public $active = true;			//enable/disable hook (true => enabled)
 | 
			
		||||
	public $delay = 5;				// amount of time in $timeunit
 | 
			
		||||
	public $timeUnit = "minute";	// unit of time for delay, second, minute, hour, day, week, month, year
 | 
			
		||||
	public $luminance_min = 60;
 | 
			
		||||
	public $luminance_max = 3000;
 | 
			
		||||
	protected $devicelist = array(
 | 
			
		||||
		"RDC_CHAMBRE_AMBIANCE" => array("state", false),
 | 
			
		||||
		"RDC_CHAMBRE_ECLAIRAGE" => array("state_l1", false),
 | 
			
		||||
		"RDC_CHAMBRE_AMBIANCE" => array("state", false),		// "ON"/"OFF"
 | 
			
		||||
		"RDC_CHAMBRE_ECLAIRAGE" => array("state_l1", false),	// "ON"/"OFF"
 | 
			
		||||
		"RDC_CHAMBRE_MVMT" => array("occupancy", false),
 | 
			
		||||
		"RDC_CHAMBRE_ARMOIRE_GAUCHE" => array("contact", false)
 | 
			
		||||
	);
 | 
			
		||||
@@ -25,7 +25,10 @@ class rdc_chambre_eclairage extends hook
 | 
			
		||||
		$lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->illuminance_lux;
 | 
			
		||||
		if ($property == "occupancy" and $value == "ON")
 | 
			
		||||
		{
 | 
			
		||||
			$this->send(RDC_CHAMBRE_LUMINOSITE, "ON", "OFF", AUTO);
 | 
			
		||||
			$this->send(RDC_CHAMBRE_AMBIANCE, "ON", "OFF", AUTO);
 | 
			
		||||
		}elseif ($property == "contact" and $value = true and getValue(RDC_CHAMBRE_ECLAIRAGE) == "OFF")
 | 
			
		||||
		{
 | 
			
		||||
			$this->send(RDC_CHAMBRE_ECLAIRAGE, "ON", "OFF", AUTO);
 | 
			
		||||
		}
 | 
			
		||||
		logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, $value), __FILE__ . ":" . __LINE__);
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ class rdc_salon_eclairage extends hook
 | 
			
		||||
 | 
			
		||||
	public $delay = 3;				// amount of time in $timeunit
 | 
			
		||||
	public $timeUnit = "minute";	// unit of time for delay, second, minute, hour, day, week, month, year
 | 
			
		||||
	public $luminance_min = 60;
 | 
			
		||||
	public $luminance_min = 70;
 | 
			
		||||
	public $luminance_max = 3000;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -26,7 +26,7 @@ class rdc_salon_eclairage extends hook
 | 
			
		||||
		{
 | 
			
		||||
			case "occupancy":
 | 
			
		||||
				logger(DEBUG, _("CASE: Occupancy => ") . bool2string($value), __FILE__ . ":" . __LINE__);
 | 
			
		||||
				//print_r($indexDevices[RDC_SALON_LUMINOSITE]);
 | 
			
		||||
				//print_r(getValue(RDC_SALON_LUMINOSITE, "illuminance_lux"));
 | 
			
		||||
				if ($value == ON and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min)
 | 
			
		||||
				{
 | 
			
		||||
					logger(DEBUG, _("setting to ON"), __FILE__ . ":" . __LINE__);
 | 
			
		||||
@@ -35,23 +35,26 @@ class rdc_salon_eclairage extends hook
 | 
			
		||||
				}elseif ($value == OFF)
 | 
			
		||||
				{
 | 
			
		||||
					logger(DEBUG, _("Value is OFF"), __FILE__ . ":" . __LINE__);
 | 
			
		||||
					if (getValue(RDC_SALON_MVMT, "occupancy") == OFF)
 | 
			
		||||
					if (getValue(RDC_SALON_MVMT, "occupancy") == OFF and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF))
 | 
			
		||||
					{
 | 
			
		||||
						if (getValue(RDC_SALON_MVMT2, "occupancy") == OFF)
 | 
			
		||||
						{
 | 
			
		||||
							logger(DEBUG, _("Setting to OFF"), __FILE__ . ":" . __LINE__);
 | 
			
		||||
							setDelay($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], $this->delay, $this->timeUnit, "state", "OFF", true);
 | 
			
		||||
							//$this->send("ON", "OFF", AUTO);
 | 
			
		||||
						}
 | 
			
		||||
						logger(DEBUG, _("Setting to OFF"), __FILE__ . ":" . __LINE__);
 | 
			
		||||
						setDelay($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], $this->delay, $this->timeUnit, "state", "OFF", true);
 | 
			
		||||
						//$this->send("ON", "OFF", AUTO);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
			case "contact":
 | 
			
		||||
				logger(DEBUG, _("CASE: Contact Door"), __FILE__ . ":" . __LINE__);
 | 
			
		||||
				if ($value == false and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min)
 | 
			
		||||
				if ($value == false and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min and getValue(RDC_SALON_ECLAIRAGE_PANNEAU, "state") == "OFF")
 | 
			
		||||
				{
 | 
			
		||||
					logger(DEBUG, _("Door is open and illumance < min"), __FILE__ . ":" . __LINE__);
 | 
			
		||||
					$this->send("ON", "OFF", AUTO);
 | 
			
		||||
					if (getValue(RDC_SALON_MVMT, "occupancy") == ON or getValue(RDC_SALON_MVMT2, "occupancy") == ON)
 | 
			
		||||
					{
 | 
			
		||||
						$this->send("ON", null, AUTO);
 | 
			
		||||
					}else
 | 
			
		||||
					{
 | 
			
		||||
						$this->send("ON", "OFF", AUTO);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
			case "illuminance_lux":
 | 
			
		||||
@@ -60,7 +63,8 @@ class rdc_salon_eclairage extends hook
 | 
			
		||||
				{
 | 
			
		||||
					logger(DEBUG, _("illuminace is > to max"), __FILE__ . ":" . __LINE__);
 | 
			
		||||
					//$this->send("OFF", null, AUTO);
 | 
			
		||||
					removeEvent($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], "state", "OFF");
 | 
			
		||||
					//removeEvent($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], "state", "OFF");
 | 
			
		||||
					setDelay($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], $this->delay, $this->timeUnit, "state", "OFF", true);
 | 
			
		||||
				}elseif ($value <= $this->luminance_min and (getValue(RDC_SALON_MVMT, "occupancy") == ON OR getValue(RDC_SALON_MVMT2,"occupancy") == ON))
 | 
			
		||||
				{
 | 
			
		||||
					logger(DEBUG, _("illuminance < min and movement detected"), __FILE__ . ":" . __LINE__);
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ class rdc_sdb_eclairage extends hook
 | 
			
		||||
		RDC_SDB_WC_ECLAIRAGE => array("state_l1", false)
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	// callback fonction. Is called with these 4 parameters
 | 
			
		||||
	// callback fonction. Is called with these 3 parameters
 | 
			
		||||
	public function callBack(&$device, $property, $value)
 | 
			
		||||
	{
 | 
			
		||||
		global $devices, $indexDevices;
 | 
			
		||||
@@ -33,19 +33,22 @@ class rdc_sdb_eclairage extends hook
 | 
			
		||||
			case "occupancy":
 | 
			
		||||
				if ($value == ON)
 | 
			
		||||
				{
 | 
			
		||||
					$this->send("ON");
 | 
			
		||||
					setDelay($device, $this->delay, $this->timeUnit, "state_l1", "OFF", true);
 | 
			
		||||
					if (getValue(RDC_SDB_WC_ECLAIRAGE, "state_l1") != "ON")
 | 
			
		||||
					{
 | 
			
		||||
						$this->send("ON");
 | 
			
		||||
					}
 | 
			
		||||
					//setDelay($indexDevices[RDC_SDB_WC_ECLAIRAGE], $this->delay, $this->timeUnit, "state_l1", "OFF", true);
 | 
			
		||||
					$device->method = AUTO;
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
			case "state_l1":
 | 
			
		||||
				if ($value == ON)
 | 
			
		||||
				{
 | 
			
		||||
					setDelay($device, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true);
 | 
			
		||||
					setDelay($indexDevices[RDC_SDB_WC_ECLAIRAGE], $this->delayManual, $this->timeUnit, "state_l1", "OFF", true);
 | 
			
		||||
					$device->method = MANUAL;
 | 
			
		||||
				}elseif ($value = OFF)
 | 
			
		||||
				{
 | 
			
		||||
					deleteEvent(searchEvent($device, "state_l1", "OFF"));
 | 
			
		||||
					removeEvent($indexDevices[RDC_SDB_WC_ECLAIRAGE], "state_l1", "OFF");
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								moha.php
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								moha.php
									
									
									
									
									
								
							@@ -33,6 +33,7 @@ $logFh = null;					// filehandle of log file
 | 
			
		||||
$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;
 | 
			
		||||
$mqttServerIp = "127.0.0.1";	// IP address of mqttserver in production mode
 | 
			
		||||
if ($testMode)
 | 
			
		||||
{
 | 
			
		||||
@@ -264,9 +265,10 @@ while (true)
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			$hooksInitialized = $i;
 | 
			
		||||
		}else
 | 
			
		||||
		}elseif($flagHooks === false)
 | 
			
		||||
		{
 | 
			
		||||
			logger(DEBUG,_("All hooks initialized"), __FILE__ . ":" . __LINE__);
 | 
			
		||||
			logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__);
 | 
			
		||||
			$flagHooks = true;
 | 
			
		||||
		}
 | 
			
		||||
		checkEvents();
 | 
			
		||||
		askWebServer($read);
 | 
			
		||||
 
 | 
			
		||||
@@ -42,11 +42,11 @@ $callback = function($topic, $message)
 | 
			
		||||
		$fnTree = explode ("/" , $topic[1]); 			// get friendlyname
 | 
			
		||||
		echo $topic[0] . " => " . $topic[1] . EOL;
 | 
			
		||||
		//$devices[$topic[0]][$fnTree[0]]->json = json_decode($message->payload);
 | 
			
		||||
		if ($fnTree[array_key_last($fnTree)] == "availability" and is_string($message->payload))
 | 
			
		||||
		if ($fnTree[array_key_last($fnTree)] == "availability")
 | 
			
		||||
		{
 | 
			
		||||
			unset ($fnTree[array_key_last($fnTree)]);
 | 
			
		||||
			$payloadArray = array("availability" => $message->payload);
 | 
			
		||||
			//print_r($payloadArray);
 | 
			
		||||
			//TODO payload can be a json object
 | 
			
		||||
		}else
 | 
			
		||||
		{
 | 
			
		||||
			$payloadArray = json_decode($message->payload);
 | 
			
		||||
 
 | 
			
		||||
@@ -41,10 +41,10 @@ function mktopic($device)
 | 
			
		||||
	return $device->topic . "/" . $device->friendlyName;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getValue($fn, $property)
 | 
			
		||||
function getValue($ieeeAddress, $property)
 | 
			
		||||
{
 | 
			
		||||
	global $indexDevices;
 | 
			
		||||
	return $indexDevices[$fn]->$property["value"];
 | 
			
		||||
	return $indexDevices[$ieeeAddress]->$property["value"];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function setValue($fn, $property, $value)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user