From 93d77db853bf5f63152daa34f574023385924548 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 23 May 2025 17:49:03 +0200 Subject: [PATCH] update --- .claude/settings.local.json | 8 ++++ html/launcher.php | 93 +++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 .claude/settings.local.json diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..fe38b6a --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,8 @@ +{ + "permissions": { + "allow": [ + "Bash(python3:*)" + ], + "deny": [] + } +} \ No newline at end of file diff --git a/html/launcher.php b/html/launcher.php index e217c47..0d836c7 100755 --- a/html/launcher.php +++ b/html/launcher.php @@ -1198,3 +1198,96 @@ if ($type == "toggle_systemd_service") { ]); } } + +/* + _____ ____ _ _ _ + | ____|_ ____ _____ __ _ | _ \ ___| |_ ___ ___| |_(_) ___ _ __ + | _| | '_ \ \ / / _ \/ _` | | | | |/ _ \ __/ _ \/ __| __| |/ _ \| '_ \ + | |___| | | \ V / __/ (_| | | |_| | __/ || __/ (__| |_| | (_) | | | | + |_____|_| |_|\_/ \___|\__,_| |____/ \___|\__\___|\___|\__|_|\___/|_| |_| + +*/ + +// Detect Envea devices on specified port +if ($type == "detect_envea_device") { + $port = $_GET['port'] ?? null; + + if (empty($port)) { + echo json_encode([ + 'success' => false, + 'error' => 'No port specified' + ]); + exit; + } + + // Validate port name (security check) + $allowedPorts = ['ttyAMA2', 'ttyAMA3', 'ttyAMA4', 'ttyAMA5']; + + if (!in_array($port, $allowedPorts)) { + echo json_encode([ + 'success' => false, + 'error' => 'Invalid port name' + ]); + exit; + } + + try { + // Execute the envea detection script + $command = "sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/envea/read_ref.py " . escapeshellarg($port) . " 2>&1"; + $output = shell_exec($command); + + // Check if we got any meaningful output + $detected = false; + $device_info = ''; + $raw_data = $output; + + if (!empty($output)) { + // Look for indicators that a device is connected + if (strpos($output, 'Connexion ouverte') !== false) { + // Connection was successful + if (strpos($output, 'Données reçues brutes') !== false && + strpos($output, 'b\'\'') === false) { + // We received actual data (not empty) + $detected = true; + $device_info = 'Envea CAIRSENS Device'; + + // Try to extract device type from ASCII data if available + if (preg_match('/Valeurs converties en ASCII : (.+)/', $output, $matches)) { + $ascii_data = trim($matches[1]); + if (!empty($ascii_data) && $ascii_data !== '........') { + $device_info = "Envea Device: " . $ascii_data; + } + } + } else { + // Connection successful but no data + $device_info = 'Port accessible but no Envea device detected'; + } + } else if (strpos($output, 'Erreur de connexion série') !== false) { + // Serial connection error + $device_info = 'Serial connection error - port may be busy or not available'; + } else { + // Other output + $device_info = 'Unexpected response from port'; + } + } else { + // No output at all + $device_info = 'No response from port'; + } + + echo json_encode([ + 'success' => true, + 'port' => $port, + 'detected' => $detected, + 'device_info' => $device_info, + 'data' => $raw_data, + 'timestamp' => date('Y-m-d H:i:s') + ], JSON_PRETTY_PRINT); + + } catch (Exception $e) { + echo json_encode([ + 'success' => false, + 'error' => 'Script execution failed: ' . $e->getMessage(), + 'port' => $port + ]); + } +}