diff --git a/3rdparty/ponvif.php b/3rdparty/ponvif.php
index f244aff..56904a6 100644
--- a/3rdparty/ponvif.php
+++ b/3rdparty/ponvif.php
@@ -14,7 +14,7 @@
* getDeviceUri() - fixed "deviceuri"
* setDeviceUri() - fixed "deviceuri"
* setMediaUri() - added MediaUri setter
-
+*
* Improved by Cycne 10.06.2017 ( Reference: https://www.onvif.org/ver10/media/wsdl/media.wsdl )
* getCodecEncoders()
* media_GetVideoEncoderConfigurations()
@@ -22,18 +22,25 @@
* media_SetVideoEncoderConfiguration()
* media_GetOSDs()
* media_DeleteOSD()
-* *
+
* FIX by Aidom 30.11.2019
* Correction ONVIF pour JeeDom
* - makeToken()
* - _xml2array
* - _sendrequest
-* - _passwordDigest
+* - _passwordDigest
+
+* Improved by Freddye83 24.03.2021
+* Add function setPTZUri to speed action on ptz (no need initialize())
+
* FIX by Flobul 18.08.2023
* Correction sourcetoken
* Catch error in request method
* Fix discovery method
-*
+
+* Fix by Phpvarious 20.09.2026
+* ptz_GetPresets (PTZPosition on null)
+
**/
class Ponvif {
@@ -84,9 +91,11 @@ public function getMediaUri() {return $this->mediauri;}
public function setMediaUri($mediauri) {$this->mediauri = $mediauri;}
public function getCodecEncoders($codec) {return $this->_getCodecEncoders($codec);}
public function getPTZUri() {return $this->ptzuri;}
+ public function setPTZUri($ptzuri) {$this->ptzuri = $ptzuri; }
public function getBaseUrl() {return $this->baseuri;}
public function getSupportedVersion() {return $this->onvifversion;}
public function getCapabilities() {return $this->capabilities;}
+ public function getProfiles() {return $this->profiles;}
public function setBreakOnError($intransingent) {$this->intransingent = $intransingent;}
public function getLastResponse() {return $this->lastresponse;}
public function setDiscoveryTimeout($discoverytimeout) {$this->discoverytimeout = $discoverytimeout;}
@@ -583,7 +592,7 @@ public function ptz_GetPresets($profileToken) {
foreach ($getpresetsresponse as $preset) {
$presets[] = array('Token' => $preset['@attributes']['token'],
'Name' => $preset['Name'],
- 'PTZPosition' => $preset['PTZPosition']);
+ 'PTZPosition' => isset($preset['PTZPosition']) ? $preset['PTZPosition'] : ""); // by Phpvarious - replace 'PTZPosition' => $preset['PTZPosition']);
}
return $presets;
}
@@ -918,7 +927,7 @@ public function core_SystemReboot()
}
}
- public function ptz_GotoHomePosition($profileToken, $pantilt, $zoom)
+ public function ptz_GotoHomePosition($profileToken, $speed_pantilt_x, $speed_pantilt_y, $speed_zoom_x)
{
if ($this->ptzuri == "") {
return [];
@@ -927,7 +936,7 @@ public function ptz_GotoHomePosition($profileToken, $pantilt, $zoom)
$REQ = $this->_makeToken();
$post_string =
- '
' . __("Assurez-vous que la caméra est sous tension ou redémarrez-la avant de relancer l'analyse.", __FILE__));
+ }
+ log::add(__CLASS__,'debug','[getConfigOnvif] [INFO] Return -> ' . json_encode($return));
+ return array('configuration' => $return);
+ }
+
+ public function createCmdPresetOnvif() {
+ $return = array();
+
+ $token = $this->getConfiguration('cameraStreamProfileToken');
+ if ($token == '') {
+ throw new Exception(__("Le jeton de profil doit être renseigné", __FILE__));
+ }
+
+ $nbCreatepreset = 0;
+
+ $onvif = new ponvif();
+ $onvif->setUsername($this->getConfiguration('username'));
+ $onvif->setPassword($this->getConfiguration('password'));
+ $onvif->setIPAddress($this->getConfiguration('ip') . ':' . $this->getConfiguration('onvif_port', 80));
+
+ try {
+ $onvif->initialize();
+ } catch(Exception $e) {
+ throw new Exception('[createCmdPresetOnvif] KO Etape initialize : ' . $e);
+ }
+ try {
+ $presets = $onvif->ptz_GetPresets($token);
+ } catch(Exception $e) {
+ throw new Exception('[createCmdPresetOnvif] KO Etape ptz_GetPresets(' . $token . ') : ' . $e);
+ }
+ $nbpresetMax = 10;
+ $nbpreset = 1;
+ foreach ($presets as $preset) {
+ if ($nbpreset > $nbpresetMax) break;
+ // Fixes double encoding (Mojibake) caused by the XML server (UTF-8 header but ISO-8859-1 content).
+ // The regex detects broken characters (e.g., "é") and the conversion restores the original accent (e.g., "é").
+ if (is_string($preset['Name']) && preg_match('/[\xC2-\xC3][\x80-\xBF]/', $preset['Name'])) {
+ $preset['Name'] = mb_convert_encoding($preset['Name'], 'ISO-8859-1', 'UTF-8');
+ }
+ $logicalId = 'preset::' . preg_replace("/\s+/", '', $preset['Token']);
+ if (!is_object($this->getCmd(null, $logicalId))) {
+ log::add(__CLASS__,'debug','[createCmdPresetOnvif] [NOTICE] Création du preset avec logicalId ' . $logicalId);
+ $cmdPreset = new cameraCmd();
+ $cmdPreset->setName($preset['Name']);
+ $cmdPreset->setType('action');
+ $cmdPreset->setSubType('other');
+ $cmdPreset->setEqLogic_id($this->getId());
+ $cmdPreset->setConfiguration('token', $preset['Token']);
+ $cmdPreset->setLogicalId($logicalId);
+ try {
+ $cmdPreset->save();
+ } catch (Exception $e) {
+ $cmdPreset->setName($preset['Name'] . rand(0, 9999));
+ $cmdPreset->save();
+ }
+ $nbCreatepreset++;
+ }
+ $nbpreset++;
+ }
+ try {
+ $node = $onvif->ptz_GetNode($token);
+ $homeSupported = $node['HomeSupported'] ?? false;
+ } catch(Exception $e) {
+ throw new Exception('[createCmdPresetOnvif] KO Etape ptz_GetNode(' . $token . ') : ' . $e);
+ }
+ if ($homeSupported) {
+ if (!is_object($this->getCmd(null, 'gotohome'))) {
+ log::add(__CLASS__,'debug','[createCmdPresetOnvif] [NOTICE] Création de la commande gotohome');
+ $cmdGotohome = new cameraCmd();
+ $cmdGotohome->setName('Go to home');
+ $cmdGotohome->setType('action');
+ $cmdGotohome->setSubType('other');
+ $cmdGotohome->setEqLogic_id($this->getId());
+ $cmdGotohome->setLogicalId('gotohome');
+ try {
+ $cmdGotohome->save();
+ } catch (Exception $e) {
+ $cmdGotohome->setName('Go to home' . rand(0, 9999));
+ $cmdGotohome->save();
+ }
+ $nbCreatepreset++;
+ }
+ }
+ $return['createPreset'] = $nbCreatepreset;
+ log::add(__CLASS__,'debug','[createCmdPresetOnvif] [INFO] Return -> ' . json_encode($return));
+ return $return;
+ }
public function decrypt() {
$this->setConfiguration('password', utils::decrypt($this->getConfiguration('password')));
@@ -606,10 +746,10 @@ public function toHtml($_version = 'dashboard', $_fluxOnly = false) {
$sendSnapshot = $this->getCmd(null, 'sendSnapshot');
$recordState = $this->getCmd(null, 'recordState');
$replace_action = array(
- '#record_id#' => $sendSnapshot->getId(),
- '#stopRecord_id#' => $stopRecord->getId(),
- '#recordState#' => $recordState->execCmd(),
- '#recordState_id#' => $recordState->getId(),
+ '#record_id#' => is_object($sendSnapshot) ? $sendSnapshot->getId() : '""',
+ '#stopRecord_id#' => is_object($stopRecord) ? $stopRecord->getId() : '""',
+ '#recordState#' => is_object($recordState) ? $recordState->execCmd() : '0',
+ '#recordState_id#' => is_object($recordState) ? $recordState->getId() : '""',
);
$on = $this->getCmd(null, 'on');
$off = $this->getCmd(null, 'off');
@@ -1065,7 +1205,7 @@ public function execute($_options = null) {
$eqLogic->recordCam($_options['title'], $_options['message']);
return true;
}
- if ($eqLogic->getConfiguration('device') == 'onvif') {
+ if ($eqLogic->getConfiguration('device') == 'onvif' && $request == '') {
$profileToken = $eqLogic->getConfiguration('cameraStreamProfileToken');
$speedX = $eqLogic->getConfiguration('speed_x', 1);
$speedY = $eqLogic->getConfiguration('speed_y', 1);
@@ -1076,7 +1216,11 @@ public function execute($_options = null) {
$onvif->setUsername($eqLogic->getConfiguration('username'));
$onvif->setPassword($eqLogic->getConfiguration('password'));
$onvif->setIPAddress($eqLogic->getConfiguration('ip') . ':' . $eqLogic->getConfiguration('onvif_port', 80));
- $onvif->initialize();
+ try {
+ $onvif->initialize();
+ } catch(Exception $e) {
+ throw new Exception(__("Échec de la connexion ONVIF.", __FILE__) . ' ' . __("Si le problème persiste, redémarrez la caméra.", __FILE__));
+ }
$action = false;
@@ -1113,7 +1257,7 @@ public function execute($_options = null) {
$onvif->core_SystemReboot();
break;
case 'gotohome':
- $onvif->ptz_GotoHomePosition($profileToken, 0, 0);
+ $onvif->ptz_GotoHomePosition($profileToken, $speedX, $speedY, $speedZ);
break;
}
@@ -1124,11 +1268,25 @@ public function execute($_options = null) {
$cmd->execCmd();
}
return true;
+ } else if ($action) {
+ usleep($sleep);
+ $onvif->ptz_Stop($profileToken, 'true', 'true');
+ return true;
+ }
+
+ //////////// Preset /////////////////
+ if (strpos($logicalId, 'preset') !== false) {
+ $presetToken = $this->getConfiguration('token', '');
+ if ($presetToken != '') {
+ $onvif->ptz_GotoPreset($profileToken, $presetToken, $speedX, $speedY, $speedZ);
+ }
}
+ //////////////////////////////////
} catch (Exception $e) {
- log::add(__CLASS__, 'debug', 'onvif error reason for ' . $logicalId . ' : ' . json_encode($onvif->getLastResponse()));
+ log::add('camera', 'debug', 'onvif error reason for ' . $logicalId . ' : ' . json_encode($onvif->getLastResponse()));
}
}
+
if (strpos($request, '#') === 0) {
$cmd = cmd::byId(str_replace('#', '', $request));
if (is_object($cmd)) {
@@ -1144,7 +1302,7 @@ public function execute($_options = null) {
'#port#' => $eqLogic->getConfiguration('port'),
);
$request = str_replace(array_keys($replace), $replace, $request);
- log::add(__CLASS__, 'debug', 'Executing ' . $request);
+ log::add('camera', 'debug', 'Executing ' . $request);
shell_exec($request);
} else {
$http = new com_http($url, $eqLogic->getConfiguration('username'), $eqLogic->getConfiguration('password'));
@@ -1161,4 +1319,4 @@ public function execute($_options = null) {
}
/* * **********************Getteur Setteur*************************** */
-}
+}
\ No newline at end of file
diff --git a/desktop/js/camera.js b/desktop/js/camera.js
index c60418d..7b2f79a 100644
--- a/desktop/js/camera.js
+++ b/desktop/js/camera.js
@@ -1,4 +1,5 @@
+
/* This file is part of Jeedom.
*
* Jeedom is free software: you can redistribute it and/or modify
@@ -19,9 +20,16 @@ $('#bt_healthCamera').on('click', function() {
$('#md_modal').load('index.php?v=d&plugin=camera&modal=health').dialog('open')
})
-$('#bt_discoverCam').on('click', function() {
- $('#md_modal').dialog({ title: "{{Découverte Caméras}}" })
- $('#md_modal').load('index.php?v=d&plugin=camera&modal=discover.cam').dialog('open')
+document.getElementById('div_pageContainer')?.addEventListener('click', function(event) {
+ let _target = null
+ if (_target = event.target.closest('#bt_discoverCam')) {
+ jeeDialog.dialog({
+ id: 'jee_modal',
+ title: "{{Découverte Caméras}}",
+ contentUrl: 'index.php?v=d&plugin=camera&modal=discover.cam',
+ })
+ return
+ }
})
$('#bt_previewCam').off('click').on('click', function() {
@@ -60,6 +68,111 @@ $('#div_pageContainer').off('click', '.listCmdActionOther').on('click', '.listCm
})
})
+//// Analyse Onvif \\\\
+document.querySelector('.analyseOnvif').addEventListener('click', function(event) {
+ if (is_object(eqLogic = document.querySelector('.eqLogicAttr[data-l1key=id]'))) {
+ let eqLogicId = eqLogic.jeeValue()
+ if (eqLogicId != '' && eqLogicId != null) {
+ domUtils.ajax({
+ type: 'POST',
+ url: 'plugins/camera/core/ajax/camera.ajax.php',
+ data: {
+ action: 'getConfigOnvif',
+ id: eqLogicId
+ },
+ dataType: 'json',
+ error: function(request, status, error) {
+ handleAjaxError(request, status, error)
+ },
+ success: function (data) {
+ if (data.state != 'ok') {
+ jeedomUtils.showAlert({
+ title: "Camera",
+ message: data.result,
+ level: 'danger'
+ });
+ return
+ }
+ if (!data.result) {
+ jeedomUtils.showAlert({
+ title: "Camera",
+ message: "{{Camera Onvif introuvable}}",
+ level: 'danger'
+ });
+ return;
+ }
+
+ let selector
+ for (let l1key in data.result) {
+ for (let l2key in data.result[l1key]) {
+ selector = '.eqLogicAttr[data-l1key="' + l1key.replaceAll('"', '') + '"][data-l2key="' + l2key.replaceAll('"', '') + '"]'
+ document.querySelectorAll(selector).forEach(_selector => {
+ if (_selector.jeeValue() == '') {
+ _selector.style.setProperty('background', 'rgba(248, 216, 0, 0.25)', 'important');
+ _selector.jeeValue(data.result[l1key][l2key])
+ }
+ })
+ }
+ }
+ jeedomUtils.showAlert({
+ title: "Camera",
+ message: "{{Veuillez enregistrer les modifications}}",
+ level: 'info'
+ });
+ }
+ });
+ }
+ }
+})
+
+//// Create command preset onvif \\\\
+document.querySelector('.createCmdPresetOnvif').addEventListener('click', function(event) {
+ if (is_object(eqLogic = document.querySelector('.eqLogicAttr[data-l1key=id]'))) {
+ let eqLogicId = eqLogic.jeeValue()
+ if (eqLogicId != '' && eqLogicId != null) {
+ domUtils.ajax({
+ type: 'POST',
+ url: 'plugins/camera/core/ajax/camera.ajax.php',
+ data: {
+ action: 'createCmdPresetOnvif',
+ id: eqLogicId
+ },
+ dataType: 'json',
+ error: function(request, status, error) {
+ handleAjaxError(request, status, error)
+ },
+ success: function (data) {
+ if (data.state != 'ok') {
+ jeedomUtils.showAlert({
+ title: "Camera",
+ message: data.result,
+ level: 'danger'
+ });
+ return
+ }
+ if (!data.result) {
+ jeedomUtils.showAlert({
+ title: "Camera",
+ message: "{{Camera Onvif introuvable}}",
+ level: 'danger'
+ });
+ return;
+ }
+ if (isset(data.result.createPreset) && data.result.createPreset > 0) {
+ window.location.href='index.php?v=d&m=camera&p=camera&id=' + eqLogicId + '&saveSuccessFull=1#commandtab'
+ } else {
+ jeedomUtils.showAlert({
+ title: "Preset",
+ message: "{{Aucun preset importé}}",
+ level: 'info'
+ });
+ }
+ }
+ });
+ }
+ }
+})
+
function addCmdToTable(_cmd) {
if (!isset(_cmd)) {
var _cmd = {}
@@ -137,7 +250,6 @@ $('#table_cmd tbody').on('change', '.cmd .cmdAttr[data-l1key=type]', function()
}
})
-
$('#bt_removeAllCapture').on('click', function() {
bootbox.confirm('{{Etes-vous sur de vouloir supprimer toutes les captures de la caméra ?}}', function(result) {
if (result) {
diff --git a/desktop/modal/discover.cam.php b/desktop/modal/discover.cam.php
index 5cf67db..d5c8b14 100644
--- a/desktop/modal/discover.cam.php
+++ b/desktop/modal/discover.cam.php
@@ -2,15 +2,16 @@
if (!isConnect('admin')) {
throw new Exception('{{401 - Accès non autorisé}}');
}
-$discover_cameras = camera::discoverCam();
?>
| {{Protocole}} | {{IP}} | +{{Port}} | {{Découverte}} | {{Type}} | {{Nom d'utilisateur}} | @@ -20,71 +21,65 @@'; - echo '' . $cam['ip'] . ''; - echo ' | '; - echo ''; - echo '' . $cam['discover'] . ''; - echo ' | '; - echo ''; - echo $cam['type']; - echo ' | '; - echo ''; - if ($cam['exist'] === false) { - echo ''; - } else { - echo 'NA'; - } - echo ' | '; - echo ''; - if ($cam['exist'] === false) { - echo ''; - } else { - echo 'NA'; - } - echo ' | '; - echo ''; - if ($cam['exist'] === false) { - echo ' {{Ajouter}}'; - } - echo ' | '; - echo ''; - } - ?> +foreach (camera::discoverCam() as $cam) { + echo '
|---|---|---|---|---|---|---|---|---|
| '; + echo '' . $cam['protocole'] . ''; + echo ' | '; + echo ''; + echo '' . $cam['ip'] . ''; + echo ' | '; + echo ''; + echo '' . $cam['port'] . ''; + echo ' | '; + echo ''; + echo '' . $cam['discover'] . ''; + echo ' | '; + echo ''; + echo $cam['type']; + echo ' | '; + echo ''; + echo ' | '; + if ($cam['exist'] === false) { + echo ' | {{Ajouter}} | '; + } else { + echo '{{Ajouter}} | '; + } + echo '