From 4acb2992ca7f106a08ce2d8e0fcb4f5c07ca6d1e Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Mon, 5 Sep 2022 13:47:41 +0200 Subject: [PATCH] debug --- class/main.php | 3 +- config/devices_constants.php | 1 + config/liste_telephones.php | 7 ++-- config/properties2log.php | 3 +- config/users.php | 11 ++++++ daemons/presenceDaemon.php | 5 +-- hooks/notifiers/notificationfreemobile.php | 4 +-- hooks/scripts/rdc_portes_ouvertes.php | 4 +-- hooks/scripts/rdc_store.php | 41 ++++++++++++---------- hooks/scripts/rdc_store.php~ | 41 ++++++++++++---------- hooks/scripts/test_portes.php | 2 +- presence.php | 4 +-- topics_callbacks/pws2mqtt.php | 3 +- topics_callbacks/zigbee2mqtt.php | 3 +- utils.php | 3 +- 15 files changed, 82 insertions(+), 53 deletions(-) create mode 100644 config/users.php diff --git a/class/main.php b/class/main.php index b046e14..56a6892 100644 --- a/class/main.php +++ b/class/main.php @@ -37,6 +37,7 @@ class device public $triggerDevice; public $properties = array(); public $lastSeen; + public $users2notify = array(); public function __construct() { @@ -141,7 +142,7 @@ class watch { logger(DEBUG, _("notifyCallback")); $msg = sprintf(_("Device '%s' have property '%s' value %s %s %s"), $device->friendlyName, $property, bool2string($value), $this->condition, bool2string($this->PropertyValue) ); - notify($msg); + notify($msg, $device); } } } diff --git a/config/devices_constants.php b/config/devices_constants.php index f0e3124..389aea8 100644 --- a/config/devices_constants.php +++ b/config/devices_constants.php @@ -51,6 +51,7 @@ $deviceTable = array( "0x04cf8cdf3c7b6056" => "RDC_CHAMBRE_LUMINOSITE", "0x00158d0006c0447c" => "RDC_CHAMBRE_ARMOIRE_GAUCHE", "0x842e14fffe9be0fc" => "RDC_STORE", + "0xa4c138165e31c0e8" => "RDC_STORE_VIBRATION", "0x04cf8cdf3c7b3d64" => "RDC_EXTERIEUR_LUMINOSITE", "0x483fda53cbcb" => "METEO" ); diff --git a/config/liste_telephones.php b/config/liste_telephones.php index 07eb8ee..9e0650f 100644 --- a/config/liste_telephones.php +++ b/config/liste_telephones.php @@ -1,9 +1,10 @@ "E8:78:29:C2:79:22", -"Maryclaire" => "D0:9C:7A:DA:8E:D8", -"Terence" => "26:4D:40:5F:1E:10" +"E8:78:29:C2:79:22" => "Daniel", +"D0:9C:7A:DA:8E:D8" => "Maryclaire", +"FA:61:B1:D8:3C:D4" => "Maryclaire", +"26:4D:40:5F:1E:10" => "Terence" ); ?> diff --git a/config/properties2log.php b/config/properties2log.php index 67db416..9a82680 100644 --- a/config/properties2log.php +++ b/config/properties2log.php @@ -36,6 +36,7 @@ $properties2log = array( "indoortempc" => 0.5, "indoorhumidity" => 0.5, "baromin" => 10, - "presence" => null + "presence" => null, + "vibration" => null ); diff --git a/config/users.php b/config/users.php new file mode 100644 index 0000000..cc95c34 --- /dev/null +++ b/config/users.php @@ -0,0 +1,11 @@ + + + diff --git a/daemons/presenceDaemon.php b/daemons/presenceDaemon.php index 1049e4c..6f4bc52 100755 --- a/daemons/presenceDaemon.php +++ b/daemons/presenceDaemon.php @@ -17,7 +17,7 @@ $command = "sudo nmap -n -sP 192.168.1.*"; //need to configure /etc/sudo/sudoer echo "presenceDaemon is starting\n"; // init du tableau des présences à -1 -foreach($macAddresses as $nom => $mac) +foreach($macAddresses as $mac => $nom) { $presence[$nom] = -1; } @@ -46,6 +46,7 @@ while (1) echo $nom . " est modifié dans tableau\n"; } } + $result = array(); sleep(1); } @@ -53,7 +54,7 @@ function search($string) { global $macAddresses, $presenceTemp; //echo "searching in " . $string . EOL; - foreach ($macAddresses as $nom => $needle) + foreach ($macAddresses as $needle => $nom) { //echo $nom ." => " . $needle . EOL; if (str_contains($string, $needle)) diff --git a/hooks/notifiers/notificationfreemobile.php b/hooks/notifiers/notificationfreemobile.php index 76ea45f..abf15d5 100644 --- a/hooks/notifiers/notificationfreemobile.php +++ b/hooks/notifiers/notificationfreemobile.php @@ -9,7 +9,7 @@ class notificationFreemobile public $lastTry; public $lastTryTimeout = 5; protected $dest = array( - "daniel" => "15480189&pass=yVpPmCWmUl2HGp", + "Daniel" => "15480189&pass=yVpPmCWmUl2HGp", ); function __construct() @@ -27,7 +27,7 @@ class notificationFreemobile curl_setopt($ch, CURLOPT_URL, $this->url . $this->dest[$destinataire] . "&msg=" . urlencode(trim($message))); // return the transfer as a string - //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // $result contains the output string if ($this->curlErr <= 5) { diff --git a/hooks/scripts/rdc_portes_ouvertes.php b/hooks/scripts/rdc_portes_ouvertes.php index 35abbf6..dc9e2e8 100644 --- a/hooks/scripts/rdc_portes_ouvertes.php +++ b/hooks/scripts/rdc_portes_ouvertes.php @@ -33,10 +33,10 @@ class alerte_intrusion extends hook { if ($value == false and isPresent() === false) { - logger(ALERT, sprintf(_("%s vient de s'ouvrir alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__); + logger(ALERT, sprintf(_("%s vient de s'ouvrir alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__, $device); }else { - logger(ALERT, sprintf(_("%s vient de se fermer alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__); + logger(ALERT, sprintf(_("%s vient de se fermer alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__, $device); } } break; diff --git a/hooks/scripts/rdc_store.php b/hooks/scripts/rdc_store.php index 719f879..254ede4 100644 --- a/hooks/scripts/rdc_store.php +++ b/hooks/scripts/rdc_store.php @@ -11,10 +11,12 @@ class rdc_store extends hook public $storeUpTime = 41; public $maxLevel; public $storeLevel; + public $motorReversal = false; protected $propertyInitialized =array(); protected $devicelist = array( RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux", RDC_SALON_LUMINOSITE => "illuminance_lux", + RDC_STORE_VIBRATION => "vibration", METEO => "rainin", METEO => "solarradiation", METEO => "windspeedkmh", @@ -46,7 +48,6 @@ class rdc_store extends hook //$this->maxLevel = 100; $r = 100; $moving = "STOP"; - $motorReversal = false; $store2level = false; if (array_key_exists("moving", $storeDevice->properties)) @@ -58,19 +59,19 @@ class rdc_store extends hook { if ($storeDevice->properties["motor_reversal"]["value"] == "ON") { - $motorReversal = true; + $this->motorReversal = true; }else { - $motorReversal = false; + $this->motorReversal = false; } - logger(DEBUG, "Motor reversal =" . bool2string($motorReversal), __FILE__ . ":" . __LINE__); + logger(DEBUG, "Motor reversal =" . bool2string($this->motorReversal), __FILE__ . ":" . __LINE__); } - if ($moving == "STOP") + if ($moving == "STOP" or $moving == null) { if (array_key_exists("position", $storeDevice->properties)) { - if ($motorReversal) + if ($this->motorReversal) { $this->storeLevel = $storeDevice->properties["position"]["value"]; }else @@ -97,7 +98,7 @@ class rdc_store extends hook { if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50) { - logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__); + logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device); } $rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6); if ($rafale == 0) @@ -110,7 +111,7 @@ class rdc_store extends hook { if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50) { - logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__); + logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__, $device); } $vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6); if ($vent == 0) @@ -154,7 +155,7 @@ class rdc_store extends hook logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__); if ($this->maxLevel != 0 and $salon_lux > 100) { - $store2level = $this->storeLevel + 15; + $store2level = $this->storeLevel + 20; } }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100) { @@ -174,13 +175,7 @@ class rdc_store extends hook //calcul du maxlevel par rapport a la vitesse des rafales $r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10; if ($r < 0) $r = 0; - if ($motorReversal) - { - $this->maxLevel = $r; - }else - { - $this->maxLevel = 100 - $r; - } + $this->maxLevel = 100 - $r; logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); } logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__); @@ -191,9 +186,15 @@ class rdc_store extends hook logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__); $this->close("Pluie"); break; - case "windgustkmh"; + case "windgustkmh": logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__); break; + case "vibration": + $tmpStore = $this->storeLevel - 20; + if ($store2level == false or $store2level > $tmpStore) + { + $this->setTo($store2level, AUTO); + } default: } logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); @@ -222,10 +223,14 @@ class rdc_store extends hook private function setTo($level, $method) { logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__); + if (!$this->motorReversal) + { + $level = 100 - $level; + } if ($level <= 100) { logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__); - $this->send(100 - $level, $method); + $this->send($level, $method); }//else /*{ logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__); diff --git a/hooks/scripts/rdc_store.php~ b/hooks/scripts/rdc_store.php~ index 4b6c6eb..66f7a10 100644 --- a/hooks/scripts/rdc_store.php~ +++ b/hooks/scripts/rdc_store.php~ @@ -11,10 +11,12 @@ class rdc_store extends hook public $storeUpTime = 41; public $maxLevel; public $storeLevel; + public $motorReversal = false; protected $propertyInitialized =array(); protected $devicelist = array( RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux", RDC_SALON_LUMINOSITE => "illuminance_lux", + RDC_STORE_VIBRATION => "vibration", METEO => "rainin", METEO => "solarradiation", METEO => "windspeedkmh", @@ -46,7 +48,6 @@ class rdc_store extends hook //$this->maxLevel = 100; $r = 100; $moving = "STOP"; - $motorReversal = false; $store2level = false; if (array_key_exists("moving", $storeDevice->properties)) @@ -58,19 +59,19 @@ class rdc_store extends hook { if ($storeDevice->properties["motor_reversal"]["value"] == "ON") { - $motorReversal = true; + $this->motorReversal = true; }else { - $motorReversal = false; + $this->motorReversal = false; } - logger(DEBUG, "Motor reversal =" . bool2string($motorReversal), __FILE__ . ":" . __LINE__); + logger(DEBUG, "Motor reversal =" . bool2string($this->motorReversal), __FILE__ . ":" . __LINE__); } - if ($moving == "STOP") + if ($moving == "STOP" or $moving == null) { if (array_key_exists("position", $storeDevice->properties)) { - if ($motorReversal) + if ($this->motorReversal) { $this->storeLevel = $storeDevice->properties["position"]["value"]; }else @@ -154,11 +155,11 @@ class rdc_store extends hook logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__); if ($this->maxLevel != 0 and $salon_lux > 100) { - $store2level = $this->storeLevel + 15; + $store2level = $this->storeLevel + 20; } - }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 100 and $soleil < 100) + }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100) { - logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 100 and soleil < 100", __FILE__ . ":" . __LINE__); + logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100", __FILE__ . ":" . __LINE__); $this->close("Luminosité faible"); } @@ -174,13 +175,7 @@ class rdc_store extends hook //calcul du maxlevel par rapport a la vitesse des rafales $r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10; if ($r < 0) $r = 0; - if ($motorReversal) - { - $this->maxLevel = $r; - }else - { - $this->maxLevel = 100 - $r; - } + $this->maxLevel = 100 - $r; logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); } logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__); @@ -191,9 +186,15 @@ class rdc_store extends hook logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__); $this->close("Pluie"); break; - case "windgustkmh"; + case "windgustkmh": logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__); break; + case "vibration": + $tmpStore = $this->storeLevel - 20; + if ($store2level == false or $store2level > $tmpStore) + { + $this->setTo($store2level, AUTO); + } default: } logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); @@ -222,10 +223,14 @@ class rdc_store extends hook private function setTo($level, $method) { logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__); + if (!$this->motorReversal) + { + $level = 100 - $level; + } if ($level <= 100) { logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__); - $this->send(100 - $level, $method); + $this->send($level, $method); }//else /*{ logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__); diff --git a/hooks/scripts/test_portes.php b/hooks/scripts/test_portes.php index a412e1c..7e29312 100644 --- a/hooks/scripts/test_portes.php +++ b/hooks/scripts/test_portes.php @@ -50,7 +50,7 @@ class test_portes extends hook } if ($send) { - logger(ALERT, _("doors opened :") . $msg, null ,$device); + logger(ALERT, _("doors opened :") . $msg, null, $device); } return $portes; } diff --git a/presence.php b/presence.php index 25d5a0b..172a1b3 100644 --- a/presence.php +++ b/presence.php @@ -1,6 +1,6 @@ $mac) +foreach($macAddresses as $mac => $nom) { $presence[$nom] = false; } @@ -23,7 +23,7 @@ function presence($argList) { return _("Le paramètre 'presence' est obligatoire
present&nom=&presence=") . EOLH; } - var_dump($presence); + //var_dump($presence); if (!array_key_exists($name, $presence)) { return sprintf(_("Ce nom (%s) n'existe pas dans la base."), $name) . EOLH; diff --git a/topics_callbacks/pws2mqtt.php b/topics_callbacks/pws2mqtt.php index ab5ba94..9f42c52 100644 --- a/topics_callbacks/pws2mqtt.php +++ b/topics_callbacks/pws2mqtt.php @@ -5,7 +5,9 @@ if (!array_key_exists("pws2mqtt", $devices)) $devices["pws2mqtt"] = array(); function pws2mqttCallback($topic, $message) { global $logFh, $devices, $included, $topics; + $topicName = $topic[0]; + $topics[$topicName]->lastSeen = time(); $fn = $topic[1]; logger(INFO, sprintf(_("Incoming notification of device %s => friendly name : %s"), $topicName, $fn), __FILE__ . ":" . __LINE__); $device = & $devices[$topicName]; @@ -30,7 +32,6 @@ function pws2mqttCallback($topic, $message) { $device = &$device[$fn]; } - $topics[$topicName]->lastSeen = time(); unset($payloadArray["friendly_name"]); unset($payloadArray["ieeeAddress"]); unset($payloadArray["type"]); diff --git a/topics_callbacks/zigbee2mqtt.php b/topics_callbacks/zigbee2mqtt.php index 3bccb2e..e213989 100644 --- a/topics_callbacks/zigbee2mqtt.php +++ b/topics_callbacks/zigbee2mqtt.php @@ -6,7 +6,8 @@ if (!array_key_exists("zigbee2mqtt", $devices)) $devices["zigbee2mqtt"] = array function zigbee2mqttCallback($topic, $message) { global $topics, $devices, $included, $logFh, $indexFriendlyNames, $devicesRequest; - + + logger(DEBUG, _("CallBack Zigbee2mqtt"), __FILE__ . ":" . __LINE__); $topics[$topic[0]]->lastSeen = time(); if ($topic[1] == "bridge") { diff --git a/utils.php b/utils.php index 7956786..16dfeac 100644 --- a/utils.php +++ b/utils.php @@ -24,12 +24,13 @@ function checkTopicsAvailability() { if ($topic->status == 1) { - logger(DEBUG, "time is " . time() . " lastSeen is " . $topic->lastSeen, __FILE__ . ":" . __LINE__ ); + logger(DEBUG, "Topic is :" . $topicName . " and time is " . time() . " lastSeen is " . $topic->lastSeen, __FILE__ . ":" . __LINE__ ); if ((time() - $topic->lastSeen > $topic->timeOut*60) and ($topic->notificationSent == false)) { if (logger(ALERT, $topicName . _(" is not available"), __FILE__ . ":" . __LINE__) == false); { $topic->notificationSent = true; + //system("systemctl restart ") } } }