Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions core/api/mobile.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,37 +523,39 @@ function saveMenuFromAppV2($menu, $mobile)
}
} else log::add('mobile', 'debug', '| [WARNING] Action unknown ─▶︎ ' . $geofence['action']);
} else log::add('mobile', 'debug', '| [ERROR] geofencing command unknown ─▶︎ ' . 'geoloc_' . $geofence['identifier']);
} else {
$transmitions = $params['transmition'];
$errorCount = 0;
foreach ($transmitions as $transmition) {
$mobile->cmdForSpecificChannel($params, 'transmition');
} else if (is_array($transmitions = $params['transmition'])) {
log::add('mobile', 'debug', '| [INFO] transmition is array');
$nbTransmition = count($transmitions);
foreach ($transmitions as $key => $transmition) {
log::add('mobile', 'debug', '|┌────────── [' . $key . '] ──────────');
if (isset($transmition['event']) && $transmition['event'] == 'geofence') {
log::add('mobile', 'debug', '| Transmition : ' . json_encode($params['transmition']));
log::add('mobile', 'debug', '|| Event ─▶︎ ' . $transmition['event']);
$geofence = $transmition['geofence'];
log::add('mobile', 'debug', '| Geofence ─▶︎ ' . json_encode($geofence));
log::add('mobile', 'debug', '|| Geofence ─▶︎ ' . json_encode($geofence));
$cmdgeoloc = cmd::byEqLogicIdAndLogicalId($mobile->getId(), 'geoloc_' . $geofence['identifier']);
if (is_object($cmdgeoloc)) {
if ($geofence['action'] == 'ENTER' || $geofence['action'] == 'EXIT') {
$eventAge = time() - intval(strtotime($geofence['timestamp']));
if ($eventAge > 1800) {
log::add('mobile', 'debug', '| [WARNING] SKIP stale event (' . round($eventAge / 60) . 'min)');
log::add('mobile', 'debug', '|| [WARNING] SKIP stale event (' . round($eventAge / 60) . 'min)');
} else {
$value = ($geofence['action'] == 'ENTER') ? 1 : 0;
log::add('mobile', 'debug', '| OK Command "' . $cmdgeoloc->getName() . '" ( geoloc_' . $geofence['identifier'] . ' ) ─▶︎ ' . $value . ' ( eventAge = ' . $eventAge . 'sec )');
log::add('mobile', 'debug', '|| OK Command "' . $cmdgeoloc->getName() . '" ( geoloc_' . $geofence['identifier'] . ' ) ─▶︎ ' . $value . ' ( eventAge = ' . $eventAge . 'sec )');
$mobile->checkAndUpdateCmd('geoloc_' . $geofence['identifier'], $value);
}
} else log::add('mobile', 'debug', '| [WARNING] Action unknown ─▶︎ ' . $geofence['action']);
} else log::add('mobile', 'debug', '| [ERROR] geofencing command unknown ─▶︎ ' . 'geoloc_' . $geofence['identifier']);
} else $errorCount++;
}
if ($errorCount > 0) {
log::add('mobile', 'debug', '| [ERROR] No geofencing settings');
} else log::add('mobile', 'debug', '|| [WARNING] Action unknown ─▶︎ ' . $geofence['action']);
} else log::add('mobile', 'debug', '|| [ERROR] geofencing command unknown ─▶︎ ' . 'geoloc_' . $geofence['identifier']);
} else log::add('mobile', 'debug', '|| [ERROR] No geofencing settings');
log::add('mobile', 'debug', '|└────────────────────────');
if ($key == $nbTransmition - 1) {
$mobile->cmdForSpecificChannel($transmitions, $key);
}
}
}
$mobile->cmdForSpecificChannel($params, 'transmition');
}
} else {
if (isset($params['Iq'])) llog::add('mobile', 'debug', '| [ERROR] EqLogic unknown ─▶︎ ' . $params['Iq']);
if (isset($params['Iq'])) log::add('mobile', 'debug', '| [ERROR] EqLogic unknown ─▶︎ ' . $params['Iq']);
else log::add('mobile', 'debug', '[WARNING] Parameter Iq does not exist !');
}
log::add('mobile', 'debug', '└───────────────────────────────────────────');
Expand Down
246 changes: 122 additions & 124 deletions core/class/mobile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ public static function createCmdGeoLocV2($Iq, $geolocs)
foreach ($decodedGeolocs as $index => $geoloc) {
if (!isset($geoloc['name'])) continue;
$logicalId = 'geoloc_' . $index;
log::add('mobile', 'debug', '|| ' . $logicalId . ' ─▶︎ ' . $geoloc['name']);
log::add('mobile', 'debug', '|| ' . $logicalId . ' ─▶︎ ' . $geoloc['name'] . ' ─▶︎ ' . $geoloc['value']);
$cmd = cmd::byEqLogicIdAndLogicalId($mobile->getId(), 'geoloc_' . $index);
if (!is_object($cmd)) {
//Migrate geoloc logicalId by name
Expand Down Expand Up @@ -1399,138 +1399,136 @@ public static function getQrCodeV2($userId)
public function cmdForSpecificChannel($params = array(), $_trigger = 'location')
{
log::add('mobile', 'debug', '|┌──:fg-success: cmdForSpecificChannel :/fg:──');
if (isset($params['Iq'])) {
if (isset($params[$_trigger])) {
$order = count($this->getCmd());
$getDeviceInformations = (isset($params[$_trigger]['extras']) && isset($params[$_trigger]['extras']['method']) && $params[$_trigger]['extras']['method'] == 'getDeviceInformations');
$eventAge = time() - intval(strtotime($params[$_trigger]['timestamp']));
if ($eventAge > 1800) {
log::add('mobile', 'debug', '|| SKIP stale specific event (' . round($eventAge / 60) . 'min) ');
} else {
log::add('mobile', 'debug', '|| eventAge = ' . $eventAge . ' s');
// Battery
if (isset($params[$_trigger]['battery'])) {
// level
if (isset($params[$_trigger]['battery']['level'])) {
if ($getDeviceInformations) {
$cmd = $this->getCmd(null, 'battery::level');
if (!is_object($cmd)) {
$cmd = new mobileCmd();
$cmd->setLogicalId('battery::level');
$cmd->setName(__('Batterie du téléphone', __FILE__));
$cmd->setDisplay('icon', '<i class="icon fas fa-battery-three-quarters"></i>');
$cmd->setDisplay('showIconAndNamedashboard', 1);
$cmd->setDisplay('showIconAndNamemobile', 1);
$cmd->setDisplay('forceReturnLineAfter', 1);
$cmd->setConfiguration('historizeRound', 2);
$cmd->setConfiguration('minValue', 0);
$cmd->setConfiguration('maxValue', 100);
$cmd->setUnite('%');
$cmd->setIsVisible(0);
$cmd->setOrder($order);
$order++;
log::add('mobile', 'debug', '|| Creating the "phone battery" command');
}
$cmd->setEqLogic_id($this->getId());
$cmd->setType('info');
$cmd->setConfiguration('calculValueOffset', '#value# * 100');
$cmd->setSubType('numeric');
if ($cmd->getChanged() === true) $cmd->save();
}
if ($params[$_trigger]['battery']['level'] != -1) {
if ($this->checkAndUpdateCmd('battery::level', $params[$_trigger]['battery']['level'])) {
log::add('mobile', 'debug', '|| Updating "phone battery" value ─▶︎ ' . $params[$_trigger]['battery']['level'] * 100 . '%');
}
} else {
log::add('mobile', 'debug', '|| [WARNING] No data available for battery level ─▶︎ ' . $params[$_trigger]['battery']['level']);
if (isset($params[$_trigger])) {
$order = count($this->getCmd());
$getDeviceInformations = (isset($params[$_trigger]['extras']) && isset($params[$_trigger]['extras']['method']) && $params[$_trigger]['extras']['method'] == 'getDeviceInformations');
$eventAge = time() - intval(strtotime($params[$_trigger]['timestamp']));
if ($eventAge > 1800) {
log::add('mobile', 'debug', '|| SKIP stale specific event (' . round($eventAge / 60) . 'min) ');
} else {
log::add('mobile', 'debug', '|| eventAge = ' . $eventAge . ' s');
// Battery
if (isset($params[$_trigger]['battery'])) {
// level
if (isset($params[$_trigger]['battery']['level'])) {
if ($getDeviceInformations) {
$cmd = $this->getCmd(null, 'battery::level');
if (!is_object($cmd)) {
$cmd = new mobileCmd();
$cmd->setLogicalId('battery::level');
$cmd->setName(__('Batterie du téléphone', __FILE__));
$cmd->setDisplay('icon', '<i class="icon fas fa-battery-three-quarters"></i>');
$cmd->setDisplay('showIconAndNamedashboard', 1);
$cmd->setDisplay('showIconAndNamemobile', 1);
$cmd->setDisplay('forceReturnLineAfter', 1);
$cmd->setConfiguration('historizeRound', 2);
$cmd->setConfiguration('minValue', 0);
$cmd->setConfiguration('maxValue', 100);
$cmd->setUnite('%');
$cmd->setIsVisible(0);
$cmd->setOrder($order);
$order++;
log::add('mobile', 'debug', '|| Creating the "phone battery" command');
}
$cmd->setEqLogic_id($this->getId());
$cmd->setType('info');
$cmd->setConfiguration('calculValueOffset', '#value# * 100');
$cmd->setSubType('numeric');
if ($cmd->getChanged() === true) $cmd->save();
}
// charging
if (isset($params[$_trigger]['battery']['is_charging'])) {
if ($getDeviceInformations) {
$cmd = $this->getCmd(null, 'battery::isCharging');
if (!is_object($cmd)) {
$cmd = new mobileCmd();
$cmd->setLogicalId('battery::isCharging');
$cmd->setName(__('En charge', __FILE__));
$cmd->setDisplay('icon', '<i class="icon techno-charging"></i>');
$cmd->setDisplay('showIconAndNamedashboard', 1);
$cmd->setDisplay('showIconAndNamemobile', 1);
$cmd->setDisplay('forceReturnLineAfter', 1);
$cmd->setTemplate('dashboard', 'core::line');
$cmd->setTemplate('mobile', 'core::line');
$cmd->setIsVisible(0);
$cmd->setOrder($order);
$order++;
log::add('mobile', 'debug', '|| Creating the "in charge" command');
}
$cmd->setEqLogic_id($this->getId());
$cmd->setType('info');
$cmd->setSubType('binary');
if ($cmd->getChanged() === true) $cmd->save();
}
if ($this->checkAndUpdateCmd('battery::isCharging', intval($params[$_trigger]['battery']['is_charging']))) {
log::add('mobile', 'debug', '|| Updating "in charge" value ─▶︎ ' . intval($params[$_trigger]['battery']['is_charging']));
if ($params[$_trigger]['battery']['level'] != -1) {
if ($this->checkAndUpdateCmd('battery::level', $params[$_trigger]['battery']['level'])) {
log::add('mobile', 'debug', '|| Updating "phone battery" value ─▶︎ ' . $params[$_trigger]['battery']['level'] * 100 . '%');
}
} else {
log::add('mobile', 'debug', '|| [WARNING] No data available for battery level ─▶︎ ' . $params[$_trigger]['battery']['level']);
}
}
// coords
if (isset($params[$_trigger]['coords'])) {
if (isset($params[$_trigger]['coords']['latitude']) && isset($params[$_trigger]['coords']['longitude'])) {
if ($getDeviceInformations) {
$cmd = $this->getCmd(null, 'coords');
if (!is_object($cmd)) {
$cmd = new mobileCmd();
$cmd->setLogicalId('coords');
$cmd->setName(__('Coordonnées', __FILE__));
$cmd->setDisplay('icon', '<i class="icon fas fa-map-marker-alt"></i>');
$cmd->setDisplay('showIconAndNamedashboard', 1);
$cmd->setDisplay('showIconAndNamemobile', 1);
$cmd->setDisplay('forceReturnLineAfter', 1);
$cmd->setTemplate('dashboard', 'core::line');
$cmd->setTemplate('mobile', 'core::line');
$cmd->setIsVisible(0);
$cmd->setOrder($order);
$order++;
log::add('mobile', 'debug', '|| Creating the "coordinates" command');
}
$cmd->setEqLogic_id($this->getId());
$cmd->setType('info');
$cmd->setSubType('string');
if ($cmd->getChanged() === true) $cmd->save();
}
$coord = $params[$_trigger]['coords']['latitude'] . ',' . $params[$_trigger]['coords']['longitude'];
if ($this->checkAndUpdateCmd('coords', $coord)) {
log::add('mobile', 'debug', '|| Updating "coordinates" value ─▶︎ ' . $coord);
// charging
if (isset($params[$_trigger]['battery']['is_charging'])) {
if ($getDeviceInformations) {
$cmd = $this->getCmd(null, 'battery::isCharging');
if (!is_object($cmd)) {
$cmd = new mobileCmd();
$cmd->setLogicalId('battery::isCharging');
$cmd->setName(__('En charge', __FILE__));
$cmd->setDisplay('icon', '<i class="icon techno-charging"></i>');
$cmd->setDisplay('showIconAndNamedashboard', 1);
$cmd->setDisplay('showIconAndNamemobile', 1);
$cmd->setDisplay('forceReturnLineAfter', 1);
$cmd->setTemplate('dashboard', 'core::line');
$cmd->setTemplate('mobile', 'core::line');
$cmd->setIsVisible(0);
$cmd->setOrder($order);
$order++;
log::add('mobile', 'debug', '|| Creating the "in charge" command');
}
$cmd->setEqLogic_id($this->getId());
$cmd->setType('info');
$cmd->setSubType('binary');
if ($cmd->getChanged() === true) $cmd->save();
}
if (isset($params[$_trigger]['coords']['altitude'])) {
if ($getDeviceInformations) {
$cmd = $this->getCmd(null, 'altitude');
if (!is_object($cmd)) {
$cmd = new mobileCmd();
$cmd->setLogicalId('altitude');
$cmd->setName(__('Altitude', __FILE__));
$cmd->setDisplay('icon', '<i class="icon fas fa-map-marked-alt"></i>');
$cmd->setDisplay('showIconAndNamedashboard', 1);
$cmd->setDisplay('showIconAndNamemobile', 1);
$cmd->setDisplay('forceReturnLineAfter', 1);
$cmd->setTemplate('dashboard', 'core::line');
$cmd->setTemplate('mobile', 'core::line');
$cmd->setIsVisible(0);
$cmd->setUnite('m');
$cmd->setOrder($order);
$order++;
log::add('mobile', 'debug', '|| Creating the "altitude" command');
}
$cmd->setEqLogic_id($this->getId());
$cmd->setType('info');
$cmd->setSubType('string');
if ($cmd->getChanged() === true) $cmd->save();
if ($this->checkAndUpdateCmd('battery::isCharging', intval($params[$_trigger]['battery']['is_charging']))) {
log::add('mobile', 'debug', '|| Updating "in charge" value ─▶︎ ' . intval($params[$_trigger]['battery']['is_charging']));
}
}
}
// coords
if (isset($params[$_trigger]['coords'])) {
if (isset($params[$_trigger]['coords']['latitude']) && isset($params[$_trigger]['coords']['longitude'])) {
if ($getDeviceInformations) {
$cmd = $this->getCmd(null, 'coords');
if (!is_object($cmd)) {
$cmd = new mobileCmd();
$cmd->setLogicalId('coords');
$cmd->setName(__('Coordonnées', __FILE__));
$cmd->setDisplay('icon', '<i class="icon fas fa-map-marker-alt"></i>');
$cmd->setDisplay('showIconAndNamedashboard', 1);
$cmd->setDisplay('showIconAndNamemobile', 1);
$cmd->setDisplay('forceReturnLineAfter', 1);
$cmd->setTemplate('dashboard', 'core::line');
$cmd->setTemplate('mobile', 'core::line');
$cmd->setIsVisible(0);
$cmd->setOrder($order);
$order++;
log::add('mobile', 'debug', '|| Creating the "coordinates" command');
}
if ($this->checkAndUpdateCmd('altitude', $params[$_trigger]['coords']['altitude'])) {
log::add('mobile', 'debug', '|| Updating "Altitude" value ─▶︎ ' . $params[$_trigger]['coords']['altitude'] . 'm');
$cmd->setEqLogic_id($this->getId());
$cmd->setType('info');
$cmd->setSubType('string');
if ($cmd->getChanged() === true) $cmd->save();
}
$coord = $params[$_trigger]['coords']['latitude'] . ',' . $params[$_trigger]['coords']['longitude'];
if ($this->checkAndUpdateCmd('coords', $coord)) {
log::add('mobile', 'debug', '|| Updating "coordinates" value ─▶︎ ' . $coord);
}
}
if (isset($params[$_trigger]['coords']['altitude'])) {
if ($getDeviceInformations) {
$cmd = $this->getCmd(null, 'altitude');
if (!is_object($cmd)) {
$cmd = new mobileCmd();
$cmd->setLogicalId('altitude');
$cmd->setName(__('Altitude', __FILE__));
$cmd->setDisplay('icon', '<i class="icon fas fa-map-marked-alt"></i>');
$cmd->setDisplay('showIconAndNamedashboard', 1);
$cmd->setDisplay('showIconAndNamemobile', 1);
$cmd->setDisplay('forceReturnLineAfter', 1);
$cmd->setTemplate('dashboard', 'core::line');
$cmd->setTemplate('mobile', 'core::line');
$cmd->setIsVisible(0);
$cmd->setUnite('m');
$cmd->setOrder($order);
$order++;
log::add('mobile', 'debug', '|| Creating the "altitude" command');
}
$cmd->setEqLogic_id($this->getId());
$cmd->setType('info');
$cmd->setSubType('string');
if ($cmd->getChanged() === true) $cmd->save();
}
if ($this->checkAndUpdateCmd('altitude', $params[$_trigger]['coords']['altitude'])) {
log::add('mobile', 'debug', '|| Updating "Altitude" value ─▶︎ ' . $params[$_trigger]['coords']['altitude'] . 'm');
}
}
}
Expand Down